Skip to content

tools/kernel-pr-check: a --build one level above the kernel tree no longer deletes it - #287

Merged
derekross merged 2 commits into
derekross:mainfrom
only21mil:build/c041-kernel-check-scratch
Nov 3, 2026
Merged

derekross merged 2 commits into
derekross:mainfrom
only21mil:build/c041-kernel-check-scratch

Conversation

@only21mil

Copy link
Copy Markdown
Contributor

What and why

tools/kernel-pr-check --build OUT clears OUT/src and OUT/src-base before it exports the commits it builds. The only check was that OUT is not inside the kernel tree. So -C /x/src --build /x passed, and the build step's rm -rf OUT/src deleted the checkout the tool promises never to touch. An OUT/src that holds a worktree's git directory went the same way, and a symlink at OUT/build into the tree had make build in the tree and the device-tree step delete its arch/arm64/boot/dts.

The tool now resolves every path the builds delete or rewrite, symlinks included: OUT/src, OUT/src-base, OUT/build, OUT/build-base and the stale outputs it removes inside the build directories. It refuses (exit 2) an OUT where any of them is the tree or its git directory, holds it or lies inside it. The guard and the deletes share one list, so a new delete can't slip past the check. The tree's path is resolved physically too. An OUT beside the tree, or one that holds the tree under another name (--build ~/omamobile-kernel with -C ~/omamobile-kernel/linux), still builds as before.

Two small cleanups come with it: the header now says where the builds go, and --help prints the whole header (it stopped a line short).

tests/kernel-pr-check covers four layouts: OUT holding a tree named src, OUT/build linking to the tree, OUT/build/arch linking into it, and OUT/src holding a worktree's git directory. The tool runs with stub clang and ld.lld, so it would reach the builds. Its rm is a stand-in that records anything under the fixtures it is asked to delete and deletes none of it, so a regression reports the deletion instead of making it. Run against the old tool, the test fails with not ok - OUT holds a tree named src: deleted …/collide/src, and the fixture tree is still there.

Not in this change: the tool still clears whatever sits at OUT/src and OUT/src-base when that is not the kernel tree. That is what --build has always done with its output directory, and an ownership marker would change behaviour for existing output directories, CI's included. It also doesn't police symlinks a user puts deeper inside OUT/build, beyond the paths it deletes.

Device and build

  • Phone: none: tools only (tools/kernel-pr-check runs on the laptop and in CI, never on a phone; CONTRIBUTING §6.5)
  • Kernel release (uname -r): n/a
  • Packages changed, with versions: none

Checks (no phone needed)

  • tools/pr-check passes (against the branch point, af8c0f0)
  • tests/all passes
  • tests/packages passes (or the packages I touched: ...): no package touched
  • Each changed package has its version bumped, and the new version is in the commit subject: no package changed
  • Commits have area prefixes and bodies that say why; any AI help is a Co-Authored-By: or Assisted-by: trailer, never a Signed-off-by:

On the phone

  • I ran this on my own phone, booted into this build: not applicable, a laptop-side checker
  • Runbook steps passed (plan, step, result): none; no plan step
  • What I did not test: a real kernel build with --build. The tests use a stand-in tree, stub compilers and a recording rm, by design, so nothing real is deleted.
  • Nothing in this change writes outside slot B and userdata, weakens the storage guard, or reads registers from userspace (AGENTS.md §1)

Found by Terra 6.1 Max and Sol 6.1 xhigh in a code audit of the repository.

Generated with Claude Opus 5.5 and GPT-6.1 Sol in T3 Code Nightly

…deletes

The builds delete and rewrite OUT/src, OUT/src-base, OUT/build and
OUT/build-base, but --build was only refused inside the kernel tree. An
OUT one level above a tree named src (-C /x/src --build /x) passed, and
the builds' rm -rf of OUT/src deleted the checkout the tool promises
never to touch. An OUT/src that holds a worktree's git directory went
the same way, and a symlink at OUT/build into the tree had make build in
the tree and the device-tree step delete its arch/arm64/boot/dts.

Resolve every directory the builds delete or rewrite, symlinks included,
and refuse an OUT where one of them is the tree or its git directory,
holds it or lies inside it. The tree's own path is now resolved
physically too, so a symlinked -C is compared by what it points at. An
OUT beside the tree, or holding a tree under another name, still builds.
The guard and the deletes share one list of what is deleted, so a new
delete can't slip past it. The header says where the builds go, and
--help now prints all of it (it stopped a line short before).

tests/kernel-pr-check covers these layouts, and a symlink deeper in
OUT/build, with an rm that records what it is asked to delete under the
fixtures and deletes none of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derekross

Copy link
Copy Markdown
Owner

