diff --git a/app/build-apk.sh b/app/build-apk.sh index 4f9efc7..eae66a9 100755 --- a/app/build-apk.sh +++ b/app/build-apk.sh @@ -55,8 +55,41 @@ else exit 1 fi +# Dev Updater draws a real progress bar from "@@progress done/total" lines, +# and ignores anything that isn't exactly that shape. Gradle can't be asked +# for this directly: an init script using taskGraph.afterTask is rejected +# outright by the configuration cache, and whenReady never fires on a cache +# hit. --dry-run costs about a second, is cache-friendly, and prints one +# ":task SKIPPED" line per task the real build will run, which is exactly +# the total. The build then prints one "> Task :x" line per task as it +# goes, so counting those against it is the whole mechanism. +# +# Task count is not time -- compileDebugKotlin and dexBuilder are most of +# the wall clock -- so the bar moves unevenly. It is still counted work +# rather than a guess at how long last time took. +TASKS=$(./gradlew :androidApp:assembleDebug --dry-run --console=plain 2>/dev/null \ + | grep -c '^:[A-Za-z:]* SKIPPED' || true) + echo "==> Building" -./gradlew :androidApp:assembleDebug +if [ "${TASKS:-0}" -gt 0 ]; then + echo "@@progress 0/$TASKS" + DONE=0 + ./gradlew :androidApp:assembleDebug --console=plain 2>&1 | while IFS= read -r line; do + echo "$line" + case "$line" in + "> Task "*) + DONE=$((DONE + 1)) + echo "@@progress $DONE/$TASKS" + ;; + esac + done + # The pipeline's exit status is the shell's, not gradle's, so ask + # gradle again rather than reporting a failed build as a success. It is + # up to date by now, so this is a second or two. + ./gradlew :androidApp:assembleDebug --console=plain >/dev/null +else + ./gradlew :androidApp:assembleDebug +fi APK="$SCRIPT_DIR/androidApp/build/outputs/apk/debug/androidApp-debug.apk" echo