Skip to content

Commit 6a87094

Browse files
authored
Merge pull request #1669 from Ivorforce/scons-variant_dir-support
Add SCons variant_dir support
2 parents f129db3 + 1345c46 commit 6a87094

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

SConstruct

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
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+
49

510
EnsureSConsVersion(4, 0)
611
EnsurePythonVersion(3, 8)
@@ -27,7 +32,7 @@ if profile:
2732
elif os.path.isfile(profile + ".py"):
2833
customs.append(profile + ".py")
2934
opts = Variables(customs, ARGUMENTS)
30-
cpp_tool = Tool("godotcpp", toolpath=["tools"])
35+
cpp_tool = Tool("godotcpp", toolpath=[Dir("tools").srcnode().abspath])
3136
cpp_tool.options(opts, env)
3237
opts.Update(env)
3338

tools/godotcpp.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
from doc_source_generator import scons_generate_doc_source
1717

1818

19-
def add_sources(sources, dir, extension):
20-
for f in os.listdir(dir):
21-
if f.endswith("." + extension):
22-
sources.append(dir + "/" + f)
23-
24-
2519
def get_cmdline_bool(option, default):
2620
"""We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
2721
and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings.
@@ -34,7 +28,12 @@ def get_cmdline_bool(option, default):
3428

3529

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

3938

4039
def validate_file(key, val, env):
@@ -54,9 +53,10 @@ def validate_parent_dir(key, val, env):
5453

5554
def get_platform_tools_paths(env):
5655
path = env.get("custom_tools", None)
56+
tools_path = env.Dir("tools").srcnode().abspath
5757
if path is None:
58-
return ["tools"]
59-
return [normalize_path(path, env), "tools"]
58+
return [tools_path]
59+
return [normalize_path(path, env), tools_path]
6060

6161

6262
def get_custom_platforms(env):
@@ -258,15 +258,17 @@ def options(opts, env):
258258
help="Path to a custom directory containing GDExtension interface header and API JSON file",
259259
default=env.get("gdextension_dir", None),
260260
validator=validate_dir,
261-
)
261+
),
262+
converter=normalize_path,
262263
)
263264
opts.Add(
264265
PathVariable(
265266
key="custom_api_file",
266267
help="Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)",
267268
default=env.get("custom_api_file", None),
268269
validator=validate_file,
269-
)
270+
),
271+
converter=normalize_path,
270272
)
271273
opts.Add(
272274
BoolVariable(
@@ -535,8 +537,9 @@ def generate(env):
535537

536538

537539
def _godot_cpp(env):
538-
extension_dir = normalize_path(env.get("gdextension_dir", env.Dir("gdextension").abspath), env)
539-
api_file = normalize_path(env.get("custom_api_file", env.File(extension_dir + "/extension_api.json").abspath), env)
540+
extension_dir = env.get("gdextension_dir", default=env.Dir("gdextension").srcnode().abspath)
541+
api_file = env.get("custom_api_file", default=os.path.join(extension_dir, "extension_api.json"))
542+
540543
bindings = env.GodotCPPBindings(
541544
env.Dir("."),
542545
[
@@ -551,15 +554,22 @@ def _godot_cpp(env):
551554
env.NoCache(bindings)
552555

553556
# Sources to compile
554-
sources = []
555-
add_sources(sources, "src", "cpp")
556-
add_sources(sources, "src/classes", "cpp")
557-
add_sources(sources, "src/core", "cpp")
558-
add_sources(sources, "src/variant", "cpp")
559-
sources.extend([f for f in bindings if str(f).endswith(".cpp")])
557+
sources = [
558+
*env.Glob("src/*.cpp"),
559+
*env.Glob("src/classes/*.cpp"),
560+
*env.Glob("src/core/*.cpp"),
561+
*env.Glob("src/variant/*.cpp"),
562+
*tuple(f for f in bindings if str(f).endswith(".cpp")),
563+
]
560564

561565
# Includes
562-
env.AppendUnique(CPPPATH=[env.Dir(d) for d in [extension_dir, "include", "gen/include"]])
566+
env.AppendUnique(
567+
CPPPATH=[
568+
env.Dir(extension_dir),
569+
env.Dir("include").srcnode(),
570+
env.Dir("gen/include"),
571+
]
572+
)
563573

564574
library = None
565575
library_name = "libgodot-cpp" + env["suffix"] + env["LIBSUFFIX"]

0 commit comments

Comments
 (0)