Branchwell

Jotley / app · jotley.ai / scripts / build-mac-local.sh

1#!/bin/zsh
2# Permission testing needs a certificate-backed identity that survives rebuilds.
3# Ad-hoc/unsigned compile checks can still use the documented xcodebuild command.
4set -euo pipefail
5if (( $# > 1 )) || [[ -n "${1:-}" && "$1" != --check-signing ]]; then
6 print -u2 'Usage: scripts/build-mac-local.sh [--check-signing]'
7 exit 1
8fi
9task_repo_root="$(cd "$(dirname "$0")/.." && pwd)"
10task_identity="${JOTLEY_MAC_SIGNING_IDENTITY:?Set JOTLEY_MAC_SIGNING_IDENTITY to an installed Apple signing certificate name or SHA-1.}"
11task_team="${JOTLEY_MAC_SIGNING_TEAM:?Set JOTLEY_MAC_SIGNING_TEAM to the certificate's Apple team ID.}"
12task_configuration="${JOTLEY_MAC_CONFIGURATION:-Release}"
13task_derived_data="${JOTLEY_MAC_DERIVED_DATA:-/Volumes/Expand/Codex Media/jotley-local-signed-build}"
14task_keychain="$HOME/Library/Keychains/login.keychain-db"
15if [[ "$task_identity" == '-' || "$task_configuration" != (Debug|Release) ]]; then
16 print -u2 'Use an Apple certificate and Debug or Release; ad-hoc signing cannot preserve privacy grants across changed builds.'
17 exit 1
18fi
19task_identity="$(python3 "$task_repo_root/scripts/signing_identity.py" "$task_identity")"
20if [[ "${1:-}" == --check-signing ]]; then
21 print "Signing preflight passed using login keychain: $task_identity"
22 exit 0
23fi
24if [[ ! -d /Volumes/Expand ]]; then
25 print -u2 'Expand is not mounted. Mount it before building; generated files must stay on Expand.'
26 exit 1
27fi
28export TMPDIR="/Volumes/Expand/Scratch/codex-media-jotley-local-signed-build-tmp"
29mkdir -p "$TMPDIR"
30xcodebuild -project "$task_repo_root/Jotley.xcodeproj" -scheme Jotley \
31 -configuration "$task_configuration" -destination 'platform=macOS' \
32 -derivedDataPath "$task_derived_data" CODE_SIGN_STYLE=Manual \
33 CODE_SIGNING_ALLOWED=YES CODE_SIGN_IDENTITY="$task_identity" \
34 OTHER_CODE_SIGN_FLAGS="--keychain \"$task_keychain\"" \
35 DEVELOPMENT_TEAM="$task_team" build
36task_app="$task_derived_data/Build/Products/$task_configuration/Jotley.app"
37codesign --verify --strict "$task_app"
38task_signature="$(codesign -dv --verbose=4 "$task_app" 2>&1)"
39if [[ "$task_signature" != *"TeamIdentifier=$task_team"* || "$task_signature" == *'Signature=adhoc'* ]]; then
40 print -u2 'The app does not have the requested stable Apple signing identity. Do not use it for permission testing.'
41 exit 1
42fi
43print "Signed local app: $task_app"
44codesign -dr - "$task_app"