From 8155f35b29b4b08bc54b2eb0c57e1e9effe9f093 Mon Sep 17 00:00:00 2001 From: Adam Scott Date: Sun, 9 Jul 2023 09:27:31 -0400 Subject: [PATCH] Import `env` if possible This PR make it possible to import `env` and use it instead of creating one from scratch every time. Handy because we encourage users to use the godot-cpp SConstruct file as a base to their projects (see the test project). So, if a project want to override specific settings, (eg. make a path local to their SConstruct file, not local to the godot-cpp/SConstruct file), it can do so. --- SConstruct | 80 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 23 deletions(-) diff --git a/SConstruct b/SConstruct index 42f8fc0b..11ec4cfb 100644 --- a/SConstruct +++ b/SConstruct @@ -51,9 +51,13 @@ elif ARGUMENTS.get("platform", ""): else: raise ValueError("Could not detect platform automatically, please specify with platform=") -# Default tools with no platform defaults to gnu toolchain. -# We apply platform specific toolchains via our custom tools. -env = Environment(tools=["default"], PLATFORM="") +try: + Import("env") +except: + # Default tools with no platform defaults to gnu toolchain. + # We apply platform specific toolchains via our custom tools. + env = Environment(tools=["default"], PLATFORM="") + env.PrependENVPath("PATH", os.getenv("PATH")) # 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") opts.Add( EnumVariable( - "platform", - "Target platform", - default_platform, + key="platform", + help="Target platform", + default=env.get("platform", default_platform), allowed_values=platforms, ignorecase=2, ) @@ -99,31 +103,53 @@ opts.Add( # 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. opts.Add( - EnumVariable("target", "Compilation target", "template_debug", ("editor", "template_release", "template_debug")) -) -opts.Add( - PathVariable( - "gdextension_dir", - "Path to a custom directory containing GDExtension interface header and API JSON file", - None, - validate_gdextension_dir, + EnumVariable( + key="target", + help="Compilation target", + default=env.get("target", "template_debug"), + allowed_values=("editor", "template_release", "template_debug"), ) ) opts.Add( PathVariable( - "custom_api_file", - "Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)", - None, - validate_api_file, + key="gdextension_dir", + help="Path to a custom directory containing GDExtension interface header and API JSON file", + default=env.get("gdextension_dir", None), + validator=validate_gdextension_dir, ) ) 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(EnumVariable("precision", "Set the floating-point precision level", "single", ("single", "double"))) +opts.Add(BoolVariable(key="build_library", help="Build the godot-cpp library.", default=env.get("build_library", True))) +opts.Add( + EnumVariable( + key="precision", + help="Set the floating-point precision level", + default=env.get("precision", "single"), + allowed_values=("single", "double"), + ) +) # Add platform options tools = {} @@ -149,7 +175,15 @@ architecture_aliases = { "ppc": "ppc32", "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) target_tool = Tool("targets", toolpath=["tools"])