@@ -5,12 +5,25 @@ set -euo pipefail
55ri_log () { echo " [run-ios-ui-tests] $1 " ; }
66
77if [ $# -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
1010fi
1111
1212WORKSPACE_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
1528if [ ! -d " $WORKSPACE_PATH " ]; then
1629 ri_log " Workspace not found at $WORKSPACE_PATH " >&2
@@ -68,26 +81,35 @@ rm -rf "$DERIVED_DATA_DIR"
6881
6982find_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
7791def normalize(name: str) -> str:
7892 return name.strip().lower()
7993
94+
8095target = 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+
82101for 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+
91113print("")
92114PY2
93115}
0 commit comments