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.

(cherry picked from commit b7297fb39c)
This commit is contained in:
Rémi Verschelde 2020-02-06 17:28:32 +01:00
parent aecb1c32ab
commit cbbea6084d
No known key found for this signature in database
GPG Key ID: C3336907360768E1
5 changed files with 33 additions and 22 deletions

View File

@ -1,8 +1,8 @@
"""Functions used to generate source files during build time """Functions used to generate source files during build time
All such functions are invoked in a subprocess on Windows to prevent build flakiness. All such functions are invoked in a subprocess on Windows to prevent build flakiness.
""" """
from platform_methods import subprocess_main from platform_methods import subprocess_main
from compat import iteritems, itervalues, open_utf8, escape_string, byte_to_str from compat import iteritems, itervalues, open_utf8, escape_string, byte_to_str

View File

@ -238,27 +238,25 @@ def write_modules(modules):
except IOError: except IOError:
pass pass
modules_cpp = ( modules_cpp = """// register_module_types.gen.cpp
""" /* THIS FILE IS GENERATED DO NOT EDIT */
// modules.cpp - THIS FILE IS GENERATED, DO NOT EDIT!!!!!!!
#include "register_module_types.h" #include "register_module_types.h"
""" #include "modules/modules_enabled.gen.h"
+ includes_cpp
+ """ %s
void register_module_types() { void register_module_types() {
""" %s
+ register_cpp
+ """
} }
void unregister_module_types() { void unregister_module_types() {
""" %s
+ unregister_cpp
+ """
} }
""" """ % (
includes_cpp,
register_cpp,
unregister_cpp,
) )
# NOTE: It is safe to generate this file here, since this is still executed serially # NOTE: It is safe to generate this file here, since this is still executed serially

View File

@ -4,19 +4,18 @@ Import("env")
import os import os
import modules_builders
env_modules = env.Clone() env_modules = env.Clone()
Export("env_modules") 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") env_modules.add_source_files(env.modules_sources, "register_module_types.gen.cpp")
for name, path in env.module_list.items(): 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): if not os.path.isabs(path):
SConscript(name + "/SCsub") # Built-in. SConscript(name + "/SCsub") # Built-in.
else: else:

View File

@ -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())

View File

@ -31,9 +31,7 @@
#ifndef REGISTER_MODULE_TYPES_H #ifndef REGISTER_MODULE_TYPES_H
#define REGISTER_MODULE_TYPES_H #define REGISTER_MODULE_TYPES_H
//
void register_module_types(); void register_module_types();
void unregister_module_types(); void unregister_module_types();
#endif #endif // REGISTER_MODULE_TYPES_H