Skip to content

Commit

Permalink
SCons: Add optional detect.py get_tools method to let platforms r…
Browse files Browse the repository at this point in the history
…egister custom tools

This helps move this logic out of SConstruct, keeping platforms more self
contained, and helping thirdparty platforms define their own custom tools.

This logic was also unreliable (the `use_mingw` one would only work if
passed manually on the command line, not in e.g. `get_flags`).
  • Loading branch information
akien-mga committed Nov 27, 2024
1 parent bbc5469 commit 5df3f0d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
17 changes: 7 additions & 10 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ if sys.stdout.isatty() and sys.platform == "win32":
# Scan possible build platforms

platform_list = [] # list of platforms
platform_tools = {} # SCons custom tools for each platform
platform_opts = {} # options for each platform
platform_flags = {} # flags for each platform
platform_doc_class_path = {}
Expand Down Expand Up @@ -121,29 +122,25 @@ for x in sorted(glob.glob("platform/*")):
x = x.replace("platform/", "") # rest of world
x = x.replace("platform\\", "") # win32
platform_list += [x]
try: # Custom tools is optional
platform_tools[x] = detect.get_tools()
except Exception:
platform_tools[x] = ["default"]
platform_opts[x] = detect.get_opts()
platform_flags[x] = detect.get_flags()
if isinstance(platform_flags[x], list): # backwards compatibility
platform_flags[x] = {flag[0]: flag[1] for flag in platform_flags[x]}
sys.path.remove(tmppath)
sys.modules.pop("detect")

custom_tools = ["default"]
# Define main SCons Environment

platform_arg = ARGUMENTS.get("platform", ARGUMENTS.get("p", False))

if platform_arg == "android":
custom_tools = ["clang", "clang++", "as", "ar", "link"]
elif platform_arg == "web":
# Use generic POSIX build toolchain for Emscripten.
custom_tools = ["cc", "c++", "ar", "link", "textfile", "zip"]
elif os.name == "nt" and methods.get_cmdline_bool("use_mingw", False):
custom_tools = ["mingw"]
env = Environment(tools=platform_tools[platform_arg])

# We let SCons build its default ENV as it includes OS-specific things which we don't
# want to have to pull in manually.
# Then we prepend PATH to make it take precedence, while preserving SCons' own entries.
env = Environment(tools=custom_tools)
env.PrependENVPath("PATH", os.getenv("PATH"))
env.PrependENVPath("PKG_CONFIG_PATH", os.getenv("PKG_CONFIG_PATH"))
if "TERM" in os.environ: # Used for colored output.
Expand Down
4 changes: 4 additions & 0 deletions platform/android/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def can_build():
return os.path.exists(get_env_android_sdk_root())


def get_tools():
return ["clang", "clang++", "as", "ar", "link"]


def get_opts():
from SCons.Variables import BoolVariable

Expand Down
5 changes: 5 additions & 0 deletions platform/web/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def can_build():
return WhereIs("emcc") is not None


def get_tools():
# Use generic POSIX build toolchain for Emscripten.
return ["cc", "c++", "ar", "link", "textfile", "zip"]


def get_opts():
from SCons.Variables import BoolVariable

Expand Down
7 changes: 7 additions & 0 deletions platform/windows/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ def detect_build_env_arch():
return ""


def get_tools():
if os.name == "nt" and methods.get_cmdline_bool("use_mingw", False):
return ["mingw"]
else:
return ["default"]


def get_opts():
from SCons.Variables import BoolVariable, EnumVariable

Expand Down

0 comments on commit 5df3f0d

Please sign in to comment.