Skip to content

Commit 3495288

Browse files
committedFeb 8, 2022
SCons: Improve logic to generate modules_tests.gen.h
This removes the need for `AlwaysBuild` by ensuring that the proper files are being tracked as `Depends`.
1 parent f425d40 commit 3495288

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed
 

‎modules/SCsub

+27-18
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,45 @@ env.CommandNoCache(
2222
),
2323
)
2424

25-
# Header to be included in `tests/test_main.cpp` to run module-specific tests.
26-
if env["tests"]:
27-
env.Depends("modules_tests.gen.h", Value(env.module_list))
28-
env.CommandNoCache(
29-
"modules_tests.gen.h",
30-
Value(env.module_list),
31-
env.Run(
32-
modules_builders.generate_modules_tests,
33-
"Generating modules tests header.",
34-
# NOTE: No need to run in subprocess since this is still executed serially.
35-
subprocess=False,
36-
),
37-
)
38-
env.AlwaysBuild("modules_tests.gen.h")
3925

4026
vs_sources = []
27+
test_headers = []
4128
# libmodule_<name>.a for each active module.
4229
for name, path in env.module_list.items():
4330
env.modules_sources = []
4431

45-
if not os.path.isabs(path):
46-
SConscript(name + "/SCsub") # Built-in.
47-
else:
48-
SConscript(path + "/SCsub") # Custom.
32+
# Name for built-in modules, (absolute) path for custom ones.
33+
base_path = path if os.path.isabs(path) else name
34+
SConscript(base_path + "/SCsub")
4935

5036
lib = env_modules.add_library("module_%s" % name, env.modules_sources)
5137
env.Prepend(LIBS=[lib])
5238
if env["vsproj"]:
5339
vs_sources += env.modules_sources
5440

41+
if env["tests"]:
42+
# Lookup potential headers in `tests` subfolder.
43+
import glob
44+
45+
module_tests = sorted(glob.glob(os.path.join(base_path, "tests", "*.h")))
46+
if module_tests != []:
47+
test_headers += module_tests
48+
49+
50+
# Generate header to be included in `tests/test_main.cpp` to run module-specific tests.
51+
if env["tests"]:
52+
env.Depends("modules_tests.gen.h", test_headers)
53+
env.CommandNoCache(
54+
"modules_tests.gen.h",
55+
test_headers,
56+
env.Run(
57+
modules_builders.generate_modules_tests,
58+
"Generating modules tests header.",
59+
# NOTE: No need to run in subprocess since this is still executed serially.
60+
subprocess=False,
61+
),
62+
)
63+
5564
# libmodules.a with only register_module_types.
5665
# Must be last so that all libmodule_<name>.a libraries are on the right side
5766
# in the linker command.

‎modules/modules_builders.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,10 @@ def generate_modules_enabled(target, source, env):
1414

1515
def generate_modules_tests(target, source, env):
1616
import os
17-
import glob
1817

1918
with open(target[0].path, "w") as f:
20-
for name, path in env.module_list.items():
21-
headers = glob.glob(os.path.join(path, "tests", "*.h"))
22-
for h in headers:
23-
f.write('#include "%s"\n' % (os.path.normpath(h)))
19+
for header in source:
20+
f.write('#include "%s"\n' % (os.path.normpath(header.path)))
2421

2522

2623
if __name__ == "__main__":

0 commit comments

Comments
 (0)
Please sign in to comment.