[SCons] Add support for custom build tools and platforms
Use with: `scons platform=os2 custom_tools=/path/to/tools` (assuming you have an `os2.py` inside `/path/to/tools/`)pull/1391/head
parent
5fcc43e54d
commit
baaad7ada2
|
@ -33,7 +33,26 @@ def validate_parent_dir(key, val, env):
|
||||||
raise UserError("'%s' is not a directory: %s" % (key, os.path.dirname(val)))
|
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.
|
# CPU architecture options.
|
||||||
architecture_array = [
|
architecture_array = [
|
||||||
|
@ -82,12 +101,25 @@ def options(opts, env):
|
||||||
else:
|
else:
|
||||||
raise ValueError("Could not detect platform automatically, please specify with platform=<platform>")
|
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(
|
opts.Add(
|
||||||
EnumVariable(
|
EnumVariable(
|
||||||
key="platform",
|
key="platform",
|
||||||
help="Target platform",
|
help="Target platform",
|
||||||
default=env.get("platform", default_platform),
|
default=env.get("platform", default_platform),
|
||||||
allowed_values=platforms,
|
allowed_values=platforms + custom_platforms,
|
||||||
ignorecase=2,
|
ignorecase=2,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -198,9 +230,9 @@ def options(opts, env):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add platform options
|
# Add platform options (custom tools can override platforms)
|
||||||
for pl in platforms:
|
for pl in sorted(set(platforms + custom_platforms)):
|
||||||
tool = Tool(pl, toolpath=["tools"])
|
tool = Tool(pl, toolpath=get_platform_tools_paths(env))
|
||||||
if hasattr(tool, "options"):
|
if hasattr(tool, "options"):
|
||||||
tool.options(opts)
|
tool.options(opts)
|
||||||
|
|
||||||
|
@ -259,7 +291,7 @@ def generate(env):
|
||||||
if env["use_hot_reload"]:
|
if env["use_hot_reload"]:
|
||||||
env.Append(CPPDEFINES=["HOT_RELOAD_ENABLED"])
|
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):
|
if tool is None or not tool.exists(env):
|
||||||
raise ValueError("Required toolchain not found for platform " + env["platform"])
|
raise ValueError("Required toolchain not found for platform " + env["platform"])
|
||||||
|
|
Loading…
Reference in New Issue