Skip to content

Commit a60508b

Browse files
committed
chore: improve android & iOS build step
1 parent 8f85e3c commit a60508b

File tree

4 files changed

+49
-75
lines changed

4 files changed

+49
-75
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,11 @@ lefthook.yml
197197

198198
## metro server logs
199199
metro-server-logs.log
200+
201+
## adb logs
202+
adb_shell_monkey.log
203+
adb_install.log
204+
205+
## xcrun logs
206+
xcrun_install.log
207+
xcrun_launch.log

scripts/run-android.sh

+14-39
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,9 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
3-
set -m # needed to access jobs
43

54
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-
}
5+
ADB_INSTALL_LOG_FILE=adb_install.log
6+
ADB_SHELL_MONKEY_LOG_FILE=adb_shell_monkey.log
357

368
# Generate android debug build.
379
export ANDROID_ABI_INCLUDE=$("${GIT_ROOT}/scripts/adb_devices_abis.sh")
@@ -40,14 +12,17 @@ export BUILD_TYPE=debug
4012
"${GIT_ROOT}/scripts/build-android.sh"
4113

4214
# Install the APK on running emulator or android device.
43-
adb install ./result/app-debug.apk
44-
45-
trap cleanupMetro EXIT ERR INT QUIT
46-
runMetro &
47-
waitForMetro
15+
installAndLaunchApp() {
16+
adb install ./result/app-debug.apk > "${ADB_INSTALL_LOG_FILE}" 2>&1
17+
"${GIT_ROOT}/scripts/wait-for-metro-port.sh" 2>&1
18+
adb shell monkey -p im.status.ethereum.debug 1 > "${ADB_SHELL_MONKEY_LOG_FILE}" 2>&1
19+
}
4820

49-
# Start the installed app.
50-
adb shell monkey -p im.status.ethereum.debug 1
21+
showAdbLogs() {
22+
cat "${ADB_INSTALL_LOG_FILE}" >&2;
23+
cat "${ADB_SHELL_MONKEY_LOG_FILE}" >&2;
24+
}
5125

52-
# bring metro job to foreground
53-
fg 'runMetro'
26+
trap showAdbLogs EXIT ERR INT QUIT
27+
installAndLaunchApp &
28+
exec "${GIT_ROOT}/scripts/run-metro.sh" 2>&1

scripts/run-ios.sh

+13-36
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,20 @@ set -euo pipefail
33
set -m # needed to access jobs
44

55
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)
6+
XCRUN_INSTALL_LOG_FILE=xcrun_install.log
7+
XCRUN_LAUNCH_LOG_FILE=xcrun_launch.log
68

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-
}
9+
# Install on the simulator
10+
installAndLaunchApp() {
11+
xcrun simctl install "$UUID" "$APP_PATH" > "${XCRUN_INSTALL_LOG_FILE}" 2>&1
12+
"${GIT_ROOT}/scripts/wait-for-metro-port.sh" 2>&1
13+
xcrun simctl launch "$UUID" im.status.ethereum.debug > "${XCRUN_LAUNCH_LOG_FILE}" 2>&1
1214

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
1715
}
1816

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.
17+
showXcrunLogs() {
18+
cat "${XCRUN_INSTALL_LOG_FILE}" >&2;
19+
cat "${XCRUN_LAUNCH_LOG_FILE}" >&2;
3420
}
3521

3622
# Check if the first argument is provided
@@ -65,15 +51,6 @@ xcodebuild -workspace "ios/StatusIm.xcworkspace" -configuration Debug -scheme St
6551

6652
APP_PATH="${BUILD_DIR}/Build/Products/Debug-iphonesimulator/StatusIm.app"
6753

68-
# Install on the simulator
69-
xcrun simctl install "$UUID" "$APP_PATH"
70-
71-
trap cleanupMetro EXIT ERR INT QUIT
72-
runMetro &
73-
waitForMetro
74-
75-
# launch the app when metro is ready
76-
xcrun simctl launch "$UUID" im.status.ethereum.debug
77-
78-
# bring metro job to foreground
79-
fg 'runMetro'
54+
trap showXcrunLogs EXIT ERR INT QUIT
55+
installAndLaunchApp &
56+
exec "${GIT_ROOT}/scripts/run-metro.sh" 2>&1

scripts/wait-for-metro-port.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
TIMEOUT=10 # Metro should not this long to start
5+
6+
while [ "${TIMEOUT}" -gt 0 ]; do
7+
if ! lsof -i:8081 &> /dev/null; then
8+
echo "."
9+
sleep 1
10+
((TIMEOUT--))
11+
else
12+
break
13+
fi
14+
done

0 commit comments

Comments
 (0)