13
13
from binding_generator import scons_emit_files , scons_generate_bindings
14
14
15
15
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
-
22
16
def get_cmdline_bool (option , default ):
23
17
"""We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
24
18
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):
31
25
32
26
33
27
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 )
35
34
36
35
37
36
def validate_file (key , val , env ):
@@ -51,9 +50,10 @@ def validate_parent_dir(key, val, env):
51
50
52
51
def get_platform_tools_paths (env ):
53
52
path = env .get ("custom_tools" , None )
53
+ tools_path = env .Dir ("tools" ).srcnode ().abspath
54
54
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 ]
57
57
58
58
59
59
def get_custom_platforms (env ):
@@ -218,15 +218,17 @@ def options(opts, env):
218
218
help = "Path to a custom directory containing GDExtension interface header and API JSON file" ,
219
219
default = env .get ("gdextension_dir" , None ),
220
220
validator = validate_dir ,
221
- )
221
+ ),
222
+ converter = normalize_path ,
222
223
)
223
224
opts .Add (
224
225
PathVariable (
225
226
key = "custom_api_file" ,
226
227
help = "Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)" ,
227
228
default = env .get ("custom_api_file" , None ),
228
229
validator = validate_file ,
229
- )
230
+ ),
231
+ converter = normalize_path ,
230
232
)
231
233
opts .Add (
232
234
BoolVariable (
@@ -529,8 +531,9 @@ def generate(env):
529
531
530
532
531
533
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
+
534
537
bindings = env .GodotCPPBindings (
535
538
env .Dir ("." ),
536
539
[
@@ -545,15 +548,22 @@ def _godot_cpp(env):
545
548
env .NoCache (bindings )
546
549
547
550
# 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
+ ]
554
558
555
559
# 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
+ )
557
567
558
568
library = None
559
569
library_name = "libgodot-cpp" + env ["suffix" ] + env ["LIBSUFFIX" ]
0 commit comments