Merge pull request #1170 from adamscott/import-env-if-exists

Import `env` if possible
pull/1184/head
David Snopek 2023-07-14 11:40:52 -05:00 committed by GitHub
commit 67bd2eac44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 57 additions and 23 deletions

View File

@ -51,9 +51,13 @@ elif ARGUMENTS.get("platform", ""):
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>")
try:
Import("env")
except:
# Default tools with no platform defaults to gnu toolchain. # Default tools with no platform defaults to gnu toolchain.
# We apply platform specific toolchains via our custom tools. # We apply platform specific toolchains via our custom tools.
env = Environment(tools=["default"], PLATFORM="") env = Environment(tools=["default"], PLATFORM="")
env.PrependENVPath("PATH", os.getenv("PATH")) env.PrependENVPath("PATH", os.getenv("PATH"))
# Default num_jobs to local cpu count if not user specified. # Default num_jobs to local cpu count if not user specified.
@ -87,9 +91,9 @@ opts = Variables(customs, ARGUMENTS)
platforms = ("linux", "macos", "windows", "android", "ios", "javascript") platforms = ("linux", "macos", "windows", "android", "ios", "javascript")
opts.Add( opts.Add(
EnumVariable( EnumVariable(
"platform", key="platform",
"Target platform", help="Target platform",
default_platform, default=env.get("platform", default_platform),
allowed_values=platforms, allowed_values=platforms,
ignorecase=2, ignorecase=2,
) )
@ -99,31 +103,53 @@ opts.Add(
# Godot release templates are only compatible with "template_release" builds. # Godot release templates are only compatible with "template_release" builds.
# For this reason, we default to template_debug builds, unlike Godot which defaults to editor builds. # For this reason, we default to template_debug builds, unlike Godot which defaults to editor builds.
opts.Add( opts.Add(
EnumVariable("target", "Compilation target", "template_debug", ("editor", "template_release", "template_debug")) EnumVariable(
) key="target",
opts.Add( help="Compilation target",
PathVariable( default=env.get("target", "template_debug"),
"gdextension_dir", allowed_values=("editor", "template_release", "template_debug"),
"Path to a custom directory containing GDExtension interface header and API JSON file",
None,
validate_gdextension_dir,
) )
) )
opts.Add( opts.Add(
PathVariable( PathVariable(
"custom_api_file", key="gdextension_dir",
"Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)", help="Path to a custom directory containing GDExtension interface header and API JSON file",
None, default=env.get("gdextension_dir", None),
validate_api_file, validator=validate_gdextension_dir,
) )
) )
opts.Add( opts.Add(
BoolVariable("generate_bindings", "Force GDExtension API bindings generation. Auto-detected by default.", False) PathVariable(
key="custom_api_file",
help="Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)",
default=env.get("custom_api_file", None),
validator=validate_api_file,
)
)
opts.Add(
BoolVariable(
key="generate_bindings",
help="Force GDExtension API bindings generation. Auto-detected by default.",
default=env.get("generate_bindings", False),
)
)
opts.Add(
BoolVariable(
key="generate_template_get_node",
help="Generate a template version of the Node class's get_node.",
default=env.get("generate_template_get_node", True),
)
) )
opts.Add(BoolVariable("generate_template_get_node", "Generate a template version of the Node class's get_node.", True))
opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True)) opts.Add(BoolVariable(key="build_library", help="Build the godot-cpp library.", default=env.get("build_library", True)))
opts.Add(EnumVariable("precision", "Set the floating-point precision level", "single", ("single", "double"))) opts.Add(
EnumVariable(
key="precision",
help="Set the floating-point precision level",
default=env.get("precision", "single"),
allowed_values=("single", "double"),
)
)
# Add platform options # Add platform options
tools = {} tools = {}
@ -149,7 +175,15 @@ architecture_aliases = {
"ppc": "ppc32", "ppc": "ppc32",
"ppc64le": "ppc64", "ppc64le": "ppc64",
} }
opts.Add(EnumVariable("arch", "CPU architecture", "", architecture_array, architecture_aliases)) opts.Add(
EnumVariable(
key="arch",
help="CPU architecture",
default=env.get("arch", ""),
allowed_values=architecture_array,
map=architecture_aliases,
)
)
# Targets flags tool (optimizations, debug symbols) # Targets flags tool (optimizations, debug symbols)
target_tool = Tool("targets", toolpath=["tools"]) target_tool = Tool("targets", toolpath=["tools"])