Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 103ec3e

Browse files
siddarthkayibrkhalil
authored andcommittedFeb 25, 2024
chore: improve android & iOS build step (#18900)
fixes #18888 ## Summary `make run-android` was sometimes flaky because we used to send metro to background via `nohup` and then bring it back to foreground after we read metro logs. Now we do not send metro to background. We first wait for a successful build. we then install the app on the simulator. After this is done we give command to sleep until metro server has started, Once metro server has started we open the installed app. In this workflow the command to open the installed app goes in background and metro stays in foreground. The new workflow should now be less flaky. ## Review notes `make run-clojure` `make run-android` OR `make run-ios` should just work #### Platforms - Android - iOS
1 parent 21af0b3 commit 103ec3e

File tree

4 files changed

+44
-75
lines changed

4 files changed

+44
-75
lines changed
 

‎.gitignore

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

198198
## metro server logs
199199
metro-server-logs.log
200+
201+
## debug build time logs
202+
logs/

‎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="${GIT_ROOT}/logs/adb_install.log"
6+
ADB_SHELL_MONKEY_LOG_FILE="${GIT_ROOT}/logs/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="${GIT_ROOT}/logs/xcrun_install.log"
7+
XCRUN_LAUNCH_LOG_FILE="${GIT_ROOT}/logs/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 take 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)
Please sign in to comment.