diff --git a/core/core_builders.py b/core/core_builders.py index 7beaf1f5c1a..dc285b01c09 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 8e3b525cb74..22cc824ab1b 100644 --- a/methods.py +++ b/methods.py @@ -238,27 +238,25 @@ def write_modules(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 diff --git a/modules/SCsub b/modules/SCsub index d9de2c999a6..b3405bbcebc 100644 --- a/modules/SCsub +++ b/modules/SCsub @@ -4,19 +4,18 @@ Import("env") import os +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 name, path in env.module_list.items(): - if name in env.disabled_modules: - continue - - env_modules.Append(CPPDEFINES=["MODULE_" + name.upper() + "_ENABLED"]) if not os.path.isabs(path): SConscript(name + "/SCsub") # Built-in. else: diff --git a/modules/modules_builders.py b/modules/modules_builders.py new file mode 100644 index 00000000000..e7be6380d1d --- /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 9cf5567efad..66583a64c06 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