-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_app.sh
executable file
·283 lines (246 loc) · 11 KB
/
build_app.sh
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
#!/bin/bash
## Copyright 2022-present Contributors to the automator project.
## SPDX-License-Identifier: BSD-3-Clause
## https://github.com/mikaelsundell/automator
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
machine_arch=$(uname -m)
macos_version=$(sw_vers -productVersion)
major_version=$(echo "$macos_version" | cut -d '.' -f 1)
# signing
sign_code=OFF
developerid_identity=""
mac_developer_identity=""
mac_installer_identity=""
provisioning_profile=""
provisioning_profile_path=""
sign_app() {
local bundle_path="$1"
local sign_type="$2"
local sign_identity="$3"
case "$sign_type" in
dylibs)
find "$bundle_path" -type f ! -path "*.framework/*" | while read -r file; do
file_type=$(file "$file")
if [[ "$file_type" == *"Mach-O 64-bit dynamically linked shared library"* ]] || [[ "$file_type" == *"Mach-O 64-bit bundle"* ]]; then
echo "signing dylib $file ..."
codesign --force --sign "$sign_identity" --timestamp "$file"
fi
done
;;
frameworks)
find "$bundle_path" -type d -name "*.framework" | while read -r framework; do
echo "signing framework $framework ..."
codesign --force --sign "$sign_identity" --timestamp "$framework"
done
;;
executables)
find "$bundle_path" -type f | while read -r file; do
file_type=$(file "$file")
if [[ "$file_type" == *"Mach-O 64-bit executable"* ]]; then
echo "signing executable $file with entitlements ..."
echo codesign --force --sign "$sign_identity" --timestamp --options runtime --entitlements "$script_dir/resources/App.entitlements" "$file"
codesign --force --sign "$sign_identity" --timestamp --options runtime --entitlements "$script_dir/resources/App.entitlements" "$file"
fi
done
;;
*)
echo "unknown sign type: $sign_type"
exit 1
;;
esac
}
verify_app() {
local bundle_path="$1"
find "$bundle_path" -type f \( -name "*.dylib" -o -name "*.so" -o -name "*.bundle" -o -name "*.framework" -o -perm +111 \) | while read -r file; do
echo "verifying $file..."
if codesign --verify --verbose "$file"; then
echo "signature verification passed for $file"
else
echo "signature verification failed for $file"
fi
done
}
# check signing
parse_args() {
while [[ "$#" -gt 0 ]]; do
case $1 in
--target=*)
major_version="${1#*=}" ;;
--sign)
sign_code=ON ;;
--provisioning=*)
provisioning_profile="${1#*=}" ;;
--provisioningpath=*)
provisioning_profile_path="${1#*=}" ;;
--github)
github=ON ;;
--appstore)
appstore=ON ;;
*)
build_type="$1" # save it in build_type if it's not a recognized flag
;;
esac
shift
done
}
parse_args "$@"
# target
if [ -z "$major_version" ]; then
macos_version=$(sw_vers -productVersion)
major_version=$(echo "$macos_version" | cut -d '.' -f 1)
fi
export MACOSX_DEPLOYMENT_TARGET=$major_version
export CMAKE_OSX_DEPLOYMENT_TARGET=$major_version
# exit on error
set -e
# clear
clear
# build type
if [ "$build_type" != "debug" ] && [ "$build_type" != "release" ] && [ "$build_type" != "all" ]; then
echo "invalid build type: $build_type (use 'debug', 'release', or 'all')"
exit 1
fi
echo "Building Automator for $build_type"
echo "---------------------------------"
# signing
if [ "$sign_code" == "ON" ]; then
default_developerid_identity=${DEVELOPERID_IDENTITY:-}
default_mac_developer_identity=${MAC_DEVELOPER_IDENTITY:-}
default_mac_installer_identity=${MAC_INSTALLER_IDENTITY:-}
read -p "enter Developer ID certificate identity [$default_developerid_identity]: " input_developerid_identity
developerid_identity=${input_developerid_identity:-$default_developerid_identity}
if [[ ! "$developerid_identity" == *"Developer ID"* ]]; then
echo "Developer ID certificate identity must contain 'Developer ID', required for github distribution."
fi
read -p "enter Mac Developer certificate Identity [$default_mac_developer_identity]: " input_mac_developer_identity
mac_developer_identity=${input_mac_developer_identity:-$default_mac_developer_identity}
if [[ ! "$mac_developer_identity" == *"3rd Party Mac Developer Application"* ]]; then
echo "Mac Developer installer identity must contain '3rd Party Mac Developer Installer', required for appstore distribution."
fi
read -p "enter Mac Installer certificate Identity [$default_mac_installer_identity]: " input_mac_installer_identity
mac_installer_identity=${input_mac_installer_identity:-$default_mac_installer_identity}
if [[ ! "$mac_installer_identity" == *"3rd Party Mac Developer Installer"* ]]; then
echo "Mac Developer installer identity must contain '3rd Party Mac Developer Installer', required for appstore distribution."
fi
echo ""
fi
# check if cmake is in the path
if ! command -v cmake &> /dev/null; then
echo "cmake not found in the PATH, will try to set to /Applications/CMake.app/Contents/bin"
export PATH=$PATH:/Applications/CMake.app/Contents/bin
if ! command -v cmake &> /dev/null; then
echo "cmake could not be found, please make sure it's installed"
exit 1
fi
fi
# check if cmake version is compatible
if ! [[ $(cmake --version | grep -o '[0-9]\+\(\.[0-9]\+\)*' | head -n1) < "3.28.0" ]]; then
echo "cmake version is not compatible with Qt, must be before 3.28.0 for multi configuration"
exit 1;
fi
# build automator
build_automator() {
local build_type="$1"
# cmake
export PATH=$PATH:/Applications/CMake.app/Contents/bin &&
# script dir
cd "$script_dir"
# clean dir
build_dir="$script_dir/build.$build_type"
if [ -d "$build_dir" ]; then
rm -rf "$build_dir"
fi
# build dir
mkdir -p "build.$build_type"
cd "build.$build_type"
# prefix dir
if ! [ -d "$THIRDPARTY_DIR" ]; then
echo "could not find 3rdparty project in: $THIRDPARTY_DIR"
exit 1
fi
prefix="$THIRDPARTY_DIR"
# xcode build
xcode_type=$(echo "$build_type" | awk '{ print toupper(substr($0, 1, 1)) tolower(substr($0, 2)) }')
# build
if [ -n "$provisioning_profile" ] && [ -n "$provisioning_profile_path" ]; then
cmake .. -DCMAKE_MODULE_PATH="$script_dir/modules" -DCMAKE_PREFIX_PATH="$prefix" -DPROVISIONING_PROFILE="$provisioning_profile" -G Xcode
else
cmake .. -DCMAKE_MODULE_PATH="$script_dir/modules" -DCMAKE_PREFIX_PATH="$prefix" -G Xcode
fi
cmake --build . --config $xcode_type --parallel &&
if [ "$github" == "ON" ]; then
dmg_file="$script_dir/Automator_macOS${major_version}_${machine_arch}_${build_type}.dmg"
if [ -f "$dmg_file" ]; then
rm -f "$dmg_file"
fi
# deploy
$script_dir/scripts/macdeploy.sh -b "$xcode_type/Automator.app" -m "$prefix/bin/macdeployqt"
if [ -n "$developerid_identity" ]; then
if [ "$sign_code" == "ON" ]; then
codesign --force --deep --sign "$developerid_identity" --timestamp --options runtime "$xcode_type/Automator.app"
fi
else
echo "Developer ID identity must be set for github distribution, sign will be skipped."
fi
# deploydmg
$script_dir/scripts/macdmg.sh -b "$xcode_type/Automator.app" -d "$dmg_file"
if [ -n "$developerid_identity" ]; then
if [ "$sign_code" == "ON" ]; then
codesign --force --deep --sign "$developerid_identity" --timestamp --options runtime --verbose "$dmg_file"
fi
else
echo "Developer ID identity must be set for github distribution, sign will be skipped."
fi
fi
if [ "$appstore" == "ON" ]; then
pkg_file="$script_dir/Automator_macOS${major_version}_${machine_arch}_${build_type}.pkg"
if [ -f "$pkg_file" ]; then
rm -f "$pkg_file"
fi
# provisioning
if [ -n "$provisioning_profile" ] && [ -n "$provisioning_profile_path" ]; then
cp -f "$provisioning_profile_path" "$xcode_type/Automator.app/Contents/embedded.provisionprofile"
else
echo "Provisioning profile and path must be set for appstore distribution, will be skipped."
fi
# deploy
$script_dir/scripts/macdeploy.sh -b "$xcode_type/Automator.app" -m "$prefix/bin/macdeployqt"
if [ -n "$mac_developer_identity" ]; then
if [ "$sign_code" == "ON" ]; then
# entitlements
teamid=$(echo "$mac_developer_identity" | awk -F '[()]' '{print $2}')
applicationid=$(/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" "$xcode_type/Automator.app/Contents/Info.plist")
entitlements="$script_dir/resources/App.entitlements"
echo sed -e "s/\${TEAMID}/$teamid/g" -e "s/\${APPLICATIONIDENTIFIER}/$applicationid/g" "$script_dir/resources/App.entitlements.in" > "$entitlements"
sed -e "s/\${TEAMID}/$teamid/g" -e "s/\${APPLICATIONIDENTIFIER}/$applicationid/g" "$script_dir/resources/App.entitlements.in" > "$entitlements"
# sign
sign_app "$xcode_type/Automator.app" "dylibs" "$mac_developer_identity"
sign_app "$xcode_type/Automator.app" "frameworks" "$mac_developer_identity"
sign_app "$xcode_type/Automator.app" "executables" "$mac_developer_identity"
verify_app "$xcode_type/Automator.app"
codesign --force --deep --sign "$mac_developer_identity" --entitlements $entitlements "$xcode_type/Automator.app"
codesign --verify "$xcode_type/Automator.app"
fi
else
echo "Mac Developer identity must be set for appstore distribution, sign will be skipped."
fi
# productbuild
if [ "$sign_code" == "ON" ]; then
if [ -n "$mac_installer_identity" ]; then
productbuild --component "$xcode_type/Automator.app" "/Applications" --sign "${mac_installer_identity}" --product "$xcode_type/Automator.app/Contents/Info.plist" "$pkg_file"
else
echo "Mac Installer identity must be set for appstore distribution, sign will be skipped."
productbuild --component "$xcode_type/Automator.app" "/Applications" --product "$xcode_type/Automator.app/Contents/Info.plist" "$pkg_file"
fi
else
productbuild --component "$xcode_type/Automator.app" "/Applications" --product "$xcode_type/Automator.app/Contents/Info.plist" "$pkg_file"
fi
fi
}
# build types
if [ "$build_type" == "all" ]; then
build_automator "debug"
build_automator "release"
else
build_automator "$build_type"
fi