summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2019-07-22 13:57:39 +0200
committerRémi Verschelde <rverschelde@gmail.com>2019-07-22 15:08:32 +0200
commit66d09a6b4cae73fbb48fe01082af5397c4a75d9a (patch)
tree052f28156bf8b60e33f928b1d3d32918f6988ab1
parent017b224a87064a3d333ba63809a0f12cfe2c4412 (diff)
SCons: Fix uses of [].append instead of env.add_source_files()
Also added support for SCons project-absolute paths (starting with #) and warning about duplicates in add_source_files(), and fixed default_controller_mappings.gen.cpp being included twice after first build due to *.cpp globbing. Part of #30270.
-rw-r--r--editor/SCsub2
-rw-r--r--main/SCsub5
-rw-r--r--methods.py30
-rw-r--r--modules/SCsub6
-rw-r--r--platform/SCsub9
-rw-r--r--scene/3d/SCsub10
6 files changed, 40 insertions, 22 deletions
diff --git a/editor/SCsub b/editor/SCsub
index 7d48e47c9f..2b560f68e8 100644
--- a/editor/SCsub
+++ b/editor/SCsub
@@ -31,7 +31,7 @@ if env['tools']:
reg_exporters_inc = '#include "register_exporters.h"\n'
reg_exporters = 'void register_exporters() {\n'
for e in env.platform_exporters:
- env.editor_sources.append("#platform/" + e + "/export/export.cpp")
+ env.add_source_files(env.editor_sources, "#platform/" + e + "/export/export.cpp")
reg_exporters += '\tregister_' + e + '_exporter();\n'
reg_exporters_inc += '#include "platform/' + e + '/export/export.h"\n'
reg_exporters += '}\n'
diff --git a/main/SCsub b/main/SCsub
index e7fe6ab4e1..62bc155c67 100644
--- a/main/SCsub
+++ b/main/SCsub
@@ -6,6 +6,7 @@ from platform_methods import run_in_subprocess
import main_builders
env.main_sources = []
+
env.add_source_files(env.main_sources, "*.cpp")
# order matters here. higher index controller database files write on top of lower index database files
@@ -14,7 +15,9 @@ controller_databases = ["#main/gamecontrollerdb.txt", "#main/gamecontrollerdb_20
env.Depends("#main/default_controller_mappings.gen.cpp", controller_databases)
env.CommandNoCache("#main/default_controller_mappings.gen.cpp", controller_databases, run_in_subprocess(main_builders.make_default_controller_mappings))
-env.main_sources.append("#main/default_controller_mappings.gen.cpp")
+# Don't warn about duplicate entry here, we need it registered manually for first build,
+# even if later builds will pick it up twice due to above *.cpp globbing.
+env.add_source_files(env.main_sources, "#main/default_controller_mappings.gen.cpp", warn_duplicates=False)
env.Depends("#main/splash.gen.h", "#main/splash.png")
env.CommandNoCache("#main/splash.gen.h", "#main/splash.png", run_in_subprocess(main_builders.make_splash))
diff --git a/methods.py b/methods.py
index bb4adfb70b..7840fb1b64 100644
--- a/methods.py
+++ b/methods.py
@@ -8,14 +8,28 @@ import subprocess
from compat import iteritems, isbasestring, decode_utf8
-def add_source_files(self, sources, filetype, lib_env=None, shared=False):
-
- if isbasestring(filetype):
- dir_path = self.Dir('.').abspath
- filetype = sorted(glob.glob(dir_path + "/" + filetype))
-
- for path in filetype:
- sources.append(self.Object(path))
+def add_source_files(self, sources, files, warn_duplicates=True):
+ # Convert string to list of absolute paths (including expanding wildcard)
+ if isbasestring(files):
+ # Keep SCons project-absolute path as they are (no wildcard support)
+ if files.startswith('#'):
+ if '*' in files:
+ print("ERROR: Wildcards can't be expanded in SCons project-absolute path: '{}'".format(files))
+ return
+ files = [files]
+ else:
+ dir_path = self.Dir('.').abspath
+ files = sorted(glob.glob(dir_path + "/" + files))
+
+ # Add each path as compiled Object following environment (self) configuration
+ for path in files:
+ obj = self.Object(path)
+ if obj in sources:
+ if warn_duplicates:
+ print("WARNING: Object \"{}\" already included in environment sources.".format(obj))
+ else:
+ continue
+ sources.append(obj)
def disable_warnings(self):
diff --git a/modules/SCsub b/modules/SCsub
index 36c2472c42..42d89d6ce2 100644
--- a/modules/SCsub
+++ b/modules/SCsub
@@ -6,9 +6,9 @@ env_modules = env.Clone()
Export('env_modules')
-env.modules_sources = [
- "register_module_types.gen.cpp",
-]
+env.modules_sources = []
+
+env_modules.add_source_files(env.modules_sources, "register_module_types.gen.cpp")
for x in env.module_list:
if (x in env.disabled_modules):
diff --git a/platform/SCsub b/platform/SCsub
index aa83154ee0..20c89ae8c6 100644
--- a/platform/SCsub
+++ b/platform/SCsub
@@ -3,7 +3,8 @@
from compat import open_utf8
Import('env')
-platform_sources = []
+
+env.platform_sources = []
# Register platform-exclusive APIs
reg_apis_inc = '#include "register_platform_apis.h"\n'
@@ -11,7 +12,7 @@ reg_apis = 'void register_platform_apis() {\n'
unreg_apis = 'void unregister_platform_apis() {\n'
for platform in env.platform_apis:
platform_dir = env.Dir(platform)
- platform_sources.append(platform_dir.File('api/api.cpp'))
+ env.add_source_files(env.platform_sources, platform + '/api/api.cpp')
reg_apis += '\tregister_' + platform + '_api();\n'
unreg_apis += '\tunregister_' + platform + '_api();\n'
reg_apis_inc += '#include "' + platform + '/api/api.h"\n'
@@ -25,7 +26,7 @@ with open_utf8('register_platform_apis.gen.cpp', 'w') as f:
f.write(reg_apis)
f.write(unreg_apis)
-platform_sources.append('register_platform_apis.gen.cpp')
+env.add_source_files(env.platform_sources, 'register_platform_apis.gen.cpp')
-lib = env.add_library('platform', platform_sources)
+lib = env.add_library('platform', env.platform_sources)
env.Prepend(LIBS=lib)
diff --git a/scene/3d/SCsub b/scene/3d/SCsub
index 200cf4316f..31a443bad1 100644
--- a/scene/3d/SCsub
+++ b/scene/3d/SCsub
@@ -3,10 +3,10 @@
Import('env')
if env['disable_3d']:
- env.scene_sources.append("3d/spatial.cpp")
- env.scene_sources.append("3d/skeleton.cpp")
- env.scene_sources.append("3d/particles.cpp")
- env.scene_sources.append("3d/visual_instance.cpp")
- env.scene_sources.append("3d/world_environment.cpp")
+ env.add_source_files(env.scene_sources, "spatial.cpp")
+ env.add_source_files(env.scene_sources, "skeleton.cpp")
+ env.add_source_files(env.scene_sources, "particles.cpp")
+ env.add_source_files(env.scene_sources, "visual_instance.cpp")
+ env.add_source_files(env.scene_sources, "world_environment.cpp")
else:
env.add_source_files(env.scene_sources, "*.cpp")