14
14
from build_profile import generate_trimmed_api
15
15
16
16
17
- def add_sources (sources , dir , extension ):
18
- for f in os .listdir (dir ):
19
- if f .endswith ("." + extension ):
20
- sources .append (dir + "/" + f )
21
-
22
-
23
17
def get_cmdline_bool (option , default ):
24
18
"""We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
25
19
and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings.
@@ -32,7 +26,12 @@ def get_cmdline_bool(option, default):
32
26
33
27
34
28
def normalize_path (val , env ):
35
- return val if os .path .isabs (val ) else os .path .join (env .Dir ("#" ).abspath , val )
29
+ """Normalize a path that was provided by the user on the command line
30
+ and is thus either an absolute path, or relative to the top level directory (#)
31
+ where the command was run.
32
+ """
33
+ # If val is an absolute path, it will not be joined.
34
+ return os .path .join (env .Dir ("#" ).abspath , val )
36
35
37
36
38
37
def validate_file (key , val , env ):
@@ -52,9 +51,10 @@ def validate_parent_dir(key, val, env):
52
51
53
52
def get_platform_tools_paths (env ):
54
53
path = env .get ("custom_tools" , None )
54
+ tools_path = env .Dir ("tools" ).srcnode ().abspath
55
55
if path is None :
56
- return ["tools" ]
57
- return [normalize_path (path , env ), "tools" ]
56
+ return [tools_path ]
57
+ return [normalize_path (path , env ), tools_path ]
58
58
59
59
60
60
def get_custom_platforms (env ):
@@ -250,15 +250,17 @@ def options(opts, env):
250
250
help = "Path to a custom directory containing GDExtension interface header and API JSON file" ,
251
251
default = env .get ("gdextension_dir" , None ),
252
252
validator = validate_dir ,
253
- )
253
+ ),
254
+ converter = normalize_path ,
254
255
)
255
256
opts .Add (
256
257
PathVariable (
257
258
key = "custom_api_file" ,
258
259
help = "Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)" ,
259
260
default = env .get ("custom_api_file" , None ),
260
261
validator = validate_file ,
261
- )
262
+ ),
263
+ converter = normalize_path ,
262
264
)
263
265
opts .Add (
264
266
BoolVariable (
@@ -561,8 +563,9 @@ def generate(env):
561
563
562
564
563
565
def _godot_cpp (env ):
564
- extension_dir = normalize_path (env .get ("gdextension_dir" , env .Dir ("gdextension" ).abspath ), env )
565
- api_file = normalize_path (env .get ("custom_api_file" , env .File (extension_dir + "/extension_api.json" ).abspath ), env )
566
+ extension_dir = env .get ("gdextension_dir" , default = env .Dir ("gdextension" ).srcnode ().abspath )
567
+ api_file = env .get ("custom_api_file" , default = os .path .join (extension_dir , "extension_api.json" ))
568
+
566
569
bindings = env .GodotCPPBindings (
567
570
env .Dir ("." ),
568
571
[
@@ -577,15 +580,22 @@ def _godot_cpp(env):
577
580
env .NoCache (bindings )
578
581
579
582
# Sources to compile
580
- sources = []
581
- add_sources (sources , "src" , "cpp" )
582
- add_sources (sources , "src/classes" , "cpp" )
583
- add_sources (sources , "src/core" , "cpp" )
584
- add_sources (sources , "src/variant" , "cpp" )
585
- sources .extend ([f for f in bindings if str (f ).endswith (".cpp" )])
583
+ sources = [
584
+ * env .Glob ("src/*.cpp" ),
585
+ * env .Glob ("src/classes/*.cpp" ),
586
+ * env .Glob ("src/core/*.cpp" ),
587
+ * env .Glob ("src/variant/*.cpp" ),
588
+ * tuple (f for f in bindings if str (f ).endswith (".cpp" )),
589
+ ]
586
590
587
591
# Includes
588
- env .AppendUnique (CPPPATH = [env .Dir (d ) for d in [extension_dir , "include" , "gen/include" ]])
592
+ env .AppendUnique (
593
+ CPPPATH = [
594
+ env .Dir (extension_dir ),
595
+ env .Dir ("include" ).srcnode (),
596
+ env .Dir ("gen/include" ),
597
+ ]
598
+ )
589
599
590
600
library = None
591
601
library_name = "libgodot-cpp" + env ["suffix" ] + env ["LIBSUFFIX" ]
0 commit comments