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
@@ -5,6 +5,8 @@
# Prints what it removes and the space freed. Waits for the Gradle lock of tools/gradle-serial.sh, so it never deletes
# under a running build. The orchestrator runs it after removing a worktree or when the disk is low.
# Usage from any checkout: tools/clean-builds.sh [--dry-run]
# shellcheck source-path=SCRIPTDIR source=gradle-lock.sh
. "$(dirname "$0")/gradle-lock.sh"
dry=0
case "$1" in
--dry-run) dry=1 ;;
@@ -39,14 +41,8 @@ done > "$list"
if [ ! -s "$list" ]; then echo "Nothing to remove."; exit 0; fi
if [ "$dry" -eq 0 ]; then
lock=/tmp/kvitt-gradle.lock
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"; rm -f "$list"' EXIT INT TERM HUP
gradle_lock_acquire
trap 'rm -rf "$KVITT_GRADLE_LOCK"; rm -f "$list"' EXIT INT TERM HUP
fi
total=0