From e2616b60b46a4b158bb710bf0e400c924789aa18 Mon Sep 17 00:00:00 2001 From: Talon Date: Fri, 19 Jun 2026 02:33:14 +0200 Subject: [PATCH] fix(scripts): run-ios-simulator.sh exits silently when no Booted sim found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When no simulator is booted, grep -oE finds no UUID and exits 1. With set -euo pipefail, that non-zero exit propagates through the command substitution and kills the script at the UDID= assignment before it can fall through to the boot-one branch. Fix: add || true to both find_sim and sim_name pipelines so they always return 0 regardless of whether a match was found. Also replace sleep 2 with xcrun simctl bootstatus -b, which blocks until the simulator is fully booted — more reliable than a fixed delay and faster when the simulator starts quickly. Update docs/building.md §9 to show the bootstatus command. --- docs/building.md | 1 + scripts/run-ios-simulator.sh | 17 ++++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/building.md b/docs/building.md index 928342c..3bce9a6 100644 --- a/docs/building.md +++ b/docs/building.md @@ -445,6 +445,7 @@ Under the hood the script uses `xcrun simctl` commands: # Boot a simulator (if not already running): xcrun simctl boot open -a Simulator +xcrun simctl bootstatus -b # wait until boot is complete before installing # Install the built .app: xcrun simctl install clients/apple/iOS/build/Debug-iphonesimulator/VoiceCatiOS.app diff --git a/scripts/run-ios-simulator.sh b/scripts/run-ios-simulator.sh index bdfea2e..248af86 100755 --- a/scripts/run-ios-simulator.sh +++ b/scripts/run-ios-simulator.sh @@ -67,21 +67,23 @@ vc_log "app: $APP" find_sim() { # Each line from simctl looks like: # " iPhone 16 (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX) (Shutdown)" + # The || true at the end prevents set -e from killing the script when no + # matching device exists (grep -oE exits 1 on no match). local filter="${1:-}" state="${2:-}" local pattern="iPhone" [[ -n "$filter" ]] && pattern="$filter" xcrun simctl list devices available 2>/dev/null \ - | grep -E "[[:space:]]$pattern" \ + | grep -E "$pattern" \ | { [[ -n "$state" ]] && grep "$state" || cat; } \ | head -1 \ | grep -oE '[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}' \ - | head -1 + | head -1 || true } sim_name() { xcrun simctl list devices available 2>/dev/null \ | grep "$1" | head -1 \ - | sed 's/[[:space:]]*('"$1"').*//' | sed 's/^[[:space:]]*//' + | sed 's/[[:space:]]*('"$1"').*//' | sed 's/^[[:space:]]*//' || true } if [[ -n "$DEVICE_UDID" ]]; then @@ -100,16 +102,17 @@ else vc_step "booting simulator: $NAME ($UDID)" xcrun simctl boot "$UDID" open -a Simulator - # Give Simulator.app a moment to display the device. - sleep 2 + # Wait for the simulator to finish booting before installing. + vc_log "waiting for simulator to boot…" + xcrun simctl bootstatus "$UDID" -b fi fi NAME="$(sim_name "$UDID")" vc_log "simulator: $NAME ($UDID)" -# If the simulator exists but Simulator.app isn't open, open it. -open -a Simulator &>/dev/null || true +# Bring Simulator.app to the foreground (no-op if already open). +open -a Simulator # ── Install ─────────────────────────────────────────────────────────────────── vc_step "installing VoiceCatiOS"