From 95aab3703fa24de87fae5c6bf3af9fea17c4d8cc Mon Sep 17 00:00:00 2001 From: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com> Date: Mon, 23 Nov 2026 21:55:27 -0500 Subject: [PATCH] fix(build): helper script edits no longer invalidate the prepared runtime, and every build uses CI's NDK (#3116) * fix(build): helper script edits no longer invalidate the prepared runtime, and every build uses CI's NDK * docs(agents): helper script edits no longer need build_local.sh --- AGENTS.md | 4 +-- app/build.gradle | 11 ++++----- gradle.properties | 1 - tools/build_local.sh | 5 ++++ tools/release/check_session_assets.py | 12 +++++++++ tools/release/runtime_inputs.py | 25 ++++++++++++++++++- tools/seed_worktree.sh | 9 +++++-- tools/tests/test_runtime_inputs.py | 35 +++++++++++++++++++++++++++ tools/tests/test_session_assets.py | 7 ++++++ 9 files changed, 97 insertions(+), 12 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 2997ceb10d..4832415479 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -5,8 +5,8 @@ # Building and testing - For an install-and-look iteration, use `tools/quick_deploy.sh` (build without lint, sign, install, about 30 s). Run `tools/build_local.sh` once to prepare the runtime and again only before a PR. It is not a per-change step. -- `verifyRuntimeInputs` fails the fast build with "Missing or changed runtime input" or "Runtime sources changed since preparation" after you pull main or edit `tools/linuxfs` (overlay scripts, preloads). Run `tools/build_local.sh` once. Do not revert scripts or copy `app/build` from another checkout to get past it. -- CI builds with the NDK in `tools/ci/toolchains.env` and runs `testReleaseUnitTest`. Local builds default to `gradle.properties`' NDK and `testDebugUnitTest`. Pass `-PndkVersion=` and run the release variant when a failure only shows up in CI. +- Helper scripts (`tools/linuxfs/overlay`, `tools/linuxfs/desktop`) are staged on every Gradle build, so editing them needs no `build_local.sh`. After preloads or other runtime components change, the fast loop warns and reuses the old binaries; run `tools/build_local.sh` when those matter. "Missing or changed runtime input" means the prepared files themselves changed: run `tools/build_local.sh` once. Do not revert scripts or copy `app/build` between checkouts; `tools/seed_worktree.sh` seeds a new worktree from the main checkout. +- Every build defaults to the NDK in `tools/ci/toolchains.env`, as CI does. CI runs `testReleaseUnitTest`; when a test fails only in CI, run the release variant locally. - Run the tests that cover what you changed, including unchanged tests of code you edited: `./gradlew -PskipRust=true :app:testDebugUnitTest --tests ''` and `python3 -m unittest discover -s tools/tests -p 'test_*.py'`. The full Python suite takes about 9 minutes, and some preload tests fail on any host without zram/ntsync. Leave full runs to CI. - For UI screenshots without a device, run `./gradlew -PskipRust=true :app:testDebugUnitTest --tests '*PreviewRenderTest'` and read `app/build/preview-renders/{handheld,portrait}/`. Add cases per `docs/compose-previews.md`. Check portrait, not just landscape. - After changing `SettingsIndex`, regenerate the doc: `UPDATE_SETTINGS_MAP=1 ./gradlew -PskipRust=true :app:testDebugUnitTest --tests '*SettingsMapTest*'`. diff --git a/app/build.gradle b/app/build.gradle index b32bc078a9..f2cb40169b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -125,7 +125,8 @@ def variantSuffixes = rootProject.file('tools/release/variants.txt').readLines() android { namespace 'com.droiddeck.launcher' compileSdk 34 - ndkVersion project.findProperty('ndkVersion') ?: '27.3.13750724' + ndkVersion project.findProperty('ndkVersion') ?: providers.fileContents(rootProject.layout.projectDirectory.file('tools/ci/toolchains.env')) + .asText.get().readLines().find { it.startsWith('CI_ANDROID_NDK_VERSION=') }.split('=', 2)[1].trim() defaultConfig { applicationId "com.droiddeck.launcher" @@ -264,11 +265,9 @@ if (vitureSdkDir) { tasks.named('preBuild').configure { dependsOn(stageVitureNotices) } } -def stageSessionScripts = tasks.register('stageSessionScripts', Copy) { - from(rootProject.file('tools/linuxfs/overlay')) { - include 'usr/local/bin/droiddeck-*', 'usr/local/bin/steam-compatibility', 'usr/bin/**' - } - into(layout.projectDirectory.dir('src/main/assets/linuxfs')) +def stageSessionScripts = tasks.register('stageSessionScripts', Exec) { + workingDir rootProject.projectDir + commandLine pythonExecutable, 'tools/release/check_session_assets.py', '--stage' } tasks.named('preBuild').configure { dependsOn(stageSessionScripts) } diff --git a/gradle.properties b/gradle.properties index 3289cc4c5d..16bca3f56d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,6 +4,5 @@ org.gradle.configuration-cache=true org.gradle.parallel=true android.useAndroidX=true android.nonTransitiveRClass=true -ndkVersion=27.3.13750724 org.gradle.tooling.parallel=true diff --git a/tools/build_local.sh b/tools/build_local.sh index d90a458d2c..ea3ebebbcf 100755 --- a/tools/build_local.sh +++ b/tools/build_local.sh @@ -63,6 +63,11 @@ fi ndk_version=${DROIDDECK_NDK_VERSION:-} if [[ -z "${ndk_version}" ]]; then + . "${repo_root}/tools/ci/toolchains.env" + [[ -d "${sdk_dir}/ndk/${CI_ANDROID_NDK_VERSION}" ]] && ndk_version=${CI_ANDROID_NDK_VERSION} +fi +if [[ -z "${ndk_version}" ]]; then + echo "NDK ${CI_ANDROID_NDK_VERSION} (tools/ci/toolchains.env) is not installed; using the newest NDK instead, so native caches will not match CI." >&2 ndk_path=$(find "${sdk_dir}/ndk" -mindepth 2 -maxdepth 2 -name source.properties -print | xargs -n1 dirname | sort -V | tail -1) ndk_version=${ndk_path##*/} fi diff --git a/tools/release/check_session_assets.py b/tools/release/check_session_assets.py index 940e722481..8a87e1af9d 100644 --- a/tools/release/check_session_assets.py +++ b/tools/release/check_session_assets.py @@ -1,6 +1,7 @@ from pathlib import Path import importlib.util import re +import shutil import sys from zipfile import ZipFile @@ -34,6 +35,14 @@ def source_assets(overlay=OVERLAY): return result +def stage(target=OVERLAY.parents[2] / 'app/src/main', overlay=OVERLAY): + for source, asset in source_assets(overlay).items(): + path = target / asset + if not path.is_file() or path.read_bytes() != source.read_bytes(): + path.parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(source, path) + + def check(apk, overlay=OVERLAY): errors = check_extraction(overlay, SESSION_FILES.read_text()) if overlay == OVERLAY else [] with ZipFile(apk) as package: @@ -60,6 +69,9 @@ def check(apk, overlay=OVERLAY): if __name__ == '__main__': + if sys.argv[1:] == ['--stage']: + stage() + sys.exit() errors = check(sys.argv[1]) if errors: sys.exit('\n'.join(errors)) diff --git a/tools/release/runtime_inputs.py b/tools/release/runtime_inputs.py index 89488e1ba5..440c682cd8 100644 --- a/tools/release/runtime_inputs.py +++ b/tools/release/runtime_inputs.py @@ -48,8 +48,19 @@ def digest(path): return result.hexdigest() +def copied(root): + # Helper scripts are staged verbatim on every Gradle build and checked against the APK by + # check_session_assets.py, so they are neither preparation inputs nor prepared outputs. + if str(Path(__file__).resolve().parent) not in sys.path: + sys.path.insert(0, str(Path(__file__).resolve().parent)) + from check_session_assets import OVERLAY, source_assets + found = source_assets() if root == ROOT else source_assets(root / OVERLAY.relative_to(ROOT)) + return {source.relative_to(root).as_posix(): 'app/src/main/' + asset for source, asset in found.items()} + + def sources(root): files, builds = [], set() + skipped = set(copied(root)) for name in SOURCE_PATHS: path = root / name files.extend(path.rglob('*') if path.is_dir() else [path]) @@ -57,14 +68,18 @@ def sources(root): builds.update(manifest.parent / 'target' for manifest in path.rglob('Cargo.toml')) return {path.relative_to(root).as_posix(): digest(path) for path in sorted(set(files)) if path.is_file() and '__pycache__' not in path.parts and path.suffix != '.pyc' + and path.relative_to(root).as_posix() not in skipped and not any(build in path.parents for build in builds)} def outputs(root): result = {} + skipped = set(copied(root).values()) for tree in ['linuxfs', 'directaudio', 'droiddeck-esync', 'desktop-removal', 'hybris']: base = root / 'app/src/main/assets' / tree for path in base.rglob('*'): + if path.relative_to(root).as_posix() in skipped: + continue if path.is_file() and not any(part.startswith('.') for part in path.relative_to(base).parts): result['assets/' + tree + '/' + path.relative_to(base).as_posix()] = path.relative_to(root).as_posix() for library in ['libproot.so', 'libproot-loader.so', 'libdirectaudiorelay.so']: @@ -84,7 +99,6 @@ def required(): for name in ['turnip26.3.0-a6xx', 'turnip26.3.0-quest2']] paths += ['assets/linuxfs/' + name for name in ['libfakeinput.so', 'libddsession.so', 'libddfastpath.so', 'libddnatv-hook.so', 'libssbs.so', 'usr/local/bin/droiddeck-clipboard', - 'usr/local/bin/droiddeck-gog-maintenance', 'usr/local/bin/gamescope', 'usr/local/lib/droiddeck/uruntime', 'usr/local/lib/droiddeck-pipewire.tzst']] for arch in ['x86_64', 'i386']: @@ -178,6 +192,10 @@ def verify(root=ROOT, stale_sources_ok=False): raise ValueError('Runtime inputs have not been prepared. Run tools/build_local.sh.') if data.get('version') != 1: raise ValueError('Runtime sources changed since preparation. Run tools/build_local.sh.') + copies = copied(root) + data['sources'] = {name: value for name, value in (data.get('sources') or {}).items() if name not in copies} + data['outputs'] = {name: output for name, output in (data.get('outputs') or {}).items() + if output.get('path') not in copies.values()} current = sources(root) if data.get('sources') != current: if not stale_sources_ok: @@ -195,6 +213,11 @@ def verify(root=ROOT, stale_sources_ok=False): raise ValueError('Missing or changed runtime input: ' + name + '. Run tools/build_local.sh.') if outputs(root) != {name: output['path'] for name, output in data['outputs'].items()}: raise ValueError('Runtime file set changed. Run tools/build_local.sh.') + for source, asset in copies.items(): + path = root / asset + if not path.is_file() or path.read_bytes() != (root / source).read_bytes(): + raise ValueError(asset + ' is not a current copy of ' + source + + '. Run python3 tools/release/check_session_assets.py --stage.') return data diff --git a/tools/seed_worktree.sh b/tools/seed_worktree.sh index e5079e7111..45bbc56bed 100755 --- a/tools/seed_worktree.sh +++ b/tools/seed_worktree.sh @@ -10,14 +10,19 @@ paths=( app/build/packs app/build/localPackAssets app/build/packs-local-aside app/build/quest-inputs app/build/rustJniLibs app/build/vkbridgeJniLibs app/src/main/assets/directaudio app/src/main/assets/droiddeck-esync app/src/main/assets/linuxfs - app/src/main/assets/desktop-removal + app/src/main/assets/desktop-removal app/src/main/assets/hybris app/src/main/jniLibs/arm64-v8a app/src/main/rust/stores/target ) for path in "${paths[@]}"; do [[ -e "${main_root}/${path}" ]] || continue if [[ -d "${main_root}/${path}" ]]; then - [[ -z "$(ls -A "${repo_root}/${path}" 2>/dev/null)" ]] || continue + if [[ -n "$(ls -A "${repo_root}/${path}" 2>/dev/null)" ]]; then + # A directory holding only tracked files (jniLibs) still lacks every built library. + [[ -z "$(git -C "${repo_root}" ls-files --others -- "${path}")" ]] || continue + cp -Rn "${main_root}/${path}/." "${repo_root}/${path}/" + continue + fi mkdir -p "$(dirname "${repo_root}/${path}")" staged=$(mktemp -d "${repo_root}/${path}.seed.XXXXXX") trap 'rm -rf "${staged}"' EXIT diff --git a/tools/tests/test_runtime_inputs.py b/tools/tests/test_runtime_inputs.py index 92f2ae1c79..2bfbfb4dc3 100644 --- a/tools/tests/test_runtime_inputs.py +++ b/tools/tests/test_runtime_inputs.py @@ -1,6 +1,7 @@ import importlib.util import gzip import io +import json from pathlib import Path, PureWindowsPath import subprocess import tarfile @@ -122,6 +123,40 @@ class RuntimeInputsTest(unittest.TestCase): runtime.verify(self.root, stale_sources_ok=True) self.assertIn('tools/linuxfs/preload/test.c', stderr.getvalue()) + def helper(self, content): + source = self.root / 'tools/linuxfs/overlay/usr/local/bin/droiddeck-test-helper' + source.parent.mkdir(parents=True, exist_ok=True) + source.write_text(content) + staged = self.root / 'app/src/main/assets/linuxfs/usr/local/bin/droiddeck-test-helper' + staged.parent.mkdir(parents=True, exist_ok=True) + staged.write_text(content) + return source, staged + + def test_an_edited_helper_script_needs_no_new_preparation(self): + self.helper('old helper') + runtime.record(self.root) + self.helper('new helper') + runtime.verify(self.root) + + def test_a_staged_helper_that_lags_its_source_is_rejected(self): + source, _ = self.helper('old helper') + runtime.record(self.root) + source.write_text('new helper') + with self.assertRaisesRegex(ValueError, 'not a current copy'): + runtime.verify(self.root, stale_sources_ok=True) + + def test_a_manifest_that_hashed_helper_scripts_still_verifies(self): + source, staged = self.helper('old helper') + runtime.record(self.root) + manifest = self.root / runtime.MANIFEST + data = json.loads(manifest.read_text()) + data['sources']['tools/linuxfs/overlay/usr/local/bin/droiddeck-test-helper'] = 'old' + data['outputs']['assets/linuxfs/usr/local/bin/droiddeck-test-helper'] = { + 'path': 'app/src/main/assets/linuxfs/usr/local/bin/droiddeck-test-helper', 'sha256': 'old'} + manifest.write_text(json.dumps(data)) + self.helper('new helper') + runtime.verify(self.root) + def test_dev_loop_still_rejects_changed_outputs(self): runtime.record(self.root) (self.root / 'app/src/main/jniLibs/arm64-v8a/libproot.so').write_bytes(b'old APK binary') diff --git a/tools/tests/test_session_assets.py b/tools/tests/test_session_assets.py index 5f7f8675d1..563ea1212e 100644 --- a/tools/tests/test_session_assets.py +++ b/tools/tests/test_session_assets.py @@ -50,3 +50,10 @@ class SessionAssetsTest(unittest.TestCase): mapping = '"usr/local/bin/droiddeck-login1" to "usr/local/bin/sub/login1"' self.assertEqual(['not extracted at session start: usr/local/bin/droiddeck-login1'], assets.check_extraction(self.overlay, mapping)) + + def test_stage_refreshes_a_changed_helper(self): + target = self.root / 'main' + assets.stage(target, self.overlay) + self.helper.write_bytes(b'new helper') + assets.stage(target, self.overlay) + self.assertEqual(b'new helper', (target / self.name).read_bytes())