1313from binding_generator import scons_emit_files , scons_generate_bindings
1414
1515
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-
2216def get_cmdline_bool (option , default ):
2317 """We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
2418 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):
3125
3226
3327def 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 )
3534
3635
3736def validate_file (key , val , env ):
@@ -51,9 +50,10 @@ def validate_parent_dir(key, val, env):
5150
5251def get_platform_tools_paths (env ):
5352 path = env .get ("custom_tools" , None )
53+ tools_path = env .Dir ("tools" ).srcnode ().abspath
5454 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 ]
5757
5858
5959def get_custom_platforms (env ):
@@ -218,15 +218,17 @@ def options(opts, env):
218218 help = "Path to a custom directory containing GDExtension interface header and API JSON file" ,
219219 default = env .get ("gdextension_dir" , None ),
220220 validator = validate_dir ,
221- )
221+ ),
222+ converter = normalize_path ,
222223 )
223224 opts .Add (
224225 PathVariable (
225226 key = "custom_api_file" ,
226227 help = "Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)" ,
227228 default = env .get ("custom_api_file" , None ),
228229 validator = validate_file ,
229- )
230+ ),
231+ converter = normalize_path ,
230232 )
231233 opts .Add (
232234 BoolVariable (
@@ -529,8 +531,15 @@ def generate(env):
529531
530532
531533def _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 (
535+ "gdextension_dir" ,
536+ default = env .Dir ("gdextension" ).srcnode ().abspath
537+ )
538+ api_file = env .get (
539+ "custom_api_file" ,
540+ default = os .path .join (extension_dir , "extension_api.json" )
541+ )
542+
534543 bindings = env .GodotCPPBindings (
535544 env .Dir ("." ),
536545 [
@@ -545,15 +554,18 @@ def _godot_cpp(env):
545554 env .NoCache (bindings )
546555
547556 # 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" )
557+ sources = env .Glob ("src/*.cpp" )
558+ sources += env .Glob ("src/classes/*.cpp" )
559+ sources += env .Glob ("src/core/*.cpp" )
560+ sources += env .Glob ("src/variant/*.cpp" )
553561 sources .extend ([f for f in bindings if str (f ).endswith (".cpp" )])
554562
555563 # Includes
556- env .AppendUnique (CPPPATH = [env .Dir (d ) for d in [extension_dir , "include" , "gen/include" ]])
564+ env .AppendUnique (CPPPATH = [
565+ env .Dir (extension_dir ),
566+ env .Dir ("include" ).srcnode (),
567+ env .Dir ("gen/include" ).srcnode (),
568+ ])
557569
558570 library = None
559571 library_name = "libgodot-cpp" + env ["suffix" ] + env ["LIBSUFFIX" ]
0 commit comments