Scripts/run-demo.sh (6518B)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16set -euo pipefail
17
18SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
19REPO_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"
20source "${SCRIPT_DIR}/select-simulator.sh"
21
22
23
24DEVICE_KIND="iphone"
25DELETE=false
26MAJOR=27
27SHOW_V4_NOTICE=false
28for arg in "$@"; do
29 case "$arg" in
30 --ipad) DEVICE_KIND="ipad" ;;
31 --iphone) DEVICE_KIND="iphone" ;;
32 --delete) DELETE=true ;;
33 --v4-notice) SHOW_V4_NOTICE=true ;;
34 [0-9]*) MAJOR="$arg" ;;
35 *) echo "Unknown argument: $arg" >&2; exit 1 ;;
36 esac
37done
38
39if [ "$DEVICE_KIND" = "ipad" ]; then
40 DEMO_NAME="Crossmate Demo iPad"
41else
42 DEMO_NAME="Crossmate Demo"
43fi
44BUNDLE_ID="net.inqk.crossmate"
45
46
47
48DERIVED_DATA="/tmp/crossmate-demo-${DEVICE_KIND}-derived"
49
50
51
52UDID=$(xcrun simctl list devices \
53 | grep -F "${DEMO_NAME} (" \
54 | head -1 \
55 | sed -E 's/.*\(([0-9A-Fa-f-]{36})\).*/\1/' || true)
56
57
58if [ "$DELETE" = true ]; then
59 if [ -n "$UDID" ]; then
60 xcrun simctl shutdown "$UDID" 2>/dev/null || true
61 xcrun simctl delete "$UDID"
62 echo "Deleted '${DEMO_NAME}' (${UDID})."
63 else
64 echo "No '${DEMO_NAME}' simulator to delete."
65 fi
66 exit 0
67fi
68
69if [ -n "$UDID" ]; then
70 echo "Reusing '${DEMO_NAME}' (${UDID})"
71else
72
73
74
75
76 select_simulator "$MAJOR"
77 if [ "$DEVICE_KIND" = "ipad" ]; then
78
79
80
81
82 DEVICE_TYPE_LINE=$(xcrun simctl list devicetypes \
83 | grep -F "iPad mini" \
84 | sed -E 's/^iPad mini[^0-9]*([0-9]+).*/\1 &/' \
85 | sort -rn -k1,1 \
86 | head -1 \
87 | cut -f2- || true)
88 else
89 DEVICE_TYPE_LINE=$(xcrun simctl list devicetypes \
90 | grep -E "^${DEVICE} \(" \
91 | head -1 || true)
92 fi
93
94
95
96 DEVICE=$(sed -E 's/ \(com\.apple[^)]*\)$//' <<<"$DEVICE_TYPE_LINE")
97 DEVICE_TYPE_ID=$(sed -E 's/.*\((com\.apple[^)]*)\)$/\1/' <<<"$DEVICE_TYPE_LINE")
98 RUNTIME_ID=$(xcrun simctl list runtimes available \
99 | grep "iOS ${RUNTIME} (" \
100 | head -1 \
101 | sed -E 's/.* - (com\.apple[^ ]*).*/\1/' || true)
102 if [ -z "$DEVICE_TYPE_ID" ] || [ -z "$RUNTIME_ID" ]; then
103 echo "Couldn't resolve a device type / runtime to create '${DEMO_NAME}'." >&2
104 exit 1
105 fi
106 echo "Creating '${DEMO_NAME}' (${DEVICE}, iOS ${RUNTIME})"
107 UDID=$(xcrun simctl create "${DEMO_NAME}" "${DEVICE_TYPE_ID}" "${RUNTIME_ID}")
108fi
109
110
111open -a Simulator
112xcrun simctl boot "$UDID" 2>/dev/null || true
113xcrun simctl bootstatus "$UDID" -b
114
115build_app() {
116 xcodebuild build \
117 -scheme "Crossmate" \
118 -project "${REPO_DIR}/Crossmate.xcodeproj" \
119 -destination "id=${UDID}" \
120 -derivedDataPath "$DERIVED_DATA" \
121 2>&1
122}
123
124build_app
125
126APP_PATH="${DERIVED_DATA}/Build/Products/Debug-iphonesimulator/Crossmate.app"
127if [ ! -d "$APP_PATH" ]; then
128 echo "Built app not found at ${APP_PATH}" >&2
129 exit 1
130fi
131
132
133
134
135
136
137PUZZLE_MANIFEST="${APP_PATH}/Puzzles/cm-starter/manifest.json"
138if [ ! -f "$PUZZLE_MANIFEST" ]; then
139 echo "Puzzle resources are missing from the cached build; rebuilding cleanly."
140 xcodebuild clean \
141 -scheme "Crossmate" \
142 -project "${REPO_DIR}/Crossmate.xcodeproj" \
143 -destination "id=${UDID}" \
144 -derivedDataPath "$DERIVED_DATA" \
145 2>&1
146 build_app
147fi
148if [ ! -f "$PUZZLE_MANIFEST" ]; then
149 echo "Puzzle resources are missing from ${APP_PATH}; refusing to launch an empty demo." >&2
150 exit 1
151fi
152
153xcrun simctl install "$UDID" "$APP_PATH"
154
155
156V4_NOTICE_FLAG=""
157if [ "$SHOW_V4_NOTICE" = true ]; then V4_NOTICE_FLAG="--crossmate-show-v4-notice"; fi
158xcrun simctl launch --terminate-running-process "$UDID" "$BUNDLE_ID" \
159 --crossmate-seed-demo $V4_NOTICE_FLAG
160
161
162open -a Simulator
163
164echo ""
165echo "Launched ${BUNDLE_ID} with --crossmate-seed-demo on '${DEMO_NAME}' (${UDID})."