diff --git a/AGENTS.md b/AGENTS.md index e7c8d51..3a4f389 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,6 +12,7 @@ Commands: ```bash open Museion.xcodeproj # develop in Xcode +./scripts/build-and-run.sh # build + launch from CLI (⌘R equivalent) xcodebuild -project Museion.xcodeproj -scheme Museion -destination 'platform=macOS' build # build xcodebuild -project Museion.xcodeproj -scheme Museion -destination 'platform=macOS' test # test (unit + UI) swiftformat . && swiftlint . # lint (run --fix first if dirty) diff --git a/scripts/build-and-run.sh b/scripts/build-and-run.sh new file mode 100755 index 0000000..5e14ccf --- /dev/null +++ b/scripts/build-and-run.sh @@ -0,0 +1,41 @@ +#!/usr/bin/env bash +# Xcode-style "Build and Run" (⌘R): build the app and launch it in place from +# DerivedData, replacing any running instance. +set -euo pipefail + +PROJECT="Museion.xcodeproj" +SCHEME="Museion" +CONFIGURATION="${1:-Debug}" +APP_NAME="Museion.app" + +cd "$(dirname "$0")/.." # script lives in scripts/; repo root is the parent + +echo "Building $CONFIGURATION..." +log=$(mktemp -t museion-run) +trap 'rm -f "$log"' EXIT + +if ! xcodebuild -project "$PROJECT" -scheme "$SCHEME" \ + -configuration "$CONFIGURATION" -destination 'platform=macOS' \ + -quiet build >"$log" 2>&1; then + echo "Build failed:" >&2 + cat "$log" >&2 + exit 1 +fi + +PRODUCTS_DIR=$(xcodebuild -project "$PROJECT" -scheme "$SCHEME" \ + -configuration "$CONFIGURATION" -showBuildSettings 2>/dev/null \ + | awk -F'= ' '/BUILT_PRODUCTS_DIR = / {print $2; exit}') +APP="$PRODUCTS_DIR/$APP_NAME" + +if [[ ! -d "$APP" ]]; then + echo "Build did not produce $APP" >&2 + exit 1 +fi + +# Kill only the instance running from this exact DerivedData bundle; +# never match by name alone — an installed Museion.app shares it. +pkill -f "$APP/Contents/MacOS/" 2>/dev/null || true +# Wait briefly for it to exit, else `open` may just re-activate the dying process. +for _ in {1..20}; do pgrep -f "$APP/Contents/MacOS/" >/dev/null || break; sleep 0.1; done +echo "Launching: $APP" +open "$APP"