Skip to content

Commit e5dee3c

Browse files
committed
Fix simulator discovery and scheme selection
1 parent ab1582c commit e5dee3c

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

scripts/run-ios-ui-tests.sh

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,25 @@ set -euo pipefail
55
ri_log() { echo "[run-ios-ui-tests] $1"; }
66

77
if [ $# -lt 1 ]; then
8-
ri_log "Usage: $0 <workspace_path> [scheme]" >&2
8+
ri_log "Usage: $0 <workspace_path> [app_bundle] [scheme]" >&2
99
exit 2
1010
fi
1111

1212
WORKSPACE_PATH="$1"
13-
REQUESTED_SCHEME="${2:-}"
13+
APP_BUNDLE_PATH="${2:-}"
14+
REQUESTED_SCHEME="${3:-}"
15+
16+
# Backwards compatibility: if the optional app bundle argument is omitted but the
17+
# second parameter was historically used for the scheme, treat it as such when it
18+
# is not a directory path.
19+
if [ -n "$APP_BUNDLE_PATH" ] && [ ! -d "$APP_BUNDLE_PATH" ] && [ -z "$REQUESTED_SCHEME" ]; then
20+
REQUESTED_SCHEME="$APP_BUNDLE_PATH"
21+
APP_BUNDLE_PATH=""
22+
fi
23+
24+
if [ -n "$APP_BUNDLE_PATH" ]; then
25+
ri_log "Ignoring deprecated app bundle argument '$APP_BUNDLE_PATH'"
26+
fi
1427

1528
if [ ! -d "$WORKSPACE_PATH" ]; then
1629
ri_log "Workspace not found at $WORKSPACE_PATH" >&2
@@ -68,26 +81,35 @@ rm -rf "$DERIVED_DATA_DIR"
6881

6982
find_sim_udid() {
7083
local desired="${1:-iPhone 16}" json
71-
if ! json="$(xcrun simctl list devices --json)"; then
84+
if ! json="$(xcrun simctl list devices --json 2>/dev/null)"; then
7285
return 1
7386
fi
74-
python3 - "$desired" <<'PY2'
75-
import json, sys
87+
SIMCTL_JSON="$json" python3 - "$desired" <<'PY2'
88+
import json, os, sys
89+
7690
7791
def normalize(name: str) -> str:
7892
return name.strip().lower()
7993
94+
8095
target = normalize(sys.argv[1])
81-
data = json.load(sys.stdin)
96+
try:
97+
data = json.loads(os.environ.get("SIMCTL_JSON", "{}"))
98+
except json.JSONDecodeError:
99+
sys.exit(1)
100+
82101
for runtime, devices in (data.get("devices") or {}).items():
83102
if "iOS" not in runtime:
84103
continue
85104
for device in devices or []:
86105
if not device.get("isAvailable"):
87106
continue
88107
if normalize(device.get("name", "")) == target:
89-
print(device.get("udid", ""))
108+
udid = device.get("udid", "")
109+
if udid:
110+
print(udid)
90111
sys.exit(0)
112+
91113
print("")
92114
PY2
93115
}

0 commit comments

Comments
 (0)