tools: one Gradle lock helper (gradle-lock.sh) for gradle-serial.sh and clean-builds.sh

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TQd3pEP9UeN2uifbHknQ7B
This commit is contained in:
2026-10-18 22:11:07 +02:00
parent 18c527f018
commit 2fac1ecba0
3 changed files with 32 additions and 16 deletions
+4 -8
View File
@@ -3,14 +3,10 @@
# (CLAUDE.md › Build and verify: parallel builds exhaust memory). Waits for a running build to finish, then runs.
# The Gradle project lives in android/; the wrapper there is used whatever directory this is started from.
# Usage from any directory of a checkout or worktree: tools/gradle-serial.sh check (or ../tools/gradle-serial.sh from android/)
lock=/tmp/kvitt-gradle.lock
# shellcheck source-path=SCRIPTDIR source=gradle-lock.sh
. "$(dirname "$0")/gradle-lock.sh"
top=$(git rev-parse --show-toplevel) || exit 1
[ -x "$top/android/gradlew" ] || { echo "gradle-serial: no android/gradlew in $top yet" >&2; exit 1; }
while ! mkdir "$lock" 2>/dev/null; do
pid=$(cat "$lock/pid" 2>/dev/null)
if [ -n "$pid" ] && ! kill -0 "$pid" 2>/dev/null; then rm -rf "$lock"; continue; fi
sleep 5
done
echo $$ > "$lock/pid"
trap 'rm -rf "$lock"' EXIT INT TERM HUP
gradle_lock_acquire
trap 'rm -rf "$KVITT_GRADLE_LOCK"' EXIT INT TERM HUP
cd "$top/android" && ./gradlew "$@"