diff --git a/scripts/reset-simulators.sh b/scripts/reset-simulators.sh index 8b2e487fd07..4b43e5712e8 100755 --- a/scripts/reset-simulators.sh +++ b/scripts/reset-simulators.sh @@ -13,18 +13,21 @@ while pgrep -q Simulator; do pkill -9 Simulator 2>/dev/null || true done -# Run once since switching simulator versions often causes CoreSimulatorService to throw an exception. -xcrun simctl list devices >/dev/null 2>&1 || true +# Run until we get a result since switching simulator versions often causes CoreSimulatorService to throw an exception. +devices="" +until [ "$devices" != "" ]; do + devices="$(xcrun simctl list devices -j)" +done # Shut down booted simulators -xcrun simctl list devices -j | ruby -rjson -e 'puts JSON.parse($stdin.read)["devices"].flat_map { |d| d[1] }.select { |d| d["state"] == "Booted" && d["availability"] == "(available)" }.map { |d| d["udid"] }' | while read udid; do +echo "$devices" | ruby -rjson -e 'puts JSON.parse($stdin.read)["devices"].flat_map { |d| d[1] }.select { |d| d["state"] == "Booted" && d["availability"] == "(available)" }.map { |d| d["udid"] }' | while read udid; do echo "shutting down simulator with ID: $udid" xcrun simctl shutdown $udid done # Erase all available simulators echo "erasing simulators" -xcrun simctl list devices -j | ruby -rjson -e 'puts JSON.parse($stdin.read)["devices"].flat_map { |d| d[1] }.select { |d| d["availability"] == "(available)" }.map { |d| d["udid"] }' | while read udid; do +echo "$devices" | ruby -rjson -e 'puts JSON.parse($stdin.read)["devices"].flat_map { |d| d[1] }.select { |d| d["availability"] == "(available)" }.map { |d| d["udid"] }' | while read udid; do xcrun simctl erase $udid & done wait @@ -35,7 +38,7 @@ fi # Wait until the boot completes echo "waiting for simulator to boot..." -until xcrun simctl list devices -j | ruby -rjson -e 'exit JSON.parse($stdin.read)["devices"].flat_map { |d| d[1] }.any? { |d| d["state"] == "Booted" }'; do +until xcrun simctl list devices -j | ruby -rjson -e 'exit JSON.parse($stdin.read)["devices"].flat_map { |d| d[1] }.any? { |d| d["availability"] == "(available)" && d["state"] == "Booted" }'; do sleep 1 done