1414from build_profile import generate_trimmed_api
1515
1616
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-
2317def get_cmdline_bool (option , default ):
2418 """We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
2519 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):
3226
3327
3428def 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 )
3635
3736
3837def validate_file (key , val , env ):
@@ -52,9 +51,10 @@ def validate_parent_dir(key, val, env):
5251
5352def get_platform_tools_paths (env ):
5453 path = env .get ("custom_tools" , None )
54+ tools_path = env .Dir ("tools" ).srcnode ().abspath
5555 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 ]
5858
5959
6060def get_custom_platforms (env ):
@@ -250,15 +250,17 @@ def options(opts, env):
250250 help = "Path to a custom directory containing GDExtension interface header and API JSON file" ,
251251 default = env .get ("gdextension_dir" , None ),
252252 validator = validate_dir ,
253- )
253+ ),
254+ converter = normalize_path ,
254255 )
255256 opts .Add (
256257 PathVariable (
257258 key = "custom_api_file" ,
258259 help = "Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)" ,
259260 default = env .get ("custom_api_file" , None ),
260261 validator = validate_file ,
261- )
262+ ),
263+ converter = normalize_path ,
262264 )
263265 opts .Add (
264266 BoolVariable (
@@ -561,8 +563,9 @@ def generate(env):
561563
562564
563565def _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+
566569 bindings = env .GodotCPPBindings (
567570 env .Dir ("." ),
568571 [
@@ -577,15 +580,22 @@ def _godot_cpp(env):
577580 env .NoCache (bindings )
578581
579582 # 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+ ]
586590
587591 # 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+ )
589599
590600 library = None
591601 library_name = "libgodot-cpp" + env ["suffix" ] + env ["LIBSUFFIX" ]
0 commit comments