16
16
from doc_source_generator import scons_generate_doc_source
17
17
18
18
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
-
25
19
def get_cmdline_bool (option , default ):
26
20
"""We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
27
21
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):
34
28
35
29
36
30
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 )
38
37
39
38
40
39
def validate_file (key , val , env ):
@@ -54,9 +53,10 @@ def validate_parent_dir(key, val, env):
54
53
55
54
def get_platform_tools_paths (env ):
56
55
path = env .get ("custom_tools" , None )
56
+ tools_path = env .Dir ("tools" ).srcnode ().abspath
57
57
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 ]
60
60
61
61
62
62
def get_custom_platforms (env ):
@@ -258,15 +258,17 @@ def options(opts, env):
258
258
help = "Path to a custom directory containing GDExtension interface header and API JSON file" ,
259
259
default = env .get ("gdextension_dir" , None ),
260
260
validator = validate_dir ,
261
- )
261
+ ),
262
+ converter = normalize_path ,
262
263
)
263
264
opts .Add (
264
265
PathVariable (
265
266
key = "custom_api_file" ,
266
267
help = "Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)" ,
267
268
default = env .get ("custom_api_file" , None ),
268
269
validator = validate_file ,
269
- )
270
+ ),
271
+ converter = normalize_path ,
270
272
)
271
273
opts .Add (
272
274
BoolVariable (
@@ -535,8 +537,9 @@ def generate(env):
535
537
536
538
537
539
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
+
540
543
bindings = env .GodotCPPBindings (
541
544
env .Dir ("." ),
542
545
[
@@ -551,15 +554,22 @@ def _godot_cpp(env):
551
554
env .NoCache (bindings )
552
555
553
556
# 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
+ ]
560
564
561
565
# 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
+ )
563
573
564
574
library = None
565
575
library_name = "libgodot-cpp" + env ["suffix" ] + env ["LIBSUFFIX" ]
0 commit comments