Skip to content

Commit

Permalink
SCons: Generate header with info on which modules are enabled
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akien-mga committed Feb 7, 2020
1 parent 00f4645 commit b7297fb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 46 deletions.
4 changes: 2 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion core/core_builders.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
43 changes: 9 additions & 34 deletions methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"):
Expand Down
12 changes: 6 additions & 6 deletions modules/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions modules/modules_builders.py
Original file line number Diff line number Diff line change
@@ -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())
4 changes: 1 addition & 3 deletions modules/register_module_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b7297fb

Please sign in to comment.