-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathSCsub
130 lines (110 loc) · 4.28 KB
/
SCsub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python3
import re
import os
import glob
import builders
Import("env")
env_goost = env.Clone()
# Make include paths independent of Goost location.
# This is needed for modules copied directly under `modules/` directory,
# but not if someone uses `custom_modules` option.
env_goost.Prepend(CPPPATH=[os.path.dirname(os.path.realpath(os.curdir))])
# Define components to build.
for name in env["goost_components_enabled"]:
opt = "goost_%s_enabled" % (name)
env_goost.Prepend(CPPDEFINES=[opt.upper()])
# Generate sources with a list of enabled and disabled classes.
classgen_sources = ["goost.py"]
if File("custom.py").exists():
# Can be configured via `custom.py`, track changes there as well.
classgen_sources.append("custom.py")
env.CommandNoCache(
["classes_enabled.gen.h", "classes_enabled.gen.cpp"], classgen_sources,
builders.make_classes_enabled,
)
# Generate version header.
env.CommandNoCache(
"core/version.gen.h", "goost.py",
builders.make_version_header,
)
# Authors.
env.CommandNoCache(
"core/authors.gen.h", "AUTHORS.md",
builders.make_authors_header,
)
# License.
env.CommandNoCache(
"core/license.gen.h", ["COPYRIGHT.txt", "LICENSE.txt"],
builders.make_license_header,
)
env_goost.Prepend(CPPDEFINES={"SCALE_FACTOR" : env["goost_scale_factor"]})
# Inject our own version of `add_source_files` (found in methods.py in Godot).
# This is needed to filter out the sources of disabled classes without
# modifying each and every SCSub file, making it work everywhere in Goost.
godot_add_source_files = env_goost.__class__.add_source_files
def goost_add_source_files(self, sources, files):
from compat import isbasestring
# Convert string to list of absolute paths (including expanding wildcard)
if isbasestring(files):
# Keep SCons project-absolute path as they are (no wildcard support)
if files.startswith("#"):
if "*" in files:
print("ERROR: Wildcards can't be expanded in SCons project-absolute path: '{}'".format(files))
return
files = [files]
else:
# Exclude .gen.cpp files from globbing, to avoid including obsolete ones.
# They should instead be added manually.
skip_gen_cpp = "*" in files
dir_path = self.Dir(".").abspath
files = sorted(glob.glob(dir_path + "/" + files))
if skip_gen_cpp:
files = [f for f in files if not f.endswith(".gen.cpp")]
# Flatten.
_files = []
for path in files:
if isinstance(path, list):
for p in path:
_files.append(p.abspath)
elif isinstance(path, str):
_files.append(path)
else:
_files.append(path.abspath)
files = _files
def to_snake_case(pascal):
# https://stackoverflow.com/a/33516645/
return re.sub(r'([A-Z]*)([A-Z][a-z]+)', lambda x: (x.group(1) + '_' if x.group(1) else '') + x.group(2) + '_', pascal).rstrip('_').lower()
# Add each path as compiled Object following environment (self) configuration
for path in files:
# Skip compiling sources of disabled Goost classes.
skip = False
for c in self["goost_classes_disabled"]:
n = "%s.*\.cpp" % to_snake_case(c)
if re.search(n, path):
skip = True
break
if skip:
continue
obj = self.Object(path)
if obj in sources:
print('WARNING: Object "{}" already included in environment sources.'.format(obj))
continue
sources.append(obj)
# Inject now!
env_goost.__class__.add_source_files = goost_add_source_files
# Add sources.
Export("env_goost")
if env["goost_core_enabled"]:
SConscript("core/SCsub")
else:
core_sources = ["core/string_names.cpp"]
env_goost.add_source_files(env.modules_sources, core_sources)
if env["goost_scene_enabled"]:
SConscript("scene/SCsub")
if env["goost_editor_enabled"]:
SConscript("editor/SCsub")
SConscript("thirdparty/SCsub")
env_goost.add_source_files(env.modules_sources, "register_types.cpp")
env_goost.add_source_files(env.modules_sources, "classes_enabled.gen.cpp")
# Restore the method back (not sure if needed, but good for consistency).
env_goost.__class__.add_source_files = godot_add_source_files