1616from doc_source_generator import scons_generate_doc_source
1717
1818
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-
2519def get_cmdline_bool (option , default ):
2620 """We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
2721 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):
3428
3529
3630def 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 )
3837
3938
4039def validate_file (key , val , env ):
@@ -54,9 +53,10 @@ def validate_parent_dir(key, val, env):
5453
5554def get_platform_tools_paths (env ):
5655 path = env .get ("custom_tools" , None )
56+ tools_path = env .Dir ("tools" ).srcnode ().abspath
5757 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 ]
6060
6161
6262def get_custom_platforms (env ):
@@ -258,15 +258,17 @@ def options(opts, env):
258258 help = "Path to a custom directory containing GDExtension interface header and API JSON file" ,
259259 default = env .get ("gdextension_dir" , None ),
260260 validator = validate_dir ,
261- )
261+ ),
262+ converter = normalize_path ,
262263 )
263264 opts .Add (
264265 PathVariable (
265266 key = "custom_api_file" ,
266267 help = "Path to a custom GDExtension API JSON file (takes precedence over `gdextension_dir`)" ,
267268 default = env .get ("custom_api_file" , None ),
268269 validator = validate_file ,
269- )
270+ ),
271+ converter = normalize_path ,
270272 )
271273 opts .Add (
272274 BoolVariable (
@@ -535,8 +537,9 @@ def generate(env):
535537
536538
537539def _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+
540543 bindings = env .GodotCPPBindings (
541544 env .Dir ("." ),
542545 [
@@ -551,15 +554,22 @@ def _godot_cpp(env):
551554 env .NoCache (bindings )
552555
553556 # 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+ ]
560564
561565 # 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+ )
563573
564574 library = None
565575 library_name = "libgodot-cpp" + env ["suffix" ] + env ["LIBSUFFIX" ]
0 commit comments