|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Verifies the behavior of BackStackEntryMapper.SerialName in R8-minified builds on a booted |
| 3 | +# emulator or device. See |
| 4 | +# sentry-android-integration-tests/nav3-backstack-entry-mapper-r8-check/README.md. |
| 5 | +# |
| 6 | +# The app is built against kotlinxSerialization-floor in gradle/dependency-matrix.versions.toml, plus |
| 7 | +# each version in NAV3_EXTRA_KOTLINX_VERSIONS, in R8 full mode, and against the floor in R8 compat |
| 8 | +# mode too. |
| 9 | +# |
| 10 | +# Usage: |
| 11 | +# test-nav3-backstack-entry-mapper-r8.sh Build all APKs, then run them. |
| 12 | +# test-nav3-backstack-entry-mapper-r8.sh build DIR Build all APKs into DIR. |
| 13 | +# test-nav3-backstack-entry-mapper-r8.sh run DIR Install and run every APK built into DIR. |
| 14 | +# |
| 15 | +# The APKs go in a subdirectory of DIR that only this script writes to, so DIR may also hold |
| 16 | +# unrelated files, which neither command touches. |
| 17 | +set -euo pipefail |
| 18 | + |
| 19 | +module="nav3-backstack-entry-mapper-r8-check" |
| 20 | +moduleDir="sentry-android-integration-tests/nav3-backstack-entry-mapper-r8-check" |
| 21 | +appId="io.sentry.tests.nav3.r8" |
| 22 | +tag="NAV3_R8_CHECK" |
| 23 | + |
| 24 | +# Extra versions as "<role> <version>" lines. Set, e.g., |
| 25 | +# NAV3_EXTRA_KOTLINX_VERSIONS="1.10.0 1.12.0" to test the floor, 1.10.0, and 1.12.0, all required. |
| 26 | +# Without it, only the floor is tested. |
| 27 | +extraKotlinxVersions=() |
| 28 | +for version in ${NAV3_EXTRA_KOTLINX_VERSIONS:-}; do |
| 29 | + extraKotlinxVersions+=("extra $version") |
| 30 | +done |
| 31 | + |
| 32 | +copyApk() { |
| 33 | + cp "${moduleDir}/build/outputs/apk/release/nav3-backstack-entry-mapper-r8-check-release.apk" "$1" |
| 34 | +} |
| 35 | + |
| 36 | +# Prints the subdirectory of DIR $1 that holds this script's APKs. |
| 37 | +apkDirIn() { |
| 38 | + echo "$1/${module}" |
| 39 | +} |
| 40 | + |
| 41 | +build() { |
| 42 | + local outDir |
| 43 | + outDir="$(apkDirIn "$1")" |
| 44 | + mkdir -p "$outDir" |
| 45 | + # Removes APKs from earlier builds, which run() would otherwise run too (e.g., one for a release |
| 46 | + # candidate that's no longer tested). Only this script writes to outDir, so no other APKs are lost. |
| 47 | + rm -f "$outDir"/*.apk |
| 48 | + for mode in full compat; do |
| 49 | + local fullMode=true |
| 50 | + [[ "$mode" == "compat" ]] && fullMode=false |
| 51 | + echo "Building R8 $mode mode APK (kotlinx floor)..." |
| 52 | + ./gradlew -p sentry-android-integration-tests ":${module}:assembleRelease" "-Pandroid.enableR8.fullMode=${fullMode}" |
| 53 | + copyApk "${outDir}/${mode}.apk" |
| 54 | + |
| 55 | + # Compat mode keeps more than full mode, so it's only tested with the floor, where it changes |
| 56 | + # the outcome for named companion objects (kotlinx.serialization's own R8 rules only cover them |
| 57 | + # from 1.10.0 on). |
| 58 | + [[ "$mode" == "compat" ]] && continue |
| 59 | + |
| 60 | + # Apps may ship a newer kotlinx than our compile floor, so rebuild against each. |
| 61 | + for entry in ${extraKotlinxVersions[@]+"${extraKotlinxVersions[@]}"}; do |
| 62 | + local role version |
| 63 | + read -r role version <<< "$entry" |
| 64 | + echo "Building R8 $mode mode APK (kotlinx ${version}, ${role})..." |
| 65 | + ./gradlew -p sentry-android-integration-tests ":${module}:assembleRelease" \ |
| 66 | + "-Pandroid.enableR8.fullMode=${fullMode}" "-Pnav3CheckKotlinxVersion=${version}" |
| 67 | + copyApk "${outDir}/${mode}-kotlinx-${version}.apk" |
| 68 | + done |
| 69 | + done |
| 70 | +} |
| 71 | + |
| 72 | +# Installs and launches APK $1, prints what its check reports, and returns non-zero unless the check |
| 73 | +# passed. Failures to install or launch the APK return non-zero too, rather than exiting, so that |
| 74 | +# run() can apply the same advisory rule to them. |
| 75 | +runApk() { |
| 76 | + local apk="$1" |
| 77 | + adb uninstall "$appId" > /dev/null 2>&1 || true |
| 78 | + adb install "$apk" > /dev/null || return 1 |
| 79 | + # Only read lines logged from this launch on, so a stale RESULT=PASS from the previous APK can't |
| 80 | + # hide this one's failure. Doesn't clear the log, which would also discard unrelated logs on a |
| 81 | + # development device. The timestamp is truncated to the second, so wait a second for it to |
| 82 | + # postdate earlier lines. |
| 83 | + local since |
| 84 | + sleep 1 |
| 85 | + since="$(adb shell "date +'%m-%d %H:%M:%S.000'" | tr -d '\r')" || return 1 |
| 86 | + adb shell am start -W -n "${appId}/.BackStackEntryMapperActivity" > /dev/null || return 1 |
| 87 | + |
| 88 | + local output="" |
| 89 | + for _ in $(seq 1 60); do |
| 90 | + output="$(adb logcat -d -T "$since" -s "${tag}:I" | grep "${tag}" || true)" |
| 91 | + if grep -q "RESULT=" <<< "$output"; then |
| 92 | + break |
| 93 | + fi |
| 94 | + if adb logcat -d -T "$since" -b crash | grep -q "$appId"; then |
| 95 | + break |
| 96 | + fi |
| 97 | + sleep 1 |
| 98 | + done |
| 99 | + |
| 100 | + if [[ -n "$output" ]]; then |
| 101 | + sed -E "s/^.*${tag}: //" <<< "$output" |
| 102 | + fi |
| 103 | + if ! grep -q "RESULT=PASS" <<< "$output"; then |
| 104 | + adb logcat -d -T "$since" -b crash | grep -A 20 "$appId" || true |
| 105 | + return 1 |
| 106 | + fi |
| 107 | +} |
| 108 | + |
| 109 | +run() { |
| 110 | + local apkDir |
| 111 | + apkDir="$(apkDirIn "$1")" |
| 112 | + local failed=0 |
| 113 | + shopt -s nullglob |
| 114 | + local apks=("$apkDir"/*.apk) |
| 115 | + if [[ ${#apks[@]} -eq 0 ]]; then |
| 116 | + echo "No APKs found in $apkDir" |
| 117 | + exit 1 |
| 118 | + fi |
| 119 | + |
| 120 | + for apk in "${apks[@]}"; do |
| 121 | + local name |
| 122 | + name="$(basename "$apk" .apk)" |
| 123 | + echo "=== $name" |
| 124 | + if ! runApk "$apk"; then |
| 125 | + echo "FAILED: $name" |
| 126 | + failed=1 |
| 127 | + fi |
| 128 | + done |
| 129 | + |
| 130 | + if [[ $failed -ne 0 ]]; then |
| 131 | + echo "Nav3 BackStackEntryMapper R8 check failed." |
| 132 | + exit 1 |
| 133 | + fi |
| 134 | + echo "Nav3 BackStackEntryMapper R8 check passed." |
| 135 | +} |
| 136 | + |
| 137 | +case "${1:-}" in |
| 138 | + build) build "${2:?Usage: $0 build DIR}" ;; |
| 139 | + run) run "${2:?Usage: $0 run DIR}" ;; |
| 140 | + "") |
| 141 | + apkDir="${moduleDir}/build/r8-check-apks" |
| 142 | + build "$apkDir" |
| 143 | + run "$apkDir" |
| 144 | + ;; |
| 145 | + *) |
| 146 | + echo "Usage: $0 [build DIR | run DIR]" |
| 147 | + exit 1 |
| 148 | + ;; |
| 149 | +esac |
0 commit comments