-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SConstruct
228 lines (196 loc) · 6.29 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
#!/usr/bin/env python
import os
import sys
import subprocess
# *** Setting.
VERSION = "0.1.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)
# *** 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",
),
],
)
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/"])
env.Append(
LIBS=[
"sentry",
"crashpad_client",
"crashpad_handler_lib",
"crashpad_minidump",
"crashpad_snapshot",
"crashpad_tools",
"crashpad_util",
"mini_chromium",
]
)
# Include additional platform-specific libs.
if env["platform"] == "windows":
env.Append(
LIBS=[
"crashpad_compat",
"winhttp",
"advapi32",
"DbgHelp",
"Version",
]
)
elif env["platform"] == "linux":
env.Append(
LIBS=[
"crashpad_compat",
"curl",
]
)
elif env["platform"] == "macos":
env.Append(
LIBS=[
"curl",
]
)
# *** Build GDExtension library.
# 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 an NTFS junction for gdUnit4 testing framework: ", 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)