Skip to content

Commit 8155f35

Browse files
committed
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.
1 parent d627942 commit 8155f35

File tree

1 file changed

+54
-20
lines changed

1 file changed

+54
-20
lines changed

SConstruct

+54-20
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ elif ARGUMENTS.get("platform", ""):
5151
else:
5252
raise ValueError("Could not detect platform automatically, please specify with platform=<platform>")
5353

54-
# Default tools with no platform defaults to gnu toolchain.
55-
# We apply platform specific toolchains via our custom tools.
56-
env = Environment(tools=["default"], PLATFORM="")
54+
try:
55+
Import("env")
56+
except:
57+
# Default tools with no platform defaults to gnu toolchain.
58+
# We apply platform specific toolchains via our custom tools.
59+
env = Environment(tools=["default"], PLATFORM="")
60+
5761
env.PrependENVPath("PATH", os.getenv("PATH"))
5862

5963
# Default num_jobs to local cpu count if not user specified.
@@ -87,9 +91,9 @@ opts = Variables(customs, ARGUMENTS)
8791
platforms = ("linux", "macos", "windows", "android", "ios", "javascript")
8892
opts.Add(
8993
EnumVariable(
90-
"platform",
91-
"Target platform",
92-
default_platform,
94+
key="platform",
95+
help="Target platform",
96+
default=env.get("platform", default_platform),
9397
allowed_values=platforms,
9498
ignorecase=2,
9599
)
@@ -99,31 +103,53 @@ opts.Add(
99103
# Godot release templates are only compatible with "template_release" builds.
100104
# For this reason, we default to template_debug builds, unlike Godot which defaults to editor builds.
101105
opts.Add(
102-
EnumVariable("target", "Compilation target", "template_debug", ("editor", "template_release", "template_debug"))
106+
EnumVariable(
107+
key="target",
108+
help="Compilation target",
109+
default=env.get("target", "template_debug"),
110+
allowed_values=("editor", "template_release", "template_debug"),
111+
)
103112
)
104113
opts.Add(
105114
PathVariable(
106-
"gdextension_dir",
107-
"Path to a custom directory containing GDExtension interface header and API JSON file",
108-
None,
109-
validate_gdextension_dir,
115+
key="gdextension_dir",
116+
help="Path to a custom directory containing GDExtension interface header and API JSON file",
117+
default=env.get("gdextension_dir", None),
118+
validator=validate_gdextension_dir,
110119
)
111120
)
112121
opts.Add(
113122
PathVariable(
114-
"custom_api_file",
115-
"Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)",
116-
None,
117-
validate_api_file,
123+
key="custom_api_file",
124+
help="Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)",
125+
default=env.get("custom_api_file", None),
126+
validator=validate_api_file,
127+
)
128+
)
129+
opts.Add(
130+
BoolVariable(
131+
key="generate_bindings",
132+
help="Force GDExtension API bindings generation. Auto-detected by default.",
133+
default=env.get("generate_bindings", False),
118134
)
119135
)
120136
opts.Add(
121-
BoolVariable("generate_bindings", "Force GDExtension API bindings generation. Auto-detected by default.", False)
137+
BoolVariable(
138+
key="generate_template_get_node",
139+
help="Generate a template version of the Node class's get_node.",
140+
default=env.get("generate_template_get_node", True),
141+
)
122142
)
123-
opts.Add(BoolVariable("generate_template_get_node", "Generate a template version of the Node class's get_node.", True))
124143

125-
opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True))
126-
opts.Add(EnumVariable("precision", "Set the floating-point precision level", "single", ("single", "double")))
144+
opts.Add(BoolVariable(key="build_library", help="Build the godot-cpp library.", default=env.get("build_library", True)))
145+
opts.Add(
146+
EnumVariable(
147+
key="precision",
148+
help="Set the floating-point precision level",
149+
default=env.get("precision", "single"),
150+
allowed_values=("single", "double"),
151+
)
152+
)
127153

128154
# Add platform options
129155
tools = {}
@@ -149,7 +175,15 @@ architecture_aliases = {
149175
"ppc": "ppc32",
150176
"ppc64le": "ppc64",
151177
}
152-
opts.Add(EnumVariable("arch", "CPU architecture", "", architecture_array, architecture_aliases))
178+
opts.Add(
179+
EnumVariable(
180+
key="arch",
181+
help="CPU architecture",
182+
default=env.get("arch", ""),
183+
allowed_values=architecture_array,
184+
map=architecture_aliases,
185+
)
186+
)
153187

154188
# Targets flags tool (optimizations, debug symbols)
155189
target_tool = Tool("targets", toolpath=["tools"])

0 commit comments

Comments
 (0)