Repository navigation
Expand file tree
/
Copy pathbundle.sh
More file actions
executable file
·72 lines (70 loc) · 3.27 KB
/
Copy pathbundle.sh
File metadata and controls
executable file
·72 lines (70 loc) · 3.27 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
#!/bin/sh
# Builds build/Blablabla.app from the SwiftPM release binary and signs it.
#
# Signing identity: BLABLABLA_SIGN_IDENTITY, by default "Blablabla Dev" (a
# local self-signed certificate). A stable identity keeps the macOS
# permissions (microphone, Accessibility) across builds; an ad hoc
# signature changes every build and loses them.
# BLABLABLA_SIGN_KEYCHAIN look for the identity in this keychain
# only (the release workflow's own)
# BLABLABLA_REQUIRE_SIGNATURE=1 fail instead of falling back to ad hoc
set -eu
cd "$(dirname "$0")"
swift build -c release
app=build/Blablabla.app
rm -rf "$app"
mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources"
cp .build/release/Blablabla "$app/Contents/MacOS/"
# Local symbols and debug info halve the binary (1.5 MB to 0.7 MB); the
# release still names its own functions in a crash report.
strip -S -x "$app/Contents/MacOS/Blablabla"
cp Support/Info.plist "$app/Contents/"
identity="${BLABLABLA_SIGN_IDENTITY:-Blablabla Dev}"
keychain="${BLABLABLA_SIGN_KEYCHAIN:-}"
# Any build not signed "Blablabla Release" (Dev or ad hoc) gets its own identifier
# and name, and so its own permissions, preferences, history and log. macOS keys
# permissions by identifier: with the release's, granting Accessibility to a test
# build silently takes it away from the installed app.
if [ "$identity" != "Blablabla Release" ]; then
plutil -replace CFBundleIdentifier -string fr.levups.blablabla.swift.dev "$app/Contents/Info.plist"
plutil -replace CFBundleName -string "Blablabla Dev" "$app/Contents/Info.plist"
plutil -replace CFBundleDisplayName -string "Blablabla Dev" "$app/Contents/Info.plist"
# The commit it was built from, shown in Settings next to the version.
commit=$(git rev-parse --short HEAD 2>/dev/null || true)
if [ -n "$commit" ]; then
plutil -replace BlablablaCommit -string "$commit" "$app/Contents/Info.plist"
fi
# Its own icon too, with a "DEV" band, so it's never taken for the installed app.
iconset="$(mktemp -d)/AppIcon.iconset"
iconutil -c iconset -o "$iconset" Support/AppIcon.icns
swift scripts/dev-icon.swift "$iconset"
iconutil -c icns -o "$app/Contents/Resources/AppIcon.icns" "$iconset"
rm -rf "$(dirname "$iconset")"
else
cp Support/AppIcon.icns "$app/Contents/Resources/"
fi
# UI strings (English source, with their translations) → <language>.lproj.
# Our own compiler, since xcstringstool comes with Xcode only; CI checks they agree.
for catalog in Resources/Localizable.xcstrings Resources/InfoPlist.xcstrings; do
swift scripts/xcstrings.swift "$catalog" "$app/Contents/Resources"
done
if [ -n "$keychain" ]; then
identities=$(security find-identity -p codesigning "$keychain")
else
identities=$(security find-identity -p codesigning)
fi
if printf '%s\n' "$identities" | grep -q "\"$identity\""; then
if [ -n "$keychain" ]; then
codesign --force --keychain "$keychain" --sign "$identity" "$app"
else
codesign --force --sign "$identity" "$app"
fi
elif [ "${BLABLABLA_REQUIRE_SIGNATURE:-}" = 1 ]; then
echo "No \"$identity\" signing identity, and a signature is required" >&2
exit 1
else
echo "No \"$identity\" signing identity: ad hoc signature, permissions reset on each build" >&2
codesign --force --sign - "$app"
fi
codesign --verify --strict "$app"
echo "$app"