From 27b36a457efb26bb2a41c6cf4a91ffa8072879dd Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 15:34:29 -0700 Subject: [PATCH] build(tools): add kde-closure-check and e2e-needed kde-closure-check fails when komorebi-for-kde/nix/root-crates.json differs from the KDE cargo closure; e2e-needed says whether a diff touches anything the Windows e2e binaries are built from. Copies of the host-side scripts with these differences only: - kde-closure-check: none (it already finds the repository relative to the script); verbatim. - e2e-needed: `tools/*` joins the paths that cannot change the binaries (docs, .github), so a change to the tools is NO instead of "not understood: treated as needed"; - e2e-needed: `# shellcheck disable=SC2001` before `set` (the sed one-liners indent multi-line output); no behaviour change. Verified: bash -n and shellcheck clean; `tools/kde-closure-check .` prints "ok: 11 root crates match the KDE cargo closure"; `tools/e2e-needed --since ` gives the same output as the host copy on a range without tools/ files, and NO for a tools-only range. --- tools/e2e-needed | 97 +++++++++++++++++++++++++++++++++++++++++ tools/kde-closure-check | 26 +++++++++++ 2 files changed, 123 insertions(+) create mode 100755 tools/e2e-needed create mode 100755 tools/kde-closure-check diff --git a/tools/e2e-needed b/tools/e2e-needed new file mode 100755 index 00000000..41c36230 --- /dev/null +++ b/tools/e2e-needed @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +# e2e-needed: does a diff touch anything the Windows e2e binaries are built from? +# e2e-needed [--range | --since REV] [--to REV] [--closure] (run in a jj workspace root) +# The Windows e2e runs komorebi.exe, komorebic.exe and komorebi-testwin.exe (flake e2eBuild). Their +# inputs are (a) the source directories of the workspace crates they depend on, from `cargo tree +# --target x86_64-pc-windows-msvc -e normal,build` (dev-dependencies are not in the binaries), +# (b) files pulled in with include_str!/include_bytes!/include! from those crates, (c) fixed +# inputs: Cargo.lock, the root Cargo.toml, rust-toolchain.toml, flake.nix, flake.lock, build +# scripts, and the e2e harness itself (e2e/). Anything else cannot change those binaries. +# Verdict NO means: every touched file is outside all of that, so a passing e2e of the previous +# binaries carries over unchanged. Verdict YES prints which files decided it. Files that are not +# understood count as YES. Uses `cargo tree --offline` (about 1-2 s, no build). Never writes. +# NOT covered by this verdict: the other gates (nextest, clippy, the bar screenshot, KDE VM, schema oracles). +# shellcheck disable=SC2001 # the sed one-liners indent multi-line output +set -uo pipefail +FROM=""; TO="@"; SHOWCL=0 +while [ $# -gt 0 ]; do + case "$1" in + --range) FROM='trunk()' ;; + --since) shift; FROM="${1:?--since needs a revset}" ;; + --to) shift; TO="${1:?--to needs a revset}" ;; + --closure) SHOWCL=1 ;; + -h|--help) sed -n '2,16p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;; + *) echo "usage: e2e-needed [--range | --since REV] [--to REV] [--closure]" >&2; exit 2 ;; + esac + shift +done +ROOT="$(jj root 2>/dev/null)" || { echo "e2e-needed: not in a jj workspace" >&2; exit 2; } +cd "$ROOT" || exit 2 +if [ -n "$FROM" ]; then FILES="$(jj diff --name-only --from "$FROM" --to "$TO")"; else FILES="$(jj diff --name-only -r "$TO")"; fi +[ -n "$FILES" ] || { echo "NO (nothing changed in @; use --since REV)"; exit 0; } + +# (a) closure: workspace crate directories (relative to root) +CL="" +for p in komorebi komorebi-windows komorebic komorebi-testwin; do + CL+="$(CARGO_BUILD_JOBS=1 nice -n 19 cargo tree --offline --locked -p "$p" --target x86_64-pc-windows-msvc \ + --prefix none -e normal,build 2>/dev/null | grep -o "(${ROOT}[^)]*)" | tr -d '()' | sed "s#^${ROOT}/\{0,1\}##")"$'\n' +done +CL="$(echo "$CL" | sed '/^$/d' | sort -u)" +[ -n "$CL" ] || { echo "YES (could not compute the dependency closure: cargo tree failed; treating as needed)"; exit 0; } +[ $SHOWCL = 1 ] && { echo "closure directories:"; echo "$CL" | sed 's/^/ /'; } + +# (b) include!-ed files, resolved against the including file +INC="" +while IFS= read -r d; do + [ -d "$d" ] || continue + while IFS=: read -r f _ rest; do + rel="$(grep -o 'include[a-z_]*!("[^"]*")' <<<"$rest" | sed 's/.*("\(.*\)")/\1/')" + for r in $rel; do + case "$r" in /*) continue ;; esac + INC+="$(realpath -m --relative-to="$ROOT" "$(dirname "$f")/$r")"$'\n' + done + done < <(grep -rn 'include[a-z_]*!(' "$d" --include='*.rs' 2>/dev/null) +done <<<"$CL" +INC="$(echo "$INC" | sed '/^$/d' | sort -u)" +[ $SHOWCL = 1 ] && { echo "include-d files:"; echo "$INC" | sed 's/^/ /'; } + +yes=(); +while IFS= read -r f; do + [ -n "$f" ] || continue + reason="" + case "$f" in + Cargo.lock|Cargo.toml|rust-toolchain.toml|flake.nix|flake.lock) reason="fixed input" ;; + e2e/*) reason="e2e harness / guest" ;; + */build.rs) reason="build script" ;; + komorebi-for-kde/*|komorebi-for-mac/*) ;; # separate trees, not in the Windows closure + *.md|docs/*|tools/*|.github/*) ;; # docs and dev tools (include!-ed docs are caught below) + esac + if [ -z "$reason" ]; then + while IFS= read -r d; do + case "$f" in "$d"/*) reason="in closure crate $d"; break ;; esac + done <<<"$CL" + fi + if [ -z "$reason" ]; then + while IFS= read -r i; do + [ -n "$i" ] || continue + case "$f" in "$i"|"$i"/*) reason="include-d by a closure crate"; break ;; esac + done <<<"$INC" + fi + if [ -z "$reason" ]; then + case "$f" in + komorebi-for-kde/*|komorebi-for-mac/*|*.md|docs/*|tools/*|.github/*) ;; + komorebi-bar/*|komorebi-gui/*|komorebi-shortcuts/*|komorebic-no-console/*|crates/komorebi-bar-core/*|schema*.json|komorebic.lib.ahk|wix/*|justfile|mkdocs.yml|deny.toml|rustfmt.toml|*.json) + # known Windows-tree paths outside the closure (crates not in the closure were checked above) + case "$f" in */*.json|*.json) [ "$f" = dependencies.json ] || [ "${f#schema}" != "$f" ] || reason="json file outside known oracle files: treated as needed" ;; esac ;; + *) reason="not understood: treated as needed" ;; + esac + fi + [ -n "$reason" ] && yes+=("$f ($reason)") +done <<<"$FILES" +if [ ${#yes[@]} -eq 0 ]; then + echo "NO: none of $(echo "$FILES" | wc -l) touched files is an input of komorebi.exe, komorebic.exe or komorebi-testwin.exe" +else + echo "YES: ${#yes[@]} touched file(s) are inputs of the e2e binaries or the harness:" + printf ' %s\n' "${yes[@]}" | head -15 + [ ${#yes[@]} -gt 15 ] && echo " ... and $(( ${#yes[@]} - 15 )) more" +fi diff --git a/tools/kde-closure-check b/tools/kde-closure-check new file mode 100755 index 00000000..87ec0d1b --- /dev/null +++ b/tools/kde-closure-check @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# Fails if the crates outside komorebi-for-kde that the KDE packages depend on differ from the list the KDE +# source filter uses (komorebi-for-kde/nix/root-crates.json). +# Usage: tools/kde-closure-check [REPO_ROOT] (default: the repository this script is in) +# Works for the merged workspace (one root Cargo.toml) and for the old KDE workspace. +set -euo pipefail +root=$(cd "${1:-$(dirname "$0")/..}" && pwd) +[ -d "$root/komorebi-for-kde" ] || root=$(cd "$root/.." && pwd) +want=$(jq -r '.[]' "$root/komorebi-for-kde/nix/root-crates.json" | sort) +if [ -f "$root/komorebi-for-kde/Cargo.toml" ]; then + have=$(cd "$root/komorebi-for-kde" && nice -n 19 cargo metadata --offline --format-version 1 \ + | jq -r --arg r "$root/" '.packages[] | select(.source == null) | .manifest_path + | select(startswith($r) and (startswith($r + "komorebi-for-kde/") | not)) + | ltrimstr($r) | sub("/Cargo.toml$"; "")' | sort) +else + # merged workspace: the closure of the KDE packages on a Linux target + have=$(cd "$root" && for p in komorebi-linux komorebic-linux komorebi-client-linux komorebi-hotkeys; do + nice -n 19 cargo tree --offline --locked -p "$p" --target x86_64-unknown-linux-gnu --prefix none -e normal,build,dev 2>/dev/null + done | grep -o "($root/[^)]*)" | tr -d '()' | sed "s#^$root/##" | grep -v '^komorebi-for-kde' | sort -u) +fi +if [ "$want" != "$have" ]; then + echo "KDE source filter and cargo closure differ" >&2 + diff <(echo "$want") <(echo "$have") | sed 's/^/ only in cargo closure: /' >&2 + exit 1 +fi +echo "ok: $(echo "$want" | wc -l) root crates match the KDE cargo closure"