Skip to content

Commit

Permalink
[SCons] Add support for custom build tools and platforms
Browse files Browse the repository at this point in the history
Use with:

`scons platform=os2 custom_tools=/path/to/tools`

(assuming you have an `os2.py` inside `/path/to/tools/`)
  • Loading branch information
Faless committed Feb 14, 2024
1 parent 5fcc43e commit 3049703
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions tools/godotcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,26 @@ def validate_parent_dir(key, val, env):
raise UserError("'%s' is not a directory: %s" % (key, os.path.dirname(val)))


platforms = ("linux", "macos", "windows", "android", "ios", "web")
def get_custom_tools_path(env):
path = env.get("custom_tools", None)
if path is not None:
return normalize_path(path, env)
return None


def get_custom_platforms(env):
path = get_custom_tools_path(env)
if path is None:
return []
platforms = []
for x in os.listdir(path):
if not x.endswith(".py"):
continue
platforms.append(x.removesuffix(".py"))
return platforms


platforms = ["linux", "macos", "windows", "android", "ios", "web"]

# CPU architecture options.
architecture_array = [
Expand Down Expand Up @@ -82,12 +101,25 @@ def options(opts, env):
else:
raise ValueError("Could not detect platform automatically, please specify with platform=<platform>")

opts.Add(
PathVariable(
key="custom_tools",
help="Path to directory containing custom tools",
default=env.get("custom_tools", None),
validator=validate_dir,
)
)

opts.Update(env)

custom_platforms = get_custom_platforms(env)

opts.Add(
EnumVariable(
key="platform",
help="Target platform",
default=env.get("platform", default_platform),
allowed_values=platforms,
allowed_values=platforms + custom_platforms,
ignorecase=2,
)
)
Expand Down Expand Up @@ -204,6 +236,12 @@ def options(opts, env):
if hasattr(tool, "options"):
tool.options(opts)

# Add custom options
for pl in custom_platforms:
tool = Tool(pl, toolpath=[get_custom_tools_path(env)])
if hasattr(tool, "options"):
tool.options(opts)

# Targets flags tool (optimizations, debug symbols)
target_tool = Tool("targets", toolpath=["tools"])
target_tool.options(opts)
Expand Down Expand Up @@ -259,7 +297,10 @@ def generate(env):
if env["use_hot_reload"]:
env.Append(CPPDEFINES=["HOT_RELOAD_ENABLED"])

tool = Tool(env["platform"], toolpath=["tools"])
if env["platform"] in platforms:
tool = Tool(env["platform"], toolpath=["tools"])
else:
tool = Tool(env["platform"], toolpath=[get_custom_tools_path(env)])

if tool is None or not tool.exists(env):
raise ValueError("Required toolchain not found for platform " + env["platform"])
Expand Down

0 comments on commit 3049703

Please sign in to comment.