Branchwell

Textley / app · textley.ai / Scripts / build-app.sh

Raw 3.7 KB on 63b71f34cfe61bc6553e8463e803a45424bff4d3
1#!/bin/bash
2set -euo pipefail
3umask 022
4
5# Usage: Scripts/build-app.sh [OUTPUT_DIRECTORY] [debug|release]
6# Set TEXTLEY_RELEASE=1 and TEXTLEY_SIGN_IDENTITY to build the Developer ID app with Sparkle.
7root="$(cd "$(dirname "$0")/.." && pwd)"
8output="${1:-$root/build}"
9configuration="${2:-release}"
10app="$output/Textley.app"
11scratch="${TEXTLEY_BUILD_SCRATCH_PATH:-$output/.build}"
12keychain="${TEXTLEY_SIGN_KEYCHAIN:-$HOME/Library/Keychains/login.keychain-db}"
13
14mkdir -p "$output/tmp" "$output/module-cache"
15export TMPDIR="$output/tmp/"
16export CLANG_MODULE_CACHE_PATH="$output/module-cache"
17export SWIFTPM_MODULECACHE_OVERRIDE="$output/module-cache"
18args=(--package-path "$root" --scratch-path "$scratch" -c "$configuration")
19
20identity="${TEXTLEY_SIGN_IDENTITY:--}"
21signing_flags=()
22sparkle=''
23if [[ "${TEXTLEY_RELEASE:-0}" == 1 ]]; then
24 [[ "$identity" == "Developer ID Application: "* ]] || { echo 'Set TEXTLEY_SIGN_IDENTITY to a Developer ID Application identity.' >&2; exit 1; }
25 [[ "$configuration" == release ]] || { echo 'Distribution builds use the release configuration.' >&2; exit 1; }
26 /usr/bin/security find-identity -v -p codesigning "$keychain" | /usr/bin/grep -Fq "\"$identity\"" || {
27 echo 'The Developer ID Application identity is missing from the selected keychain.' >&2; exit 1; }
28 /usr/bin/grep -q TEXTLEY_SPARKLE_PUBLIC_KEY "$root/Scripts/Sparkle.plist" && {
29 echo 'Add the textley-direct Sparkle public key to Scripts/Sparkle.plist.' >&2; exit 1; }
30 signing_flags=(--timestamp --options runtime --keychain "$keychain")
31 sparkle="$(bash "$root/Scripts/prepare-sparkle.sh" "$output/sparkle")"
32 args+=(-Xswiftc -DTEXTLEY_SPARKLE -Xswiftc -F -Xswiftc "$sparkle"
33 -Xlinker -F -Xlinker "$sparkle" -Xlinker -rpath -Xlinker @executable_path/../Frameworks)
34fi
35
36rm -rf "$app"
37mkdir -p "$app/Contents/MacOS" "$app/Contents/Resources/TextleyClaudeMCP"
38xcrun swift build "${args[@]}"
39bin="$(xcrun swift build "${args[@]}" --show-bin-path)"
40install -m 755 "$bin/Textley" "$app/Contents/MacOS/Textley"
41install -m 644 "$root/Scripts/Info.plist" "$app/Contents/Info.plist"
42install -m 644 "$root/Resources/TextleyClaudeMCP/manifest.json" "$root/Resources/TextleyClaudeMCP/server.js" \
43 "$app/Contents/Resources/TextleyClaudeMCP"
44iconset="$output/tmp/AppIcon.iconset"
45mkdir -p "$iconset"
46for size in 16 32 128 256 512; do
47 /usr/bin/sips -z "$size" "$size" "$root/Resources/AppIcon.png" --out "$iconset/icon_${size}x${size}.png" >/dev/null
48 twice=$((size * 2))
49 /usr/bin/sips -z "$twice" "$twice" "$root/Resources/AppIcon.png" --out "$iconset/icon_${size}x${size}@2x.png" >/dev/null
50done
51/usr/bin/iconutil -c icns "$iconset" -o "$app/Contents/Resources/AppIcon.icns"
52install -m 644 "$root/Resources/AgentSkill.md" "$root/Resources/AgentSkill-LICENSE.txt" "$app/Contents/Resources/"
53
54if [[ -n "$sparkle" ]]; then
55 /usr/libexec/PlistBuddy -c "Merge '$root/Scripts/Sparkle.plist'" "$app/Contents/Info.plist"
56 install -m 644 "$sparkle/LICENSE" "$app/Contents/Resources/Sparkle-LICENSE.txt"
57 install -m 644 "$root/Packaging/macOS/background.tiff" "$app/Contents/Resources/TextleyInstallerBackground.tiff"
58 framework="$app/Contents/Frameworks/Sparkle.framework"
59 ditto "$sparkle/Sparkle.framework" "$framework"
60 for component in "$framework/Versions/Current/XPCServices/"*.xpc \
61 "$framework/Versions/Current/Autoupdate" "$framework/Versions/Current/Updater.app" "$framework"; do
62 /usr/bin/codesign --force --sign "$identity" "${signing_flags[@]}" "$component"
63 done
64fi
65find "$app" -type d -exec chmod 755 {} +
66/usr/bin/codesign --force --sign "$identity" ${signing_flags[@]+"${signing_flags[@]}"} "$app"
67/usr/bin/codesign --verify --deep --strict "$app"
68printf '%s\n' "$app"