Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/tests/test_builders.py
23446 views
1
"""Functions used to generate source files during build time"""
2
3
import re
4
5
import methods
6
7
RE_PATH_SPLIT = re.compile(r"[^/\\]+?(?=\.)")
8
9
TEMPLATE = """\
10
#ifndef _WIN32
11
#define TEST_DLL_PRIVATE __attribute__((visibility("hidden")))
12
#else
13
#define TEST_DLL_PRIVATE
14
#endif // _WIN32
15
16
namespace ForceLink {{
17
TEST_DLL_PRIVATE void force_link_tests();
18
{TESTS_DECLARE}
19
}} // namespace ForceLink
20
21
void ForceLink::force_link_tests() {{
22
{TESTS_CALL}
23
}}
24
"""
25
26
27
def force_link_builder(target, source, env):
28
names = [RE_PATH_SPLIT.search(str(path)).group() for path in source[0].read()]
29
declares = [f"TEST_DLL_PRIVATE void force_link_{name}();" for name in names]
30
calls = [f"force_link_{name}();" for name in names]
31
32
with methods.generated_wrapper(str(target[0])) as file:
33
file.write(
34
TEMPLATE.format(
35
TESTS_DECLARE="\n\t".join(declares),
36
TESTS_CALL="\n\t".join(calls),
37
)
38
)
39
40