Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SCons] Add support for custom build tools and platforms #1391

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 38 additions & 6 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_platform_tools_paths(env):
path = env.get("custom_tools", None)
if path is None:
return ["tools"]
return [normalize_path(path, env), "tools"]


def get_custom_platforms(env):
path = env.get("custom_tools", None)
if path is None:
return []
platforms = []
for x in os.listdir(normalize_path(path, env)):
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 @@ -198,9 +230,9 @@ def options(opts, env):
)
)

# Add platform options
for pl in platforms:
tool = Tool(pl, toolpath=["tools"])
# Add platform options (custom tools can override platforms)
for pl in sorted(set(platforms + custom_platforms)):
tool = Tool(pl, toolpath=get_platform_tools_paths(env))
if hasattr(tool, "options"):
tool.options(opts)

Expand Down Expand Up @@ -259,7 +291,7 @@ def generate(env):
if env["use_hot_reload"]:
env.Append(CPPDEFINES=["HOT_RELOAD_ENABLED"])

tool = Tool(env["platform"], toolpath=["tools"])
tool = Tool(env["platform"], toolpath=get_platform_tools_paths(env))

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