1111from binding_generator import scons_generate_bindings , scons_emit_files
1212
1313
14- def add_sources (sources , dir , extension ):
15- for f in os .listdir (dir ):
16- if f .endswith ("." + extension ):
17- sources .append (dir + "/" + f )
18-
19-
2014def get_cmdline_bool (option , default ):
2115 """We use `ARGUMENTS.get()` to check if options were manually overridden on the command line,
2216 and SCons' _text2bool helper to convert them to booleans, otherwise they're handled as strings.
@@ -29,6 +23,10 @@ def get_cmdline_bool(option, default):
2923
3024
3125def normalize_path (val , env ):
26+ """Normalize a path that was provided by the user on the command line
27+ and is thus either an absolute path or relative to the top level directory (#)
28+ where the command was run
29+ """
3230 return val if os .path .isabs (val ) else os .path .join (env .Dir ("#" ).abspath , val )
3331
3432
@@ -49,9 +47,10 @@ def validate_parent_dir(key, val, env):
4947
5048def get_platform_tools_paths (env ):
5149 path = env .get ("custom_tools" , None )
50+ tools_path = env .Dir ("tools" ).srcnode ().abspath
5251 if path is None :
53- return ["tools" ]
54- return [normalize_path (path , env ), "tools" ]
52+ return [tools_path ]
53+ return [normalize_path (path , env ), tools_path ]
5554
5655
5756def get_custom_platforms (env ):
@@ -387,8 +386,22 @@ def generate(env):
387386
388387
389388def _godot_cpp (env ):
390- extension_dir = normalize_path (env .get ("gdextension_dir" , env .Dir ("gdextension" ).abspath ), env )
391- api_file = normalize_path (env .get ("custom_api_file" , env .File (extension_dir + "/extension_api.json" ).abspath ), env )
389+ extension_dir = env .get ("gdextension_dir" , None )
390+ # A user provided extension_dir is relative to where they are running from (#)
391+ # But our gdextension directory is here in the source tree
392+ if extension_dir is not None :
393+ extension_dir = normalize_path (extension_dir , env )
394+ else :
395+ extension_dir = env .Dir ("gdextension" ).srcnode ().abspath
396+
397+ api_file = env .get ("custom_api_file" , None )
398+ # A user provided api_file is relative to where they are running from (#)
399+ # But a default api_file is relative to extension_dir
400+ if api_file is not None :
401+ api_file = normalize_path (api_file , env )
402+ else :
403+ api_file = os .path .join (extension_dir , "extension_api.json" )
404+
392405 bindings = env .GodotCPPBindings (
393406 env .Dir ("." ),
394407 [
@@ -403,15 +416,12 @@ def _godot_cpp(env):
403416 env .NoCache (bindings )
404417
405418 # Sources to compile
406- sources = []
407- add_sources (sources , "src" , "cpp" )
408- add_sources (sources , "src/classes" , "cpp" )
409- add_sources (sources , "src/core" , "cpp" )
410- add_sources (sources , "src/variant" , "cpp" )
419+ sources = env .Glob ("src/*.cpp" )
420+ sources += env .Glob ("src/*/*.cpp" )
411421 sources .extend ([f for f in bindings if str (f ).endswith (".cpp" )])
412422
413423 # Includes
414- env .AppendUnique (CPPPATH = [env .Dir (d ) for d in [ extension_dir , "include" , "gen/include" ] ])
424+ env .AppendUnique (CPPPATH = [env .Dir (extension_dir ), env . Dir ( "include" ). srcnode (), env . Dir ( "gen/include" ) ])
415425
416426 library = None
417427 library_name = "libgodot-cpp" + env ["suffix" ] + env ["LIBSUFFIX" ]
0 commit comments