Skip to content

Commit d6edb72

Browse files
committed
Add SCons variant_dir support
Adds support for using SCons's variant_dir feature to specify the build path for where to build a variant of the the library. Correct paths in SConstruct and godotcpp tool for the following, even when the current directory is not the root of the repository: - the binding_generator python module - godotcpp tools - source code and includes - generated source code
1 parent 1d829f2 commit d6edb72

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

SConstruct

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import os
44
import platform
55
import sys
66
import subprocess
7+
8+
# binding_generator is located in the source tree along with this SConstruct file
9+
sys.path.append(Dir(".").srcnode().abspath)
710
from binding_generator import scons_generate_bindings, scons_emit_files
811

912

@@ -32,7 +35,7 @@ if profile:
3235
elif os.path.isfile(profile + ".py"):
3336
customs.append(profile + ".py")
3437
opts = Variables(customs, ARGUMENTS)
35-
cpp_tool = Tool("godotcpp", toolpath=["tools"])
38+
cpp_tool = Tool("godotcpp", toolpath=[Dir("tools").srcnode().abspath])
3639
cpp_tool.options(opts, env)
3740
opts.Update(env)
3841

tools/godotcpp.py

+26-16
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212
from binding_generator import scons_generate_bindings, scons_emit_files
1313

1414

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

3125

3226
def normalize_path(val, env):
27+
"""Normalize a path that was provided by the user on the command line
28+
and is thus either an absolute path or relative to the top level directory (#)
29+
where the command was run
30+
"""
3331
return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)
3432

3533

@@ -50,9 +48,10 @@ def validate_parent_dir(key, val, env):
5048

5149
def get_platform_tools_paths(env):
5250
path = env.get("custom_tools", None)
51+
tools_path = env.Dir("tools").srcnode().abspath
5352
if path is None:
54-
return ["tools"]
55-
return [normalize_path(path, env), "tools"]
53+
return [tools_path]
54+
return [normalize_path(path, env), tools_path]
5655

5756

5857
def get_custom_platforms(env):
@@ -458,8 +457,22 @@ def generate(env):
458457

459458

460459
def _godot_cpp(env):
461-
extension_dir = normalize_path(env.get("gdextension_dir", env.Dir("gdextension").abspath), env)
462-
api_file = normalize_path(env.get("custom_api_file", env.File(extension_dir + "/extension_api.json").abspath), env)
460+
extension_dir = env.get("gdextension_dir", None)
461+
# A user provided extension_dir is relative to where they are running from (#)
462+
# But our gdextension directory is here in the source tree
463+
if extension_dir is not None:
464+
extension_dir = normalize_path(extension_dir, env)
465+
else:
466+
extension_dir = env.Dir("gdextension").srcnode().abspath
467+
468+
api_file = env.get("custom_api_file", None)
469+
# A user provided api_file is relative to where they are running from (#)
470+
# But a default api_file is relative to extension_dir
471+
if api_file is not None:
472+
api_file = normalize_path(api_file, env)
473+
else:
474+
api_file = os.path.join(extension_dir, "extension_api.json")
475+
463476
bindings = env.GodotCPPBindings(
464477
env.Dir("."),
465478
[
@@ -474,15 +487,12 @@ def _godot_cpp(env):
474487
env.NoCache(bindings)
475488

476489
# Sources to compile
477-
sources = []
478-
add_sources(sources, "src", "cpp")
479-
add_sources(sources, "src/classes", "cpp")
480-
add_sources(sources, "src/core", "cpp")
481-
add_sources(sources, "src/variant", "cpp")
490+
sources = env.Glob("src/*.cpp")
491+
sources += env.Glob("src/*/*.cpp")
482492
sources.extend([f for f in bindings if str(f).endswith(".cpp")])
483493

484494
# Includes
485-
env.AppendUnique(CPPPATH=[env.Dir(d) for d in [extension_dir, "include", "gen/include"]])
495+
env.AppendUnique(CPPPATH=[env.Dir(extension_dir), env.Dir("include").srcnode(), env.Dir("gen/include")])
486496

487497
library = None
488498
library_name = "libgodot-cpp" + env["suffix"] + env["LIBSUFFIX"]

0 commit comments

Comments
 (0)