Files
iris 69a22c54e7 Stop Gradle installing on every checkout's emulator at once
The adb wrapper can only aim a call that goes through it, and Gradle's
Android tasks do not: installDebug, uninstallDebug and connectedAndroidTest
ask the adb server for every attached device and act on all of them. One
session ran installDebug with two emulators up and replaced the app on both,
which Gradle reported as success and the other session read as its own build
never landing.

`emu check` answers the question the wrapper already answers for adb --
would a command that reaches every attached device reach a stranger's
emulator from here -- and install.sh links a Gradle init script into
~/.gradle/init.d so every build on this machine asks it, including checkouts
nobody has adopted it in.

It refuses narrowly: a lone emulator, a physical phone and a caller who
named a device are all fine. ANDROID_SERIAL naming another checkout's
emulator is not, because that is what a serial exported into a long-lived
shell decays into once an emulator restarts and another's takes the port.
2026-08-31 15:40:58 -04:00

70 lines
2.8 KiB
Bash
Executable File

#!/bin/sh
# Puts these tools where a shell and an agent will find them, by symlink.
#
# Symlinks rather than copies so that editing the repo is editing what runs --
# the alternative is a second copy that drifts, which is exactly what this
# repo was made to end (ui-trace, the adb wrapper and three near-identical
# emulator boot sequences all lived in different places).
#
# Idempotent: run it again after a pull, or after adding a command.
set -eu
here=$(cd "$(dirname "$0")" && pwd)
bindir=${BINDIR:-$HOME/.local/bin}
sharedir=${SHAREDIR:-$HOME/.local/share}
mkdir -p "$bindir" "$sharedir"
for target in "$here"/bin/*; do
name=$(basename "$target")
link="$bindir/$name"
# A real file here is the pre-repo copy of one of these tools. Kept, once,
# under .bak: it is somebody's working state until they have looked at it,
# and a tool that silently deletes the thing it replaces is one nobody can
# undo.
if [ -e "$link" ] && [ ! -L "$link" ]; then
echo "install: keeping the existing $name as $name.bak"
mv "$link" "$link.bak"
fi
ln -sfn "$target" "$link"
echo "install: $link -> $target"
done
# The device recorder's source and build script, which ui-trace reads from a
# fixed path and rebuilds when the source is newer than the jar. Linked as a
# directory so a rebuild lands in the repo rather than beside it.
if [ -e "$sharedir/ui-trace" ] && [ ! -L "$sharedir/ui-trace" ]; then
echo "install: keeping the existing share/ui-trace as ui-trace.bak"
mv "$sharedir/ui-trace" "$sharedir/ui-trace.bak"
fi
ln -sfn "$here/share/ui-trace" "$sharedir/ui-trace"
echo "install: $sharedir/ui-trace -> $here/share/ui-trace"
# Gradle never goes through the adb wrapper -- its device tasks reach every
# attached device by themselves -- so the one place that can hold for a
# checkout nobody has adopted this in is an init script, which Gradle applies
# to every build on this machine.
gradledir=${GRADLE_INIT_DIR:-$HOME/.gradle/init.d}
mkdir -p "$gradledir"
init="$gradledir/emulator-tools.gradle"
if [ -e "$init" ] && [ ! -L "$init" ]; then
echo "install: keeping the existing emulator-tools.gradle as emulator-tools.gradle.bak"
mv "$init" "$init.bak"
fi
ln -sfn "$here/share/gradle-init/emulator-tools.gradle" "$init"
echo "install: $init -> $here/share/gradle-init/emulator-tools.gradle"
case ":$PATH:" in
*":$bindir:"*) ;;
*) echo "install: note -- $bindir is not on PATH" ;;
esac
# The adb wrapper only wins if it comes before the SDK's own on PATH. Said
# rather than fixed: which shell profile to edit is not this script's to
# decide, and getting it wrong is a broken login shell.
real=$(command -v adb 2>/dev/null || true)
if [ "$real" != "$bindir/adb" ]; then
echo "install: note -- 'adb' resolves to $real, not $bindir/adb;"
echo " put $bindir before the SDK's platform-tools on PATH."
fi