-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild_run.sh
More file actions
executable file
·187 lines (167 loc) · 7.35 KB
/
Copy pathbuild_run.sh
File metadata and controls
executable file
·187 lines (167 loc) · 7.35 KB
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
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_ROOT="${BUILD_ROOT:-${SCRIPT_DIR}/build/macos}"
RUN_ROOT="${RUN_ROOT:-${SCRIPT_DIR}/build/run}"
CONFIGURATION="${CONFIGURATION:-Release}"
CLEAN_FRONTEND_BUILD="${CLEAN_FRONTEND_BUILD:-0}"
require_tool() {
if ! command -v "$1" >/dev/null 2>&1; then
echo "error: required tool '$1' was not found on PATH" >&2
exit 1
fi
}
require_tool /usr/bin/xcodebuild
require_tool aa
require_tool dwarfdump
require_tool lipo
frontend_symbols_are_usable() {
local dsym_path="$1"
local dsym_statistics
[[ -d "${dsym_path}" ]] || return 1
dsym_statistics="$(dwarfdump --statistics "${dsym_path}" 2>/dev/null)" || return 1
[[ "${dsym_statistics}" == *'"#functions":'* ]] &&
[[ "${dsym_statistics}" != *'"#functions": 0'* ]] &&
[[ "${dsym_statistics}" == *'"#bytes with line information":'* ]] &&
[[ "${dsym_statistics}" != *'"#bytes with line information": 0'* ]]
}
frontend_symbols_match_bundle() {
local bundle_binary="$1"
local dsym_path="$2"
local bundle_uuids
local dsym_uuids
bundle_uuids="$(dwarfdump --uuid "${bundle_binary}" | awk '{ print $2, $3 }' | LC_ALL=C sort)"
dsym_uuids="$(dwarfdump --uuid "${dsym_path}" | awk '{ print $2, $3 }' | LC_ALL=C sort)"
[[ -n "${bundle_uuids}" && "${bundle_uuids}" == "${dsym_uuids}" ]]
}
validate_frontend_symbols() {
local bundle_path="$1"
local dsym_path="$2"
local bundle_binary="${bundle_path}/Contents/MacOS/Outer Shell"
local bundle_uuids
local dsym_uuids
if [[ ! -f "${bundle_binary}" ]]; then
echo "error: frontend executable not found at ${bundle_binary}" >&2
exit 1
fi
if [[ ! -d "${dsym_path}" ]]; then
echo "error: frontend dSYM not found at ${dsym_path}" >&2
exit 1
fi
if ! frontend_symbols_are_usable "${dsym_path}"; then
echo "error: frontend dSYM has no usable function or source-line information" >&2
echo " ${dsym_path}" >&2
echo " Run a clean frontend build before packaging." >&2
exit 1
fi
if ! frontend_symbols_match_bundle "${bundle_binary}" "${dsym_path}"; then
bundle_uuids="$(dwarfdump --uuid "${bundle_binary}" | awk '{ print $2, $3 }' | LC_ALL=C sort)"
dsym_uuids="$(dwarfdump --uuid "${dsym_path}" | awk '{ print $2, $3 }' | LC_ALL=C sort)"
echo "error: frontend executable and dSYM UUIDs do not match" >&2
echo "Executable UUIDs:" >&2
printf '%s\n' "${bundle_uuids}" >&2
echo "dSYM UUIDs:" >&2
printf '%s\n' "${dsym_uuids}" >&2
exit 1
fi
}
build_frontend() {
/usr/bin/xcodebuild \
-project "${SCRIPT_DIR}/outershell.xcodeproj" \
-scheme "Outer Shell" \
-configuration "${CONFIGURATION}" \
SYMROOT="${BUILD_ROOT}" \
ARCHS="arm64 x86_64" \
ONLY_ACTIVE_ARCH=NO \
CODE_SIGNING_ALLOWED=NO \
CODE_SIGNING_REQUIRED=NO \
"$@" \
build
}
rm -rf "${RUN_ROOT}"
mkdir -p \
"${BUILD_ROOT}" \
"${RUN_ROOT}/bundles"
echo "==> Building Outer Shell.bundle"
frontend_bundle_path="${BUILD_ROOT}/${CONFIGURATION}/Outer Shell.bundle"
frontend_bundle_binary="${frontend_bundle_path}/Contents/MacOS/Outer Shell"
frontend_dsym_path="${BUILD_ROOT}/${CONFIGURATION}/Outer Shell.bundle.dSYM"
frontend_object_root=""
frontend_dsym_backup_root=""
frontend_dsym_backup=""
if [[ "${CLEAN_FRONTEND_BUILD}" == 1 ]]; then
frontend_object_root="$(mktemp -d "${TMPDIR:-/tmp}/outershell-frontend-build.XXXXXX")"
trap 'rm -rf "${frontend_object_root}"' EXIT
build_frontend "OBJROOT=${frontend_object_root}"
else
if frontend_symbols_are_usable "${frontend_dsym_path}" &&
frontend_symbols_match_bundle "${frontend_bundle_binary}" "${frontend_dsym_path}"; then
frontend_dsym_backup_root="$(mktemp -d "${TMPDIR:-/tmp}/outershell-symbol-backup.XXXXXX")"
frontend_dsym_backup="${frontend_dsym_backup_root}/Outer Shell.bundle.dSYM"
trap 'rm -rf "${frontend_dsym_backup_root}"' EXIT
ditto "${frontend_dsym_path}" "${frontend_dsym_backup}"
fi
build_frontend
if ! frontend_symbols_are_usable "${frontend_dsym_path}" &&
[[ -n "${frontend_dsym_backup}" ]] &&
frontend_symbols_match_bundle "${frontend_bundle_binary}" "${frontend_dsym_backup}"; then
echo "==> Restoring matching frontend dSYM after unchanged incremental build"
ditto "${frontend_dsym_backup}" "${frontend_dsym_path}"
fi
fi
validate_frontend_symbols \
"${frontend_bundle_path}" \
"${frontend_dsym_path}"
if [[ -n "${frontend_object_root}" ]]; then
rm -rf "${frontend_object_root}"
frontend_object_root=""
fi
if [[ -n "${frontend_dsym_backup_root}" ]]; then
rm -rf "${frontend_dsym_backup_root}"
frontend_dsym_backup_root=""
fi
trap - EXIT
echo "==> Building outershelld"
/usr/bin/xcodebuild \
-project "${SCRIPT_DIR}/outershell.xcodeproj" \
-target outershelld \
-configuration "${CONFIGURATION}" \
SYMROOT="${BUILD_ROOT}" \
ARCHS="arm64 x86_64" \
ONLY_ACTIVE_ARCH=NO \
build
echo "==> Building Outer Shell agent"
/usr/bin/xcodebuild \
-project "${SCRIPT_DIR}/outershell.xcodeproj" \
-target OuterShellAgent \
-configuration "${CONFIGURATION}" \
SYMROOT="${BUILD_ROOT}" \
ONLY_ACTIVE_ARCH=YES \
build
echo "==> Archiving OuterShell bundles"
"${SCRIPT_DIR}/Scripts/archive_outershell_bundle.sh" \
"${BUILD_ROOT}/${CONFIGURATION}/Outer Shell.bundle" \
"${RUN_ROOT}/bundles" \
OuterShell.bundle
rm -rf "${BUILD_ROOT}/${CONFIGURATION}/Outer Shell.app/Contents/Resources/bundles"
mkdir -p "${BUILD_ROOT}/${CONFIGURATION}/Outer Shell.app/Contents/Resources/bundles"
cp "${RUN_ROOT}/bundles"/OuterShell.bundle.*.aar \
"${BUILD_ROOT}/${CONFIGURATION}/Outer Shell.app/Contents/Resources/bundles/"
cp "${SCRIPT_DIR}/app-icon.png" \
"${BUILD_ROOT}/${CONFIGURATION}/Outer Shell.app/Contents/Resources/app-icon.png"
cp "${SCRIPT_DIR}/OuterShell.icns" \
"${BUILD_ROOT}/${CONFIGURATION}/Outer Shell.app/Contents/Resources/OuterShell.icns"
rm -rf "${BUILD_ROOT}/${CONFIGURATION}/Outer Shell.app/Contents/Resources/web"
cp -R "${SCRIPT_DIR}/Resources/OuterShellWeb" \
"${BUILD_ROOT}/${CONFIGURATION}/Outer Shell.app/Contents/Resources/web"
rm -rf "${BUILD_ROOT}/${CONFIGURATION}/Outer Shell.app/Contents/Resources/bundled-apps"
echo "Built:"
echo " ${BUILD_ROOT}/${CONFIGURATION}/outershelld"
echo " ${BUILD_ROOT}/${CONFIGURATION}/Outer Shell.app"
echo " ${RUN_ROOT}/bundles"
echo
echo "Run:"
echo " API_SOCKET=\"$(getconf DARWIN_USER_TEMP_DIR)outershelld-api\""
echo " \"${BUILD_ROOT}/${CONFIGURATION}/outershelld\" --api-socket-path \"\$API_SOCKET\" &"
echo " clang -std=gnu17 -DOUTER_SHELL_BACKEND_STANDALONE=1 Backend/OuterShellBuffer.c Backend/OuterShellAPI.c Backend/OuterShellPlatform.c Backend/OuterShellDownloaderApple.m Backend/OuterShellBackend.c -framework Foundation -o /tmp/OuterShellBackend && /tmp/OuterShellBackend --port 7354 --api-socket-path \"\$API_SOCKET\" --bundles-dir \"${RUN_ROOT}/bundles\" --web-root \"${SCRIPT_DIR}/Resources/OuterShellWeb\" --native-app-template-dir \"${SCRIPT_DIR}/Resources/NativeAppTemplate\""
echo " \"${BUILD_ROOT}/${CONFIGURATION}/Outer Shell.app/Contents/MacOS/Outer Shell\" --socket-path \"$(getconf DARWIN_USER_TEMP_DIR)org.outershell.OuterShell\" --app-base-url \"https://outershell.org/outer-shell/apps\""