Skip to content

Commit 55e93ea

Browse files
CedevIvorforce
authored andcommitted
Add SCons variant_dir support, which allows specifying a target build directory.
1 parent 27ffd8c commit 55e93ea

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

SConstruct

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/usr/bin/env python
22

33
import os
4+
import sys
5+
6+
# Add godot-cpp folder to sys.path, so that we can import local modules.
7+
sys.path.append(Dir(".").srcnode().abspath)
8+
from binding_generator import scons_generate_bindings, scons_emit_files
9+
410

511
EnsureSConsVersion(4, 0)
612

@@ -27,7 +33,7 @@ if profile:
2733
elif os.path.isfile(profile + ".py"):
2834
customs.append(profile + ".py")
2935
opts = Variables(customs, ARGUMENTS)
30-
cpp_tool = Tool("godotcpp", toolpath=["tools"])
36+
cpp_tool = Tool("godotcpp", toolpath=[Dir("tools").srcnode().abspath])
3137
cpp_tool.options(opts, env)
3238
opts.Update(env)
3339

tools/godotcpp.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
from binding_generator import scons_emit_files, scons_generate_bindings
1414

1515

16-
def add_sources(sources, dir, extension):
17-
for f in os.listdir(dir):
18-
if f.endswith("." + extension):
19-
sources.append(dir + "/" + f)
20-
21-
2216
def get_cmdline_bool(option, default):
2317
"""We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
2418
and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings.
@@ -31,7 +25,12 @@ def get_cmdline_bool(option, default):
3125

3226

3327
def normalize_path(val, env):
34-
return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)
28+
"""Normalize a path that was provided by the user on the command line
29+
and is thus either an absolute path, or relative to the top level directory (#)
30+
where the command was run.
31+
"""
32+
# If val is an absolute path, it will not be joined.
33+
return os.path.join(env.Dir("#").abspath, val)
3534

3635

3736
def validate_file(key, val, env):
@@ -51,9 +50,10 @@ def validate_parent_dir(key, val, env):
5150

5251
def get_platform_tools_paths(env):
5352
path = env.get("custom_tools", None)
53+
tools_path = env.Dir("tools").srcnode().abspath
5454
if path is None:
55-
return ["tools"]
56-
return [normalize_path(path, env), "tools"]
55+
return [tools_path]
56+
return [normalize_path(path, env), tools_path]
5757

5858

5959
def get_custom_platforms(env):
@@ -218,15 +218,17 @@ def options(opts, env):
218218
help="Path to a custom directory containing GDExtension interface header and API JSON file",
219219
default=env.get("gdextension_dir", None),
220220
validator=validate_dir,
221-
)
221+
),
222+
converter=normalize_path,
222223
)
223224
opts.Add(
224225
PathVariable(
225226
key="custom_api_file",
226227
help="Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)",
227228
default=env.get("custom_api_file", None),
228229
validator=validate_file,
229-
)
230+
),
231+
converter=normalize_path,
230232
)
231233
opts.Add(
232234
BoolVariable(
@@ -529,8 +531,9 @@ def generate(env):
529531

530532

531533
def _godot_cpp(env):
532-
extension_dir = normalize_path(env.get("gdextension_dir", env.Dir("gdextension").abspath), env)
533-
api_file = normalize_path(env.get("custom_api_file", env.File(extension_dir + "/extension_api.json").abspath), env)
534+
extension_dir = env.get("gdextension_dir", default=env.Dir("gdextension").srcnode().abspath)
535+
api_file = env.get("custom_api_file", default=os.path.join(extension_dir, "extension_api.json"))
536+
534537
bindings = env.GodotCPPBindings(
535538
env.Dir("."),
536539
[
@@ -545,15 +548,22 @@ def _godot_cpp(env):
545548
env.NoCache(bindings)
546549

547550
# Sources to compile
548-
sources = []
549-
add_sources(sources, "src", "cpp")
550-
add_sources(sources, "src/classes", "cpp")
551-
add_sources(sources, "src/core", "cpp")
552-
add_sources(sources, "src/variant", "cpp")
553-
sources.extend([f for f in bindings if str(f).endswith(".cpp")])
551+
sources = [
552+
*env.Glob("src/*.cpp"),
553+
*env.Glob("src/classes/*.cpp"),
554+
*env.Glob("src/core/*.cpp"),
555+
*env.Glob("src/variant/*.cpp"),
556+
*tuple(f for f in bindings if str(f).endswith(".cpp")),
557+
]
554558

555559
# Includes
556-
env.AppendUnique(CPPPATH=[env.Dir(d) for d in [extension_dir, "include", "gen/include"]])
560+
env.AppendUnique(
561+
CPPPATH=[
562+
env.Dir(extension_dir),
563+
env.Dir("include").srcnode(),
564+
env.Dir("gen/include").srcnode(),
565+
]
566+
)
557567

558568
library = None
559569
library_name = "libgodot-cpp" + env["suffix"] + env["LIBSUFFIX"]

0 commit comments

Comments
 (0)