#!/bin/zsh set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$ROOT" APP_NAME=OrionToolbar DERIVED="$ROOT/.build" CONFIGURATION="${CONFIGURATION:-Debug}" [[ "$CONFIGURATION" == Debug || "$CONFIGURATION" == Release ]] || { echo 'CONFIGURATION must be Debug or Release' >&2; exit 2; } mkdir -p "$ROOT/.build/build-logs" LOG="$ROOT/build-logs/build-${CONFIGURATION}-$(date +%Y%m%d-%H%M%S).log" echo "Building $APP_NAME ($CONFIGURATION)" set -o pipefail xcodebuild -project "$ROOT/OrionToolbar.xcodeproj" -scheme "$APP_NAME" -configuration "$CONFIGURATION" -derivedDataPath "$DERIVED" CODE_SIGNING_ALLOWED=NO build 2>&1 | tee "$LOG" APP="$DERIVED/Build/Products/$CONFIGURATION/$APP_NAME.app" [[ -d "$APP" ]] || { echo "Missing application: $APP" >&2; exit 1; } plutil -lint "$APP/Contents/Info.plist" EXE=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleExecutable' "$APP/Contents/Info.plist") [[ -x "$APP/Contents/MacOS/$EXE" ]] || { echo 'Application executable missing' >&2; exit 1; } echo "Build complete: $APP" echo "Log: $LOG" if [[ "${1:-}" == '--launch' ]]; then pkill -x "$APP_NAME" 2>/dev/null || true open "$APP" fi