Skip to content

Commit

Permalink
further fixes to reset-simulators.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsim committed Sep 14, 2016
1 parent c25cf8c commit 3da08b7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions scripts/reset-simulators.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 3da08b7

Please sign in to comment.