|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | +set -m # needed to access jobs |
| 4 | + |
| 5 | +GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel) |
| 6 | + |
| 7 | +# We run Metro in background while calling adb. |
| 8 | +cleanupMetro() { |
| 9 | + pkill -f run-metro.sh |
| 10 | + rm -f metro-server-logs.log |
| 11 | +} |
| 12 | + |
| 13 | +# Using function gives a neater jobspec name. |
| 14 | +runMetro() { |
| 15 | + nohup "${GIT_ROOT}/scripts/run-metro.sh" 2>&1 \ |
| 16 | + | tee metro-server-logs.log |
| 17 | +} |
| 18 | + |
| 19 | +waitForMetro() { |
| 20 | + set +e # Allow grep command to fail in the loop. |
| 21 | + TIMEOUT=5 |
| 22 | + echo "Waiting for Metro server..." >&2 |
| 23 | + while ! grep -q "Welcome to Metro" metro-server-logs.log; do |
| 24 | + echo -n "." >&2 |
| 25 | + sleep 1 |
| 26 | + if ((TIMEOUT == 0)); then |
| 27 | + echo -e "\nMetro server timed out, exiting" >&2 |
| 28 | + set -e # Restore errexit for rest of script. |
| 29 | + return 1 |
| 30 | + fi |
| 31 | + ((TIMEOUT--)) |
| 32 | + done |
| 33 | + set -e # Restore errexit for rest of script. |
| 34 | +} |
| 35 | + |
| 36 | +# Check if the first argument is provided |
| 37 | +if [ -z "${1-}" ]; then |
| 38 | + echo "Error: No simulator name provided." >&2 |
| 39 | + exit 1 |
| 40 | +fi |
| 41 | + |
| 42 | +SIMULATOR=${1} |
| 43 | + |
| 44 | +# get our desired UUID |
| 45 | +UUID=$(xcrun simctl list devices | grep -E "$SIMULATOR \(" | head -n 1 | awk -F '[()]' '{print $2}') |
| 46 | + |
| 47 | +# get simulator status |
| 48 | +SIMULATOR_STATE=$(xcrun simctl list devices | grep -E "$SIMULATOR \(" | head -n 1 | awk '{print $NF}') |
| 49 | + |
| 50 | +# sometimes a simulator is already running, shut it down to avoid errors |
| 51 | +if [ "$SIMULATOR_STATE" != "(Shutdown)" ]; then |
| 52 | + xcrun simctl shutdown "$UUID" |
| 53 | +fi |
| 54 | + |
| 55 | +# boot up iOS for simulator |
| 56 | +xcrun simctl boot "$UUID" |
| 57 | + |
| 58 | +# start the simulator |
| 59 | +open -a Simulator --args -CurrentDeviceUDID "$UUID" |
| 60 | + |
| 61 | +#iOS build of debug scheme |
| 62 | +xcodebuild -workspace "ios/StatusIm.xcworkspace" -configuration Debug -scheme StatusIm -destination id="$UUID" | xcbeautify |
| 63 | + |
| 64 | +trap cleanupMetro EXIT ERR INT QUIT |
| 65 | +runMetro & |
| 66 | +waitForMetro |
| 67 | + |
| 68 | +# launch the app when metro is ready |
| 69 | +xcrun simctl launch "$UUID" im.status.ethereum.debug |
| 70 | + |
| 71 | +# bring metro job to foreground |
| 72 | +fg 'runMetro' |
0 commit comments