Thanks: a guard that resolves every path the build deletes, symlinks included, and that shares one list with the deletes is the right shape. I checked it three ways:

  • tests/kernel-pr-check passes in a container with no network.
  • Against a real kernel tree, mounted read-only, -C /x/src --build /x is refused: "overlaps the kernel tree /x/src … exit 2".
  • The layout in our review docs (-C /linux --build /out) still passes and goes on to the builds.

One thing to know: #288 also edits the header and the --help range. The two merge cleanly as text, but together the header grows by two lines, and sed -n '3,37p' cuts its last line again. Whichever of the two merges second needs 3,38p. Better, work the range out from the file (print up to the first line that isn't a comment), so the next header edit can't break it again. I'm happy to do that at merge.

Minor, no change needed: inside a container where git refuses the tree as "dubious ownership", the git-directory half of the check finds nothing and quietly skips. The tree half still applies, and our documented container command sets safe.directory.

@derekross

Copy link
Copy Markdown
Owner

Thanks for the reply, and for holding further PRs. Here's where the batch stands against today's main, which has changed a lot in the last few hours (the kernel publishing rewrite, release-key signing and the pinned toolchain):

No need to rebase anything.

@derekross

Copy link
Copy Markdown
Owner

Thanks again. Since my last note, #310 has landed on main. It adds --no-checkpatch and --strict-trailers to kernel-pr-check and grows the header, so this branch now conflicts on one line: the --help case. I resolved it locally by keeping main's two options. With your extra header line, the header now ends at line 46, so the range needs to be 3,46p. If #288 merges too, it needs 3,47p. On that merged tree tests/kernel-pr-check passes, 18 checks, main's new trailer tests included.

tools/publish-kernel doesn't use --build, so this change can't affect publishing. I'll resolve the conflict at merge, unless you'd rather rebase. If you do, working the range out from the file would end this for good.

derekross added a commit to only21mil/omarchy-mobile that referenced this pull request Nov 3, 2026
…tions, --help 3,49p; tests: main's --no-checkpatch and trailer tests before the checker tests)
@derekross
derekross merged commit 0894511 into derekross:main Nov 3, 2026
2 checks passed
derekross added a commit to only21mil/omarchy-mobile that referenced this pull request Nov 3, 2026
@only21mil

only21mil commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Note

🤖 Opus 5.5 replying on behalf of Victor.

Thanks for resolving the conflicts here. As you suggested, #529 works the --help range out from the file: it prints from line 3 up to the first non-comment line, using the same range-selection predicate as tools/nv-backup without its # stripping. The output is byte for byte what 3,49p prints today, and a new check in tests/kernel-pr-check adds a header line to a copy of the tool and confirms --help still ends at the header’s last line. Fourteen other tools use the same hard-coded pattern; #529 lists them, and a shared helper for those could follow in a separate PR if you’d like.

derekross pushed a commit that referenced this pull request Nov 9, 2026
--help printed a hard-coded line range of the header comment, so every
change to the header had to move the range by hand: #287 and #288 each
added a header line and both set it to '3,37p', and with #310 on main
the merged ranges became '3,46p' and '3,47p'. Whichever change missed
the update cut the header's last line. On #287 the maintainer suggested
working the range out from the file instead.

--help now prints from line 3 to the first line that isn't a comment,
with the awk line tools/nv-backup and tools/phone-provision already use
(without their "# " stripping, so the output keeps its current form).
On today's header its output is byte for byte what '3,49p' printed.

tests/kernel-pr-check gains a check that runs --help on a copy of the
tool with one more header line, and compares it with the header up to
the line before `set -uo pipefail`. It failed with the old range (the
last header line was missing) and passes with this change.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
derekross added a commit that referenced this pull request Nov 9, 2026
Fourteen tools printed --help as a hard-coded line range of their
header comment (sed -n '3,NNp'), the pattern that cut kernel-pr-check's
header after #287, #288 and #310 each edited it. On #287 the maintainer
suggested working the range out from the file; #529 did that for
kernel-pr-check alone. This moves all of them onto one helper,
tools/lib/usage.sh: usage_from_header prints the comment lines from
line 3 up to the first line that isn't a comment (#529's awk line), with
"# " taken off or, with --raw, kept. Tools load it only for --help, so
the copies the tests make of a tool, with only the lib files it needs,
still run. kernel-pr-check moves onto it too.

Ten tools print byte for byte what they printed before (cmp of stdout,
stderr and exit status, and of phone-demo's and phone-mirror's error
usage). Five ranges were already wrong, and print the header now:
fetch-toolchain and build-flame-probe printed two lines of code after
it; install-phone cut --reinstall, --unsigned and its last paragraph,
build-rootfs cut --channel, and release cut its check-bundle stage.
build-packages, phone-demo and release print only the start of a longer
header, so the helper takes a paragraph count (a bare "#" line ends
one) and their output stays what the range meant.

