#!/bin/sh set -eu mac=$(cd "$(dirname "$0")" && pwd) root=$(dirname "$mac") shared=$HOME/Library/Caches/byre/build build=$mac/.build app=$build/byre.app svg=$mac/icon.svg icns=$build/byre.icns identity="Developer ID Application" mkdir -p "$shared" "$build" if [ "$(security cms -D -i "$mac/byre.provisionprofile" | plutil -extract ProvisionsAllDevices raw -)" != true ]; then echo "bundle: mac/byre.provisionprofile is not a Developer ID profile" >&2 exit 1 fi lockf -k "$shared.lock" sh -ec ' rsync -rlc --delete --exclude /mac/.build --exclude /hands/.build "$1/mac" "$1/api" "$1/hands" "$2/" swift build --package-path "$2/mac" --configuration release --no-color-diagnostics swift build --package-path "$2/hands" --configuration release --no-color-diagnostics cp "$2/mac/.build/release/Byre" "$3" cp "$2/hands/.build/release/byre-hands" "$4" rm -rf "$5" ditto "$2/mac/.build/release/Sparkle.framework" "$5" ' sh "$root" "$shared" "$build/Byre" "$build/byre-hands" "$build/Sparkle.framework" go -C "$root" build -trimpath -o "$build/server/byre" ./cmd/byre if [ ! "$icns" -nt "$svg" ]; then iconset=$build/byre.iconset rm -rf "$iconset" mkdir -p "$iconset" for size in 16 32 128 256 512; do rsvg-convert --width $size --height $size --output "$iconset/icon_${size}x${size}.png" "$svg" rsvg-convert --width $((size * 2)) --height $((size * 2)) --output "$iconset/icon_${size}x${size}@2x.png" "$svg" done iconutil --convert icns --output "$icns" "$iconset" fi version=$(git -C "$root" describe --tags --always) version=${version#v} rm -rf "$app" mkdir -p "$app/Contents/MacOS" "$app/Contents/Helpers" "$app/Contents/Frameworks" "$app/Contents/Resources/fonts" cp "$build/Byre" "$app/Contents/MacOS/Byre" cp "$build/server/byre" "$app/Contents/Helpers/byre" cp "$build/byre-hands" "$app/Contents/Helpers/byre-hands" ditto "$build/Sparkle.framework" "$app/Contents/Frameworks/Sparkle.framework" cp "$mac/Info.plist" "$app/Contents/Info.plist" plutil -insert ByreCommit -string "$(git -C "$root" rev-parse HEAD)" "$app/Contents/Info.plist" plutil -insert CFBundleShortVersionString -string "$version" "$app/Contents/Info.plist" plutil -insert CFBundleVersion -string "$(git -C "$root" rev-list --count HEAD)" "$app/Contents/Info.plist" cp "$mac"/fonts/*.woff2 "$app/Contents/Resources/fonts/" cp "$icns" "$app/Contents/Resources/byre.icns" cp "$mac/byre.provisionprofile" "$app/Contents/embedded.provisionprofile" sparkle=$app/Contents/Frameworks/Sparkle.framework rm -rf "$sparkle/Versions/B/XPCServices" sign() { codesign --force --timestamp --options runtime --sign "$identity" "$@" } sign --identifier run.fc.byre.hands --entitlements "$mac/automation.entitlements" "$app/Contents/Helpers/byre-hands" sign --identifier run.fc.byre --entitlements "$mac/automation.entitlements" "$app/Contents/Helpers/byre" sign "$sparkle/Versions/B/Autoupdate" sign "$sparkle/Versions/B/Updater.app" sign "$sparkle" sign --entitlements "$mac/byre.entitlements" "$app" echo "$app"