From 59eaa0eb063dbf849f80bb59ff782eb29fdd96b4 Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Thu, 3 Dec 2026 15:53:28 -0500 Subject: [PATCH] fix(agent): after agent setup, Gradle and git work on the device (#3642) --- app/src/main/assets/agent/dd-gh-login | 17 ++++++++++++ .../droiddeck/launcher/agent/AgentSetup.kt | 13 +++++++++- tools/agent/AGENTS.md | 4 ++- tools/agent/dd-gh-login | 17 ++++++++++++ tools/agent/setup | 26 +++++++++++++++++++ 5 files changed, 75 insertions(+), 2 deletions(-) diff --git a/app/src/main/assets/agent/dd-gh-login b/app/src/main/assets/agent/dd-gh-login index f9b0b7734a..e02054ffc1 100644 --- a/app/src/main/assets/agent/dd-gh-login +++ b/app/src/main/assets/agent/dd-gh-login @@ -28,6 +28,19 @@ float_code() { [ "$result" = ok ] } +# git pushes through gh's sign-in and commits as the signed-in account, with its no-reply address. +configure_git() { + gh auth setup-git || return 1 + [ -n "$(git config --global user.name)" ] && [ -n "$(git config --global user.email)" ] && return 0 + local user id login name + user=$(gh api user -q '"\(.id) \(.login) \(.name // .login)"') || return 1 + read -r id login name <<<"$user" + [ -n "$id" ] && [ -n "$login" ] || return 1 + [ -n "$(git config --global user.name)" ] || git config --global user.name "${name:-$login}" + [ -n "$(git config --global user.email)" ] || git config --global user.email "$id+$login@users.noreply.github.com" +} +if [ "${1:-}" = --git ]; then configure_git; exit; fi + coproc GH { BROWSER=true gh auth login --hostname github.com --git-protocol https --web 2>&1; } gh_pid=$GH_PID exec {ghout}<&"${GH[0]}" {ghin}>&"${GH[1]}" @@ -48,5 +61,9 @@ while IFS= read -r line <&"$ghout"; do done wait "$gh_pid" status=$? +if [ $status = 0 ] && ! configure_git; then + echo "Signed in, but git could not be set up: run dd-gh-login --git" + status=1 +fi [ -n "$shown" ] && [ -n "$inbox" ] && [ -d "$inbox" ] && : > "$inbox/device-code" exit $status diff --git a/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt b/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt index aa2ad40ae7..ad78dd3d44 100644 --- a/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/agent/AgentSetup.kt @@ -226,7 +226,18 @@ object AgentSetup { /** The whole output of a step's last run; the card shows only its last line. */ fun logFile(app: Context, step: Step) = File(app.filesDir, "agent/setup-${step.name.lowercase()}.log") - fun buildToolsInstalled(app: Context) = AgentHost.guestFileExists(app, "/root/aapt2/aapt2") && AgentHost.guestFileExists(app, "$CHECKOUT/.git") + /** + * An install set up before setup wrote the Gradle init script gets the step again, but only + * once the checkout's setup writes it: the step runs that script, and an older one never would. + */ + fun buildToolsInstalled(app: Context) = AgentHost.guestFileExists(app, "/root/aapt2/aapt2") && AgentHost.guestFileExists(app, "$CHECKOUT/.git") && + (AgentHost.guestFileExists(app, GRADLE_INIT) || !setupWritesGradleInit(app)) + + private const val GRADLE_INIT = "/root/.gradle/init.d/droiddeck-device.gradle" + + private fun setupWritesGradleInit(app: Context) = runCatching { + File(LinuxRuntime.rootDir(app), "$CHECKOUT/tools/agent/setup".removePrefix("/")).readText().contains(GRADLE_INIT.substringAfterLast('/')) + }.getOrDefault(false) /** dd-lab-build compiled this install's commit, so a Lab build compiles only what changed. */ private fun prepared(app: Context) = runCatching { diff --git a/tools/agent/AGENTS.md b/tools/agent/AGENTS.md index 20b1736bd7..d9b7deb09e 100644 --- a/tools/agent/AGENTS.md +++ b/tools/agent/AGENTS.md @@ -59,7 +59,9 @@ The source is checked out at `/root/DroidDeck` once the Agent tab's build tools process, and the conversation continues on the new build. - Python tests run from the repository root: `python3 -m unittest tools.tests.test_x`. Some fail on the device on `origin/main` too; run them on a worktree of `origin/main` before blaming a change. -- Gradle unit tests rarely run on the device. Leave them to CI and say so rather than retrying. +- Gradle runs on the device once the build tools are set up, but slowly: run the test classes that cover + your change, and leave full suites and native builds to CI. `PreviewRenderTest` cannot run here + (Robolectric's native graphics has no aarch64 Linux build). - If `git push` asks for credentials, run `gh auth setup-git` once. - Commits and pull requests you make are the user's own: no co-author line, AI credit or generated-by note. diff --git a/tools/agent/dd-gh-login b/tools/agent/dd-gh-login index f9b0b7734a..e02054ffc1 100755 --- a/tools/agent/dd-gh-login +++ b/tools/agent/dd-gh-login @@ -28,6 +28,19 @@ float_code() { [ "$result" = ok ] } +# git pushes through gh's sign-in and commits as the signed-in account, with its no-reply address. +configure_git() { + gh auth setup-git || return 1 + [ -n "$(git config --global user.name)" ] && [ -n "$(git config --global user.email)" ] && return 0 + local user id login name + user=$(gh api user -q '"\(.id) \(.login) \(.name // .login)"') || return 1 + read -r id login name <<<"$user" + [ -n "$id" ] && [ -n "$login" ] || return 1 + [ -n "$(git config --global user.name)" ] || git config --global user.name "${name:-$login}" + [ -n "$(git config --global user.email)" ] || git config --global user.email "$id+$login@users.noreply.github.com" +} +if [ "${1:-}" = --git ]; then configure_git; exit; fi + coproc GH { BROWSER=true gh auth login --hostname github.com --git-protocol https --web 2>&1; } gh_pid=$GH_PID exec {ghout}<&"${GH[0]}" {ghin}>&"${GH[1]}" @@ -48,5 +61,9 @@ while IFS= read -r line <&"$ghout"; do done wait "$gh_pid" status=$? +if [ $status = 0 ] && ! configure_git; then + echo "Signed in, but git could not be set up: run dd-gh-login --git" + status=1 +fi [ -n "$shown" ] && [ -n "$inbox" ] && [ -d "$inbox" ] && : > "$inbox/device-code" exit $status diff --git a/tools/agent/setup b/tools/agent/setup index e3b649db5e..45ad8144f7 100755 --- a/tools/agent/setup +++ b/tools/agent/setup @@ -16,6 +16,9 @@ command -v claude >/dev/null || [ -x "$HOME/.local/bin/claude" ] || mkdir -p "$HOME/.local/bin" for tool in dd-agent dd-lab-build dd-gh-login android-open; do install -m755 "$here/$tool" "$HOME/.local/bin/$tool"; done +if gh auth status >/dev/null 2>&1 && ! "$here/dd-gh-login" --git; then + echo "setup: git could not use the GitHub sign-in; run dd-gh-login --git" >&2 +fi # DroidDeck passes the live loopback adb port; a fixed one here would go stale whenever wireless debugging is toggled. sed -i 's|ADB_SERIAL=127.0.0.1:5555 |ADB_SERIAL="${ADB_SERIAL:-127.0.0.1:5555}" |' "$HOME/.bashrc" 2>/dev/null || true grep -q 'droiddeck-agent-path' "$HOME/.bashrc" 2>/dev/null || @@ -63,6 +66,29 @@ if [ ! -x "$sdk/cmdline-tools/latest/bin/sdkmanager" ]; then mv "$sdk/cmdline-tools/cmdline-tools" "$sdk/cmdline-tools/latest" fi export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-arm64 +# Ubuntu's default JDK can be newer than the Gradle wrapper supports, so every shell and Gradle run +# here uses 17, the SDK above and the qemu-wrapped aapt2, not only dd-lab-build's. +sed -i '/^# droiddeck-agent-gradle$/,+1d' "$HOME/.bashrc" 2>/dev/null || true +printf '# droiddeck-agent-gradle\nexport JAVA_HOME=%s ANDROID_HOME="$HOME/android-sdk"\n' "$JAVA_HOME" >> "$HOME/.bashrc" +mkdir -p "$HOME/.gradle" +touch "$HOME/.gradle/gradle.properties" +# Gradle's own settings carry the SDK too, for shells that do not read ~/.bashrc. +for setting in "org.gradle.java.home=$JAVA_HOME" "android.aapt2FromMavenOverride=$HOME/aapt2/aapt2" "systemProp.android.home=$sdk"; do + sed -i "/^${setting%%=*}=/d" "$HOME/.gradle/gradle.properties" + echo "$setting" >> "$HOME/.gradle/gradle.properties" +done +# The NDK's compilers are x86-64 only, so DroidDeck's native code is left to CI, as dd-lab-build does, +# and Conscrypt ships no aarch64 Linux library for Robolectric to load. +mkdir -p "$HOME/.gradle/init.d" +cat > "$HOME/.gradle/init.d/droiddeck-device.gradle" <<'GRADLE' +settingsEvaluated { settings -> + if (settings.rootProject.name != 'DroidDeck') return + gradle.startParameter.excludedTaskNames += ':app:buildVkBridgeServer' + gradle.allprojects { + tasks.withType(org.gradle.api.tasks.testing.Test).configureEach { systemProperty 'robolectric.conscryptMode', 'OFF' } + } +} +GRADLE (set +o pipefail; yes | "$sdk/cmdline-tools/latest/bin/sdkmanager" --licenses >/dev/null) "$sdk/cmdline-tools/latest/bin/sdkmanager" "platforms;android-34" "build-tools;35.0.0" >/dev/null