From 493fd5341211b57622a56cd36f6a67de5b02b93a Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Sun, 8 Nov 2026 12:49:33 +0000 Subject: [PATCH] tools/kernel-pr-check: work the --help range out from the file --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 --- tests/kernel-pr-check | 17 ++++++++++++++--- tools/kernel-pr-check | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tests/kernel-pr-check b/tests/kernel-pr-check index 47457d38c..079588d51 100755 --- a/tests/kernel-pr-check +++ b/tests/kernel-pr-check @@ -3,15 +3,26 @@ # tools/kernel-pr-check's commit checks against a stand-in kernel tree (a # git repository with a fake scripts/checkpatch.pl): sign-offs, prefixes, # checkpatch errors and warnings, and a checker that is missing or doesn't -# run to the end. Its device-tree comparison runs against a second -# stand-in whose make prints the messages each board file asks for; the -# real builds (clang, dtc, dt-validate) need a real tree and are run by hand. +# run to the end, and --help. Its device-tree comparison runs against a +# second stand-in whose make prints the messages each board file asks for; +# the real builds (clang, dtc, dt-validate) need a real tree and are run by hand. set -euo pipefail here=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd) t=$(mktemp -d) trap 'rm -rf "$t"' EXIT fail() { echo "not ok - $*" >&2; exit 1; } +# --help prints the whole header comment and no code, from a copy whose +# header has grown by a line: a hard-coded range cut its last line after +# #287, #288 and #310 each edited the header. +h=$t/help/tools/kernel-pr-check +mkdir -p "${h%/*}" +sed '3a\# A line added to the header.' "$here/tools/kernel-pr-check" > "$h" +chmod +x "$h" +diff <("$h" --help) <(sed -n '3,/^set -uo pipefail$/p' "$h" | sed '$d') \ + || fail "--help isn't the header comment, from line 3 to the line before set -uo pipefail" +echo "ok - --help prints the whole header comment, however long it grows, and no code" + k=$t/linux mkdir -p "$k/scripts" "$k/drivers" # checkpatch's stand-in: an ERROR for any added line with "BADSTYLE", a diff --git a/tools/kernel-pr-check b/tools/kernel-pr-check index ae0613c35..47f94a0ac 100755 --- a/tools/kernel-pr-check +++ b/tools/kernel-pr-check @@ -69,7 +69,7 @@ while (($#)); do --merge) merge=1; shift ;; --no-checkpatch) checkpatch=0; shift ;; --strict-trailers) shift ;; # no longer stricter; see above - -h|--help) sed -n '3,49p' "$self"; exit 0 ;; + -h|--help) awk 'NR > 2 && !/^#/ { exit } NR > 2' "$self"; exit 0 ;; -*) echo "kernel-pr-check: unknown option $1" >&2; exit 2 ;; *) break ;; esac