Skip to content

Commit 5b47e4d

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 340dde3 commit 5b47e4d

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):
@@ -511,8 +510,22 @@ def generate(env):
511510

512511

513512
def _godot_cpp(env):
514-
extension_dir = normalize_path(env.get("gdextension_dir", env.Dir("gdextension").abspath), env)
515-
api_file = normalize_path(env.get("custom_api_file", env.File(extension_dir + "/extension_api.json").abspath), env)
513+
extension_dir = env.get("gdextension_dir", None)
514+
# A user provided extension_dir is relative to where they are running from (#)
515+
# But our gdextension directory is here in the source tree
516+
if extension_dir is not None:
517+
extension_dir = normalize_path(extension_dir, env)
518+
else:
519+
extension_dir = env.Dir("gdextension").srcnode().abspath
520+
521+
api_file = env.get("custom_api_file", None)
522+
# A user provided api_file is relative to where they are running from (#)
523+
# But a default api_file is relative to extension_dir
524+
if api_file is not None:
525+
api_file = normalize_path(api_file, env)
526+
else:
527+
api_file = os.path.join(extension_dir, "extension_api.json")
528+
516529
bindings = env.GodotCPPBindings(
517530
env.Dir("."),
518531
[
@@ -527,15 +540,12 @@ def _godot_cpp(env):
527540
env.NoCache(bindings)
528541

529542
# Sources to compile
530-
sources = []
531-
add_sources(sources, "src", "cpp")
532-
add_sources(sources, "src/classes", "cpp")
533-
add_sources(sources, "src/core", "cpp")
534-
add_sources(sources, "src/variant", "cpp")
543+
sources = env.Glob("src/*.cpp")
544+
sources += env.Glob("src/*/*.cpp")
535545
sources.extend([f for f in bindings if str(f).endswith(".cpp")])
536546

537547
# Includes
538-
env.AppendUnique(CPPPATH=[env.Dir(d) for d in [extension_dir, "include", "gen/include"]])
548+
env.AppendUnique(CPPPATH=[env.Dir(extension_dir), env.Dir("include").srcnode(), env.Dir("gen/include")])
539549

540550
library = None
541551
library_name = "libgodot-cpp" + env["suffix"] + env["LIBSUFFIX"]

0 commit comments

Comments
 (0)