2024-02-14 14:28:45 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
set -m # needed to access jobs
|
|
|
|
|
|
|
|
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
|
2024-02-19 15:41:36 +00:00
|
|
|
XCRUN_INSTALL_LOG_FILE="${GIT_ROOT}/logs/xcrun_install.log"
|
|
|
|
XCRUN_LAUNCH_LOG_FILE="${GIT_ROOT}/logs/xcrun_launch.log"
|
2024-02-20 05:24:09 +00:00
|
|
|
XCRUN_SIMULATOR_JSON_FILE="${GIT_ROOT}/logs/ios_simulators_list.log"
|
2024-02-14 14:28:45 +00:00
|
|
|
|
2024-02-19 15:41:36 +00:00
|
|
|
# Install on the simulator
|
|
|
|
installAndLaunchApp() {
|
2024-02-20 01:46:54 +00:00
|
|
|
xcrun simctl install "$UDID" "$APP_PATH" > "${XCRUN_INSTALL_LOG_FILE}" 2>&1
|
2024-02-19 15:41:36 +00:00
|
|
|
"${GIT_ROOT}/scripts/wait-for-metro-port.sh" 2>&1
|
2024-02-20 01:46:54 +00:00
|
|
|
xcrun simctl launch "$UDID" im.status.ethereum.debug > "${XCRUN_LAUNCH_LOG_FILE}" 2>&1
|
2024-02-14 14:28:45 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-02-19 15:41:36 +00:00
|
|
|
showXcrunLogs() {
|
|
|
|
cat "${XCRUN_INSTALL_LOG_FILE}" >&2;
|
|
|
|
cat "${XCRUN_LAUNCH_LOG_FILE}" >&2;
|
2024-02-14 14:28:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Check if the first argument is provided
|
|
|
|
if [ -z "${1-}" ]; then
|
|
|
|
echo "Error: No simulator name provided." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-02-20 01:46:54 +00:00
|
|
|
# fetch available iOS Simulators
|
2024-02-20 05:24:09 +00:00
|
|
|
xcrun simctl list devices -j > "${XCRUN_SIMULATOR_JSON_FILE}"
|
2024-02-20 01:46:54 +00:00
|
|
|
|
2024-02-14 14:28:45 +00:00
|
|
|
SIMULATOR=${1}
|
|
|
|
|
2024-02-20 01:46:54 +00:00
|
|
|
# get the first available UDID for Simulators that match the name
|
|
|
|
read -r UDID SIMULATOR_STATE IS_AVAILABLE < <(jq --raw-output --arg simulator "${SIMULATOR}" '
|
|
|
|
[ .devices[] | .[] | select(.name == $simulator) ] |
|
|
|
|
map(select(.isAvailable)) + map(select(.isAvailable | not)) |
|
|
|
|
first |
|
|
|
|
"\(.udid) \(.state) \(.isAvailable)"
|
2024-02-20 05:24:09 +00:00
|
|
|
' "${XCRUN_SIMULATOR_JSON_FILE}")
|
2024-02-14 14:28:45 +00:00
|
|
|
|
2024-02-20 01:46:54 +00:00
|
|
|
if [ "${IS_AVAILABLE}" == false ] || [ "${UDID}" == null ]; then
|
|
|
|
echo "Error: Simulator ${SIMULATOR} is not available, Please find and install them."
|
|
|
|
echo "For help please refer"
|
|
|
|
echo "https://developer.apple.com/documentation/safari-developer-tools/adding-additional-simulators#Add-and-remove-Simulators " >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-02-14 14:28:45 +00:00
|
|
|
|
|
|
|
# sometimes a simulator is already running, shut it down to avoid errors
|
2024-02-20 01:46:54 +00:00
|
|
|
if [ "${SIMULATOR_STATE}" != "Shutdown" ]; then
|
|
|
|
xcrun simctl shutdown "${UDID}"
|
2024-02-14 14:28:45 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# boot up iOS for simulator
|
2024-02-20 01:46:54 +00:00
|
|
|
xcrun simctl boot "${UDID}"
|
2024-02-14 14:28:45 +00:00
|
|
|
|
|
|
|
# start the simulator
|
2024-02-20 01:46:54 +00:00
|
|
|
open -a Simulator --args -CurrentDeviceUDID "${UDID}"
|
2024-02-14 14:28:45 +00:00
|
|
|
|
2024-02-15 12:25:06 +00:00
|
|
|
BUILD_DIR="${GIT_ROOT}/build"
|
|
|
|
|
2024-02-14 14:28:45 +00:00
|
|
|
#iOS build of debug scheme
|
2024-02-20 01:46:54 +00:00
|
|
|
xcodebuild -workspace "ios/StatusIm.xcworkspace" -configuration Debug -scheme StatusIm -destination id="${UDID}" -derivedDataPath "${BUILD_DIR}" -verbose | xcbeautify
|
2024-02-15 12:25:06 +00:00
|
|
|
|
|
|
|
APP_PATH="${BUILD_DIR}/Build/Products/Debug-iphonesimulator/StatusIm.app"
|
|
|
|
|
2024-02-19 15:41:36 +00:00
|
|
|
trap showXcrunLogs EXIT ERR INT QUIT
|
|
|
|
installAndLaunchApp &
|
|
|
|
exec "${GIT_ROOT}/scripts/run-metro.sh" 2>&1
|