wipe simulators between runs

This commit is contained in:
Ari Lazier 2016-08-04 11:11:32 -07:00
parent 0074bdfe94
commit f86975f78e
2 changed files with 60 additions and 11 deletions

59
scripts/reset-simulators.sh Executable file
View File

@ -0,0 +1,59 @@
#!/bin/bash
set -o pipefail
set -e
while pgrep -q Simulator; do
# Kill all the current simulator processes as they may be from a
# different Xcode version
pkill Simulator 2>/dev/null || true
# CoreSimulatorService doesn't exit when sent SIGTERM
pkill -9 Simulator 2>/dev/null || true
done
# Shut down simulators until there's no booted ones left
# Only do one at a time because devices sometimes show up multiple times
while xcrun simctl list | grep -q Booted; do
xcrun simctl list | grep Booted | sed 's/.* (\(.*\)) (Booted)/\1/' | head -n 1 | xargs xcrun simctl shutdown
done
# Clean up all available simulators
(
previous_device=''
IFS=$'\n' # make newlines the only separator
for LINE in $(xcrun simctl list); do
if [[ $LINE =~ unavailable || $LINE =~ disconnected ]]; then
# skip unavailable simulators
continue
fi
if [[ $LINE =~ "--" ]]; then
# Reset the last seen device so we won't consider devices with the same name to be duplicates
# if they appear in different sections.
previous_device=""
continue
fi
regex='^(.*) [(]([0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12})[)]'
if [[ $LINE =~ $regex ]]; then
device="${BASH_REMATCH[1]}"
guid="${BASH_REMATCH[2]}"
# Delete the simulator if it's a duplicate of the last seen one
# Otherwise delete all contents and settings for it
if [[ $device == $previous_device ]]; then
xcrun simctl delete $guid
else
xcrun simctl erase $guid
previous_device="$device"
fi
fi
done
)
if [[ -a "${DEVELOPER_DIR}/Applications/iOS Simulator.app" ]]; then
open "${DEVELOPER_DIR}/Applications/iOS Simulator.app"
elif [[ -a "${DEVELOPER_DIR}/Applications/Simulator.app" ]]; then
open "${DEVELOPER_DIR}/Applications/Simulator.app"
fi

View File

@ -30,16 +30,6 @@ cleanup() {
rm -f "$PACKAGER_OUT" "$LOGCAT_OUT"
}
kill_ios_simulator() {
while pgrep -q Simulator; do
# Kill all the current simulator processes as they may be from a
# different Xcode version
pkill Simulator 2>/dev/null || true
# CoreSimulatorService doesn't exit when sent SIGTERM
pkill -9 Simulator 2>/dev/null || true
done
}
open_chrome() {
local dir
for dir in "$HOME/Applications" "/Applications"; do
@ -65,7 +55,7 @@ start_packager() {
}
xctest() {
kill_ios_simulator
${SRCROOT}/scripts/reset-simulators.sh
local dest="$(xcrun simctl list devices | grep -v unavailable | grep -m 1 -o '[0-9A-F\-]\{36\}')"
xcodebuild -scheme "$1" -configuration "$CONFIGURATION" -sdk iphonesimulator -destination id="$dest" build test