@@ -1271,10 +1271,53 @@ index c3e261ecd9e..26ef7a95de4 100644
12711271 <array>
12721272 <string>iPhoneOS</string>
12731273diff --git a/iOS/testbed/__main__.py b/iOS/testbed/__main__.py
1274- index b4499f5ac17..08fbe90a1c6 100644
1274+ index b4499f5ac17..d12a5ab065b 100644
12751275--- a/iOS/testbed/__main__.py
12761276+++ b/iOS/testbed/__main__.py
1277- @@ -230,33 +230,69 @@
1277+ @@ -82,19 +82,29 @@
1278+
1279+ # Return a list of UDIDs associated with booted simulators
1280+ async def list_devices():
1281+ - # List the testing simulators, in JSON format
1282+ - raw_json = await async_check_output(
1283+ - "xcrun", "simctl", "--set", "testing", "list", "-j"
1284+ - )
1285+ - json_data = json.loads(raw_json)
1286+ -
1287+ - # Filter out the booted iOS simulators
1288+ - return [
1289+ - simulator["udid"]
1290+ - for runtime, simulators in json_data["devices"].items()
1291+ - for simulator in simulators
1292+ - if runtime.split(".")[-1].startswith("iOS") and simulator["state"] == "Booted"
1293+ - ]
1294+ + try:
1295+ + # List the testing simulators, in JSON format
1296+ + raw_json = await async_check_output(
1297+ + "xcrun", "simctl", "--set", "testing", "list", "-j"
1298+ + )
1299+ + json_data = json.loads(raw_json)
1300+ +
1301+ + # Filter out the booted iOS simulators
1302+ + return [
1303+ + simulator["udid"]
1304+ + for runtime, simulators in json_data["devices"].items()
1305+ + for simulator in simulators
1306+ + if runtime.split(".")[-1].startswith("iOS") and simulator["state"] == "Booted"
1307+ + ]
1308+ + except subprocess.CalledProcessError as e:
1309+ + # If there's no ~/Library/Developer/XCTestDevices folder (which is the
1310+ + # case on fresh installs, and in some CI environments), `simctl list`
1311+ + # returns error code 1, rather than an empty list. Handle that case,
1312+ + # but raise all other errors.
1313+ + if e.returncode == 1:
1314+ + return []
1315+ + else:
1316+ + raise
1317+
1318+
1319+ async def find_device(initial_devices):
1320+ @@ -230,33 +240,69 @@
12781321 shutil.copytree(source, target, symlinks=True)
12791322 print(" done")
12801323
@@ -1351,7 +1394,7 @@ index b4499f5ac17..08fbe90a1c6 100644
13511394
13521395 for app_src in apps:
13531396 print(f" Installing app {app_src.name!r}...", end="", flush=True)
1354- @@ -372,8 +408 ,8 @@
1397+ @@ -372,8 +418 ,8 @@
13551398
13561399 if context.subcommand == "clone":
13571400 clone_testbed(
0 commit comments