From 3334209a732737274a8598191267573fcb989a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Wed, 30 May 2018 19:11:33 +0200 Subject: SCons: Pass env to modules can_build method This allows to disable modules based on the environment, in particular `env[tools]` which tells us if we are building the editor or not. --- SConstruct | 12 +++++++++++- modules/bmp/config.py | 4 +--- modules/bullet/config.py | 2 +- modules/csg/config.py | 2 +- modules/dds/config.py | 2 +- modules/enet/config.py | 2 +- modules/etc/config.py | 10 +++------- modules/freetype/config.py | 2 +- modules/gdnative/config.py | 2 +- modules/gdscript/config.py | 2 +- modules/gridmap/config.py | 2 +- modules/hdr/config.py | 2 +- modules/jpg/config.py | 2 +- modules/mbedtls/config.py | 2 +- modules/mobile_vr/config.py | 2 +- modules/mono/config.py | 2 +- modules/ogg/config.py | 2 +- modules/opus/config.py | 2 +- modules/pvr/config.py | 2 +- modules/recast/config.py | 4 ++-- modules/regex/config.py | 2 +- modules/squish/config.py | 10 +++------- modules/stb_vorbis/config.py | 2 +- modules/svg/config.py | 2 +- modules/tga/config.py | 2 +- modules/thekla_unwrap/config.py | 8 +++----- modules/theora/config.py | 2 +- modules/tinyexr/config.py | 10 +++------- modules/visual_script/config.py | 2 +- modules/vorbis/config.py | 2 +- modules/webm/config.py | 4 ++-- modules/webp/config.py | 2 +- modules/websocket/config.py | 4 +--- 33 files changed, 53 insertions(+), 61 deletions(-) diff --git a/SConstruct b/SConstruct index 63105bfa84..3056e03d48 100644 --- a/SConstruct +++ b/SConstruct @@ -396,7 +396,17 @@ if selected_platform in platform_list: sys.path.append(tmppath) env.current_module = x import config - if (config.can_build(selected_platform)): + # can_build changed number of arguments between 3.0 (1) and 3.1 (2), + # so try both to preserve compatibility for 3.0 modules + can_build = False + try: + can_build = config.can_build(env, selected_platform) + except TypeError: + print("Warning: module '%s' uses a deprecated `can_build` " + "signature in its config.py file, it should be " + "`can_build(env, platform)`." % x) + can_build = config.can_build(selected_platform) + if (can_build): config.configure(env) env.module_list.append(x) try: diff --git a/modules/bmp/config.py b/modules/bmp/config.py index fb920482f5..1c8cd12a2d 100644 --- a/modules/bmp/config.py +++ b/modules/bmp/config.py @@ -1,7 +1,5 @@ - -def can_build(platform): +def can_build(env, platform): return True - def configure(env): pass diff --git a/modules/bullet/config.py b/modules/bullet/config.py index 0a31c2e503..92dbcf5cb0 100644 --- a/modules/bullet/config.py +++ b/modules/bullet/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/csg/config.py b/modules/csg/config.py index 5e1d916790..38ccc66d91 100644 --- a/modules/csg/config.py +++ b/modules/csg/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/dds/config.py b/modules/dds/config.py index 5f133eba90..1c8cd12a2d 100644 --- a/modules/dds/config.py +++ b/modules/dds/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/enet/config.py b/modules/enet/config.py index 8031fbb4b6..3e30bbe778 100644 --- a/modules/enet/config.py +++ b/modules/enet/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/etc/config.py b/modules/etc/config.py index 395fc1bb02..098f1eafa9 100644 --- a/modules/etc/config.py +++ b/modules/etc/config.py @@ -1,9 +1,5 @@ -def can_build(platform): - return True +def can_build(env, platform): + return env['tools'] def configure(env): - # Tools only, disabled for non-tools - # TODO: Find a cleaner way to achieve that - if not env['tools']: - env['module_etc_enabled'] = False - env.disabled_modules.append("etc") + pass diff --git a/modules/freetype/config.py b/modules/freetype/config.py index 5f133eba90..1c8cd12a2d 100644 --- a/modules/freetype/config.py +++ b/modules/freetype/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/gdnative/config.py b/modules/gdnative/config.py index 68148c4d87..626e9239f8 100644 --- a/modules/gdnative/config.py +++ b/modules/gdnative/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/gdscript/config.py b/modules/gdscript/config.py index 6496b59d75..95b40d90af 100644 --- a/modules/gdscript/config.py +++ b/modules/gdscript/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/gridmap/config.py b/modules/gridmap/config.py index a93f4edb81..5022116c9b 100644 --- a/modules/gridmap/config.py +++ b/modules/gridmap/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/hdr/config.py b/modules/hdr/config.py index 5f133eba90..1c8cd12a2d 100644 --- a/modules/hdr/config.py +++ b/modules/hdr/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/jpg/config.py b/modules/jpg/config.py index 5f133eba90..1c8cd12a2d 100644 --- a/modules/jpg/config.py +++ b/modules/jpg/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/mbedtls/config.py b/modules/mbedtls/config.py index 5f133eba90..1c8cd12a2d 100755 --- a/modules/mbedtls/config.py +++ b/modules/mbedtls/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/mobile_vr/config.py b/modules/mobile_vr/config.py index aa8ef111d3..4912457e2b 100644 --- a/modules/mobile_vr/config.py +++ b/modules/mobile_vr/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): # should probably change this to only be true on iOS and Android return False diff --git a/modules/mono/config.py b/modules/mono/config.py index 18d9c67795..3afb8a8892 100644 --- a/modules/mono/config.py +++ b/modules/mono/config.py @@ -19,7 +19,7 @@ def find_file_in_dir(directory, files, prefix='', extension=''): return '' -def can_build(platform): +def can_build(env, platform): if platform in ["javascript"]: return False # Not yet supported return True diff --git a/modules/ogg/config.py b/modules/ogg/config.py index 5f133eba90..1c8cd12a2d 100644 --- a/modules/ogg/config.py +++ b/modules/ogg/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/opus/config.py b/modules/opus/config.py index 60f8d838d6..a1cde10ea0 100644 --- a/modules/opus/config.py +++ b/modules/opus/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/pvr/config.py b/modules/pvr/config.py index 5f133eba90..1c8cd12a2d 100644 --- a/modules/pvr/config.py +++ b/modules/pvr/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/recast/config.py b/modules/recast/config.py index fc074cf661..098f1eafa9 100644 --- a/modules/recast/config.py +++ b/modules/recast/config.py @@ -1,5 +1,5 @@ -def can_build(platform): - return platform != "android" +def can_build(env, platform): + return env['tools'] def configure(env): pass diff --git a/modules/regex/config.py b/modules/regex/config.py index cb2da26738..42cfe3b43c 100644 --- a/modules/regex/config.py +++ b/modules/regex/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/squish/config.py b/modules/squish/config.py index 97c95999c8..098f1eafa9 100644 --- a/modules/squish/config.py +++ b/modules/squish/config.py @@ -1,9 +1,5 @@ -def can_build(platform): - return True +def can_build(env, platform): + return env['tools'] def configure(env): - # Tools only, disabled for non-tools - # TODO: Find a cleaner way to achieve that - if not env['tools']: - env['module_squish_enabled'] = False - env.disabled_modules.append("squish") + pass diff --git a/modules/stb_vorbis/config.py b/modules/stb_vorbis/config.py index defe8d0c94..d75e41797a 100644 --- a/modules/stb_vorbis/config.py +++ b/modules/stb_vorbis/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/svg/config.py b/modules/svg/config.py index 5f133eba90..1c8cd12a2d 100644 --- a/modules/svg/config.py +++ b/modules/svg/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/tga/config.py b/modules/tga/config.py index 5f133eba90..1c8cd12a2d 100644 --- a/modules/tga/config.py +++ b/modules/tga/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/thekla_unwrap/config.py b/modules/thekla_unwrap/config.py index b1ce7d4b91..bd092bdc16 100644 --- a/modules/thekla_unwrap/config.py +++ b/modules/thekla_unwrap/config.py @@ -1,7 +1,5 @@ -def can_build(platform): - return platform != "android" and platform != "ios" +def can_build(env, platform): + return (env['tools'] and platform not in ["android", "ios"]) def configure(env): - if not env['tools']: - env['builtin_thekla_atlas'] = False - env.disabled_modules.append("thekla_unwrap") + pass diff --git a/modules/theora/config.py b/modules/theora/config.py index 34d34f8be2..7504166237 100644 --- a/modules/theora/config.py +++ b/modules/theora/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/tinyexr/config.py b/modules/tinyexr/config.py index e12bb398ce..098f1eafa9 100644 --- a/modules/tinyexr/config.py +++ b/modules/tinyexr/config.py @@ -1,9 +1,5 @@ -def can_build(platform): - return True +def can_build(env, platform): + return env['tools'] def configure(env): - # Tools only, disabled for non-tools - # TODO: Find a cleaner way to achieve that - if not env['tools']: - env['module_tinyexr_enabled'] = False - env.disabled_modules.append("tinyexr") + pass diff --git a/modules/visual_script/config.py b/modules/visual_script/config.py index 6b1ce41014..07a0450734 100644 --- a/modules/visual_script/config.py +++ b/modules/visual_script/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/vorbis/config.py b/modules/vorbis/config.py index 5f133eba90..1c8cd12a2d 100644 --- a/modules/vorbis/config.py +++ b/modules/vorbis/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/webm/config.py b/modules/webm/config.py index dcae4447d5..72a4073423 100644 --- a/modules/webm/config.py +++ b/modules/webm/config.py @@ -1,5 +1,5 @@ -def can_build(platform): - return platform != 'iphone' +def can_build(env, platform): + return platform not in ['iphone'] def configure(env): pass diff --git a/modules/webp/config.py b/modules/webp/config.py index 5f133eba90..1c8cd12a2d 100644 --- a/modules/webp/config.py +++ b/modules/webp/config.py @@ -1,4 +1,4 @@ -def can_build(platform): +def can_build(env, platform): return True def configure(env): diff --git a/modules/websocket/config.py b/modules/websocket/config.py index 399ca88fc1..f59ef432b4 100644 --- a/modules/websocket/config.py +++ b/modules/websocket/config.py @@ -1,8 +1,6 @@ - -def can_build(platform): +def can_build(env, platform): return True - def configure(env): pass -- cgit v1.2.3