From b7297fb39ca7a55390f9390666bd29803adc827f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 6 Feb 2020 17:28:32 +0100 Subject: SCons: Generate header with info on which modules are enabled We already had `MODULE_*_ENABLED` defines but only in the modules environment, and a few custom `*_ENABLED` defines in the main env when we needed the information in core. Now this is defined in a single header which can be included in the files that need this information. --- SConstruct | 4 ++-- core/core_builders.py | 2 +- methods.py | 43 +++++++++-------------------------------- modules/SCsub | 12 ++++++------ modules/modules_builders.py | 16 +++++++++++++++ modules/register_module_types.h | 4 +--- 6 files changed, 35 insertions(+), 46 deletions(-) create mode 100644 modules/modules_builders.py diff --git a/SConstruct b/SConstruct index 6703038bed..b9698601c3 100644 --- a/SConstruct +++ b/SConstruct @@ -410,7 +410,7 @@ if selected_platform in platform_list: env.module_icons_paths = [] env.doc_class_path = {} - for x in module_list: + for x in sorted(module_list): if not env['module_' + x + '_enabled']: continue tmppath = "./modules/" + x @@ -427,7 +427,7 @@ if selected_platform in platform_list: "signature in its config.py file, it should be " "`can_build(env, platform)`." % x) can_build = config.can_build(selected_platform) - if (can_build): + if can_build: config.configure(env) env.module_list.append(x) diff --git a/core/core_builders.py b/core/core_builders.py index f3a9e3b221..7720183595 100644 --- a/core/core_builders.py +++ b/core/core_builders.py @@ -1,8 +1,8 @@ """Functions used to generate source files during build time All such functions are invoked in a subprocess on Windows to prevent build flakiness. - """ + from platform_methods import subprocess_main from compat import iteritems, itervalues, open_utf8, escape_string, byte_to_str diff --git a/methods.py b/methods.py index 33b8f1cbe7..39981406c7 100644 --- a/methods.py +++ b/methods.py @@ -160,20 +160,22 @@ def detect_modules(): except IOError: pass - modules_cpp = """ -// modules.cpp - THIS FILE IS GENERATED, DO NOT EDIT!!!!!!! + modules_cpp = """// register_module_types.gen.cpp +/* THIS FILE IS GENERATED DO NOT EDIT */ #include "register_module_types.h" -""" + includes_cpp + """ +#include "modules/modules_enabled.gen.h" + +%s void register_module_types() { -""" + register_cpp + """ +%s } void unregister_module_types() { -""" + unregister_cpp + """ +%s } -""" +""" % (includes_cpp, register_cpp, unregister_cpp) # NOTE: It is safe to generate this file here, since this is still executed serially with open("modules/register_module_types.gen.cpp", "w") as f: @@ -200,38 +202,11 @@ def win32_spawn(sh, escape, cmd, args, env): print("=====") return rv -""" -def win32_spawn(sh, escape, cmd, args, spawnenv): - import win32file - import win32event - import win32process - import win32security - for var in spawnenv: - spawnenv[var] = spawnenv[var].encode('ascii', 'replace') - - sAttrs = win32security.SECURITY_ATTRIBUTES() - StartupInfo = win32process.STARTUPINFO() - newargs = ' '.join(map(escape, args[1:])) - cmdline = cmd + " " + newargs - - # check for any special operating system commands - if cmd == 'del': - for arg in args[1:]: - win32file.DeleteFile(arg) - exit_code = 0 - else: - # otherwise execute the command. - hProcess, hThread, dwPid, dwTid = win32process.CreateProcess(None, cmdline, None, None, 1, 0, spawnenv, None, StartupInfo) - win32event.WaitForSingleObject(hProcess, win32event.INFINITE) - exit_code = win32process.GetExitCodeProcess(hProcess) - win32file.CloseHandle(hProcess); - win32file.CloseHandle(hThread); - return exit_code -""" def disable_module(self): self.disabled_modules.append(self.current_module) + def use_windows_spawn_fix(self, platform=None): if (os.name != "nt"): diff --git a/modules/SCsub b/modules/SCsub index dc0420616c..75483fd637 100644 --- a/modules/SCsub +++ b/modules/SCsub @@ -2,19 +2,19 @@ Import('env') +import modules_builders + env_modules = env.Clone() Export('env_modules') -env.modules_sources = [] +env.CommandNoCache("modules_enabled.gen.h", Value(env.module_list), modules_builders.generate_modules_enabled) +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): - continue - env_modules.Append(CPPDEFINES=["MODULE_" + x.upper() + "_ENABLED"]) - SConscript(x + "/SCsub") +for module in env.module_list: + SConscript(module + "/SCsub") if env['split_libmodules']: env.split_lib("modules", env_lib = env_modules) diff --git a/modules/modules_builders.py b/modules/modules_builders.py new file mode 100644 index 0000000000..0e9cba2b0b --- /dev/null +++ b/modules/modules_builders.py @@ -0,0 +1,16 @@ +"""Functions used to generate source files during build time + +All such functions are invoked in a subprocess on Windows to prevent build flakiness. +""" + +from platform_methods import subprocess_main + + +def generate_modules_enabled(target, source, env): + with open(target[0].path, 'w') as f: + for module in env.module_list: + f.write('#define %s\n' % ("MODULE_" + module.upper() + "_ENABLED")) + + +if __name__ == '__main__': + subprocess_main(globals()) diff --git a/modules/register_module_types.h b/modules/register_module_types.h index a8eb68b929..b410457201 100644 --- a/modules/register_module_types.h +++ b/modules/register_module_types.h @@ -31,9 +31,7 @@ #ifndef REGISTER_MODULE_TYPES_H #define REGISTER_MODULE_TYPES_H -// - void register_module_types(); void unregister_module_types(); -#endif +#endif // REGISTER_MODULE_TYPES_H -- cgit v1.2.3 From f3726ee99488695c4aae22fffd3649499b285faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 6 Feb 2020 21:51:36 +0100 Subject: Use modules_enabled.gen.h to improve inter dependency checks - Fix build with gdscript module disabled. Fixes #31011. - Remove unused `gdscript` compile option. - Fix build with regex module disabled. - Fix ImageLoaderSVG to forward declare thirdparty structs. --- SConstruct | 3 --- editor/editor_themes.cpp | 6 +++++- editor/import/editor_scene_importer_gltf.cpp | 1 + editor/plugin_config_dialog.cpp | 14 +++++++++++++- main/tests/test_gdscript.cpp | 5 +++-- main/tests/test_string.cpp | 14 +++++++++----- modules/freetype/SCsub | 2 -- modules/recast/navigation_mesh_generator.cpp | 3 ++- modules/svg/SCsub | 4 ---- modules/svg/image_loader_svg.cpp | 5 ++--- modules/svg/image_loader_svg.h | 7 ++++--- scene/gui/rich_text_label.cpp | 9 ++++++++- scene/resources/dynamic_font.cpp | 5 ++++- scene/resources/dynamic_font.h | 4 +++- 14 files changed, 54 insertions(+), 28 deletions(-) diff --git a/SConstruct b/SConstruct index b9698601c3..7578a7c385 100644 --- a/SConstruct +++ b/SConstruct @@ -118,7 +118,6 @@ opts.Add(BoolVariable('use_precise_math_checks', 'Math checks use very precise e # Components opts.Add(BoolVariable('deprecated', "Enable deprecated features", True)) -opts.Add(BoolVariable('gdscript', "Enable GDScript support", True)) opts.Add(BoolVariable('minizip', "Enable ZIP archive support using minizip", True)) opts.Add(BoolVariable('xaudio2', "Enable the XAudio2 audio driver", False)) @@ -477,8 +476,6 @@ if selected_platform in platform_list: sys.exit(255) else: env.Append(CPPDEFINES=['_3D_DISABLED']) - if env['gdscript']: - env.Append(CPPDEFINES=['GDSCRIPT_ENABLED']) if env['disable_advanced_gui']: if env['tools']: print("Build option 'disable_advanced_gui=yes' cannot be used with 'tools=yes' (editor), only with 'tools=no' (export template).") diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 8037045e77..28bc20a957 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -35,7 +35,11 @@ #include "editor_icons.gen.h" #include "editor_scale.h" #include "editor_settings.h" + +#include "modules/modules_enabled.gen.h" +#ifdef MODULE_SVG_ENABLED #include "modules/svg/image_loader_svg.h" +#endif static Ref make_stylebox(Ref p_texture, float p_left, float p_top, float p_right, float p_botton, float p_margin_left = -1, float p_margin_top = -1, float p_margin_right = -1, float p_margin_botton = -1, bool p_draw_center = true) { Ref style(memnew(StyleBoxTexture)); @@ -109,7 +113,7 @@ Ref editor_generate_icon(int p_index, bool p_convert_color, float void editor_register_and_generate_icons(Ref p_theme, bool p_dark_theme = true, int p_thumb_size = 32, bool p_only_thumbs = false) { -#ifdef SVG_ENABLED +#ifdef MODULE_SVG_ENABLED // The default icon theme is designed to be used for a dark theme. // This dictionary stores color codes to convert to other colors // for better readability on a light theme. diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index fc9c877ac7..d4664e1bb9 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "editor_scene_importer_gltf.h" + #include "core/crypto/crypto_core.h" #include "core/io/json.h" #include "core/math/disjoint_set.h" diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp index 07b87633a9..1506ba319c 100644 --- a/editor/plugin_config_dialog.cpp +++ b/editor/plugin_config_dialog.cpp @@ -35,9 +35,13 @@ #include "editor/editor_plugin.h" #include "editor/editor_scale.h" #include "editor/project_settings_editor.h" -#include "modules/gdscript/gdscript.h" #include "scene/gui/grid_container.h" +#include "modules/modules_enabled.gen.h" +#ifdef MODULE_GDSCRIPT_ENABLED +#include "modules/gdscript/gdscript.h" +#endif + void PluginConfigDialog::_clear_fields() { name_edit->set_text(""); subfolder_edit->set_text(""); @@ -75,6 +79,9 @@ void PluginConfigDialog::_on_confirmed() { // TODO Use script templates. Right now, this code won't add the 'tool' annotation to other languages. // TODO Better support script languages with named classes (has_named_classes). + // FIXME: It's hacky to have hardcoded access to the GDScript module here. + // The editor code should not have to know what languages are enabled. +#ifdef MODULE_GDSCRIPT_ENABLED if (lang_name == GDScriptLanguage::get_singleton()->get_name()) { // Hard-coded GDScript template to keep usability until we use script templates. Ref