install-phone keeps the awk line inline, as nv-backup and
phone-provision already do: make-bundle ships these three alone,
without tools/lib (review lesson L-497).

tests/tools-help fails if any tool still hard-codes the range, and runs
--help on every tool that prints its header (the helper's users and the
three inline ones): it must print the header, or whole paragraphs from
its start, and no code, and a copy whose header has grown by a line
must print that line too. It replaces #529's single-tool check in
tests/kernel-pr-check. On the base it fails on the range check, and the
per-tool check fails for 13 of the 15 tools.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Derek Ross <derekross@gmail.com>
chillerno1 added a commit to chillerno1/omarchy-mobile that referenced this pull request Nov 12, 2026
tests/tools-help refuses a hard-coded line range for a tool's help
(derekross#287): this one still had sed -n '3,12p', the only one left, and the
test failed on it. Use usage_from_header like every other tool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…onger deletes it (derekross#287)

…deletes

The builds delete and rewrite OUT/src, OUT/src-base, OUT/build and
OUT/build-base, but --build was only refused inside the kernel tree. An
OUT one level above a tree named src (-C /x/src --build /x) passed, and
the builds' rm -rf of OUT/src deleted the checkout the tool promises
never to touch. An OUT/src that holds a worktree's git directory went
the same way, and a symlink at OUT/build into the tree had make build in
the tree and the device-tree step delete its arch/arm64/boot/dts.

Resolve every directory the builds delete or rewrite, symlinks included,
and refuse an OUT where one of them is the tree or its git directory,
holds it or lies inside it. The tree's own path is now resolved
physically too, so a symlinked -C is compared by what it points at. An
OUT beside the tree, or holding a tree under another name, still builds.
The guard and the deletes share one list of what is deleted, so a new
delete can't slip past it. The header says where the builds go, and
--help now prints all of it (it stopped a line short before).

tests/kernel-pr-check covers these layouts, and a symlink deeper in
OUT/build, with an rm that records what it is asked to delete under the
fixtures and deletes none of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…ross#529)

--help printed a hard-coded line range of the header comment, so every
change to the header had to move the range by hand: derekross#287 and derekross#288 each
added a header line and both set it to '3,37p', and with derekross#310 on main
the merged ranges became '3,46p' and '3,47p'. Whichever change missed
the update cut the header's last line. On derekross#287 the maintainer suggested
working the range out from the file instead.

--help now prints from line 3 to the first line that isn't a comment,
with the awk line tools/nv-backup and tools/phone-provision already use
(without their "# " stripping, so the output keeps its current form).
On today's header its output is byte for byte what '3,49p' printed.

tests/kernel-pr-check gains a check that runs --help on a copy of the
tool with one more header line, and compares it with the header up to
the line before `set -uo pipefail`. It failed with the old range (the
last header line was missing) and passes with this change.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…ekross#559)

Fourteen tools printed --help as a hard-coded line range of their
header comment (sed -n '3,NNp'), the pattern that cut kernel-pr-check's
header after derekross#287, derekross#288 and derekross#310 each edited it. On derekross#287 the maintainer
suggested working the range out from the file; derekross#529 did that for
kernel-pr-check alone. This moves all of them onto one helper,
tools/lib/usage.sh: usage_from_header prints the comment lines from
line 3 up to the first line that isn't a comment (derekross#529's awk line), with
"# " taken off or, with --raw, kept. Tools load it only for --help, so
the copies the tests make of a tool, with only the lib files it needs,
still run. kernel-pr-check moves onto it too.

Ten tools print byte for byte what they printed before (cmp of stdout,
stderr and exit status, and of phone-demo's and phone-mirror's error
usage). Five ranges were already wrong, and print the header now:
fetch-toolchain and build-flame-probe printed two lines of code after
it; install-phone cut --reinstall, --unsigned and its last paragraph,
build-rootfs cut --channel, and release cut its check-bundle stage.
build-packages, phone-demo and release print only the start of a longer
header, so the helper takes a paragraph count (a bare "#" line ends
one) and their output stays what the range meant.

install-phone keeps the awk line inline, as nv-backup and
phone-provision already do: make-bundle ships these three alone,
without tools/lib (review lesson L-497).

tests/tools-help fails if any tool still hard-codes the range, and runs
--help on every tool that prints its header (the helper's users and the
three inline ones): it must print the header, or whole paragraphs from
its start, and no code, and a copy whose header has grown by a line
must print that line too. It replaces derekross#529's single-tool check in
tests/kernel-pr-check. On the base it fails on the range check, and the
per-tool check fails for 13 of the 15 tools.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Derek Ross <derekross@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants