-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSConstruct
304 lines (252 loc) · 8.73 KB
/
SConstruct
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/usr/bin/env python
import os
import sys
import subprocess
from functools import partial
# *** Setting.
VERSION = "0.2.0-dev"
PROJECT_DIR = "project"
EXTENSION_NAME = "sentrysdk"
COMPATIBILITY_MINIMUM = "4.3"
BIN_DIR = "{project_dir}/addons/{extension_name}/bin".format(
project_dir=PROJECT_DIR, extension_name=EXTENSION_NAME
)
def run_cmd(**kwargs):
"""Run command in a subprocess and return its exit code."""
result = subprocess.run(
kwargs["args"],
check=True,
)
return result.returncode
# *** Generate version header.
print("Generating SDK version header...")
git_sha = "unknown"
try:
cmd = ["git", "rev-parse", "--short", "HEAD"]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
git_sha = proc.communicate()[0].strip().decode("utf-8")
except:
pass
version_header_content = """/* DO NOT EDIT - generated by SConstruct */
#ifndef SENTRY_GODOT_SDK_VERSION_GEN_H
#define SENTRY_GODOT_SDK_VERSION_GEN_H
#define SENTRY_GODOT_SDK_VERSION \"{version}+{git_sha}\"
#endif // SENTRY_GODOT_SDK_VERSION_GEN_H
""".format(version=VERSION, git_sha=git_sha)
with open("src/sdk_version.gen.h", "w") as f:
f.write(version_header_content)
# *** Build godot-cpp.
print("Reading godot-cpp build configuration...")
env = SConscript("modules/godot-cpp/SConstruct")
# *** Build sentry-native.
# TODO: macOS needs to use a different SDK.
if env["platform"] in ["linux", "macos"]:
def build_sentry_native(target, source, env):
result = subprocess.run(
["sh", "scripts/build-sentry-native.sh"],
check=True,
)
return result.returncode
crashpad_handler_target = "{bin}/{platform}/crashpad_handler".format(
bin=BIN_DIR,
platform=env["platform"]
)
sentry_native = env.Command(
[
"modules/sentry-native/install/lib/libsentry.a",
crashpad_handler_target,
],
["modules/sentry-native/src"],
[
build_sentry_native,
Copy(
crashpad_handler_target,
"modules/sentry-native/install/bin/crashpad_handler",
),
],
)
elif env["platform"] == "windows":
def build_sentry_native(target, source, env):
result = subprocess.run(
["powershell", "scripts/build-sentry-native.ps1"],
check=True,
)
return result.returncode
sentry_native = env.Command(
["modules/sentry-native/install/lib/sentry.lib", BIN_DIR + "/windows/crashpad_handler.exe"],
["modules/sentry-native/src/"],
[
build_sentry_native,
Copy(
BIN_DIR + "/windows/crashpad_handler.exe",
"modules/sentry-native/install/bin/crashpad_handler.exe",
),
],
)
if env["platform"] in ["linux", "macos", "windows"]:
Depends(sentry_native, "modules/godot-cpp") # Force sentry-native to be built sequential to godot-cpp (not in parallel)
Default(sentry_native)
Clean(sentry_native, ["modules/sentry-native/build", "modules/sentry-native/install"])
# Include relative to project source root.
env.Append(CPPPATH=["src/"])
# Include sentry-native libs (static).
if env["platform"] in ["linux", "macos", "windows"]:
env.Append(CPPDEFINES=["SENTRY_BUILD_STATIC", "NATIVE_SDK"])
env.Append(CPPPATH=["modules/sentry-native/include"])
env.Append(LIBPATH=["modules/sentry-native/install/lib/"])
sn_targets = []
sn_sources = ["modules/sentry-native/src/"]
def add_target(lib_name):
env.Append(LIBS=[lib_name])
if env["platform"] == "windows":
sn_targets.append("modules/sentry-native/install/lib/" + lib_name + ".lib")
sn_targets.append("modules/sentry-native/install/lib/" + lib_name + ".pdb")
else:
sn_targets.append("modules/sentry-native/install/lib/lib" + lib_name + ".a")
add_target("sentry")
add_target("crashpad_client")
add_target("crashpad_handler_lib")
add_target("crashpad_minidump")
add_target("crashpad_snapshot")
add_target("crashpad_tools")
add_target("crashpad_util")
add_target("mini_chromium")
# Include additional platform-specific libs.
if env["platform"] == "windows":
add_target("crashpad_compat")
env.Append(
LIBS=[
"winhttp",
"advapi32",
"DbgHelp",
"Version",
]
)
elif env["platform"] == "linux":
add_target("crashpad_compat")
env.Append(
LIBS=[
"curl",
]
)
elif env["platform"] == "macos":
env.Append(
LIBS=[
"curl",
]
)
build_actions = []
dest_dir = BIN_DIR + "/" + env["platform"]
if env["platform"] == "windows":
build_actions.append(
partial(run_cmd, args=["powershell", "scripts/build-sentry-native.ps1"])
),
build_actions.append(
Copy(
dest_dir + "/crashpad_handler.exe",
"modules/sentry-native/install/bin/crashpad_handler.exe",
)
)
build_actions.append(
Copy(
dest_dir + "/crashpad_handler.pdb",
"modules/sentry-native/install/bin/crashpad_handler.pdb",
)
)
sn_targets.append(dest_dir + "/crashpad_handler.exe")
sn_targets.append(dest_dir + "/crashpad_handler.pdb")
else:
# TODO: macOS needs to use a different SDK.
build_actions.append(
partial(run_cmd, args=[
"sh", "scripts/build-sentry-native.sh",
"--macos-deployment-target", env["macos_deployment_target"]
])
),
build_actions.append(
Copy(
dest_dir + "/crashpad_handler",
"modules/sentry-native/install/bin/crashpad_handler",
)
)
sn_targets.append(dest_dir + "/crashpad_handler")
sentry_native = env.Command(sn_targets, sn_sources, build_actions)
# Force sentry-native to be built sequential to godot-cpp (not in parallel).
Depends(sentry_native, "modules/godot-cpp")
Default(sentry_native)
Clean(sentry_native, ["modules/sentry-native/build", "modules/sentry-native/install"])
# *** Build GDExtension library.
# Include relative to project source root.
env.Append(CPPPATH=["src/"])
# Source files to compile.
sources = Glob("src/*.cpp")
sources += Glob("src/sentry/*.cpp")
# Compile sentry-native code only on respective platforms.
if env["platform"] in ["linux", "windows", "macos"]:
sources += Glob("src/sentry/native/*.cpp")
build_type = "release" if env["target"] == "template_release" else "debug"
if env["platform"] == "macos":
library = env.SharedLibrary(
"{bin}/{platform}/lib{name}.{platform}.{build_type}.framework/lib{name}.{platform}.{build_type}".format(
bin=BIN_DIR,
name=EXTENSION_NAME,
platform=env["platform"],
build_type=build_type,
),
source=sources,
)
else:
library = env.SharedLibrary(
"{bin}/{platform}/lib{name}.{platform}.{build_type}.{arch}{shlib_suffix}".format(
bin=BIN_DIR,
name=EXTENSION_NAME,
platform=env["platform"],
build_type=build_type,
arch=env["arch"],
shlib_suffix=env["SHLIBSUFFIX"],
),
source=sources,
)
Default(library)
# *** Deploy extension manifest.
manifest = env.Substfile(
target="{bin}/{name}.gdextension".format(
bin=BIN_DIR,
name=EXTENSION_NAME,
),
source="src/manifest.gdextension",
SUBST_DICT={
"{name}": EXTENSION_NAME,
"{compatibility_minimum}": COMPATIBILITY_MINIMUM,
},
)
Default(manifest)
# *** Create symbolic link from project addons dir to gdUnit4 testing framework submodule.
def symlink(target, source, env):
# Note: parameter `target` is a list of build targets.
assert len(target) == 1
assert len(source) == 1
dst = str(target[0])
src = str(source[0])
if env["platform"] == "windows":
# Create NTFS junction.
# Note: Windows requires elevated privileges to create symlinks, so we're creating NTFS junction instead.
try:
import _winapi
_winapi.CreateJunction(src, dst)
except Exception as e:
# Don't fail the build if this step fails.
print("WARNING: Failed to create NTFS junction for gdUnit4: ", str(e))
else:
# Create symlink.
src = os.path.relpath(src, os.path.dirname(dst))
os.symlink(src, dst)
return 0
gdunit_symlink = env.Command(
PROJECT_DIR + "/addons/gdUnit4",
"modules/gdUnit4/addons/gdUnit4",
[
symlink,
],
)
Default(gdunit_symlink)