scripts/clean-includes: Misc improvements
v2 cover scripts/clean-includes: Misc improvements
This is v2 of a series I sent last year:
https://patchew.org/QEMU/[email protected]/
which make clean-includes a bit easier to use and maintain, and update the exclude list.
All these patches have been reviewed except patch 5; the change there is to make the command line given in the generated git commit message properly shell-quote the arguments.
I also have some patches which I have produced by running this updated script, but I'll post those separately. The exclude list as updated by this series is enough to make all the changes the script suggests be correct ones, with the possible exception of hw/virtio/cbor-helpers.c, where I'm waiting to find out if we should make the change or put it on the exclude list.
thanks
-- PMM
Peter Maydell (6):
scripts/clean-includes: Allow directories on command line scripts/clean-includes: Remove outdated comment scripts/clean-includes: Make ignore-regexes one per line scripts/clean-includes: Do all our exclusions with REGEXFILE scripts/clean-includes: Give the args in git commit messages scripts/clean-includes: Update exclude list
scripts/clean-includes | 105 +++++++++++++++++++++++++++++------------ 1 file changed, 74 insertions(+), 31 deletions(-)
Signature · 1 line
2.47.3
PATCH v2 1/6 scripts/clean-includes: Allow directories on command line
Currently clean-includes supports two ways of specifying files to check:
* --all to run on everything
* specific files
There's no way to say "check everything in target/arm".
Add support for handling directory names, by always running the arguments through git ls-files.
--- scripts/clean-includes | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
scripts/clean-includes +8 -4
@@ -14,7 +14,7 @@ # the top-level directory. # Usage: -# clean-includes [--git subjectprefix] [--check-dup-head] file ... +# clean-includes [--git subjectprefix] [--check-dup-head] file-or-dir ... # or # clean-includes [--git subjectprefix] [--check-dup-head] --all #
@@ -28,7 +28,8 @@ # # Using --all will cause clean-includes to run on the whole source # tree (excluding certain directories which are known not to need -# handling). +# handling). This is equivalent to passing '.' as the directory to +# scan. # This script requires Coccinelle to be installed.
@@ -86,11 +87,14 @@ if [ $# -eq 0 ]; then exit 1 fi +# --all means "scan everything starting from the current directory" if [ "$1" = "--all" ]; then - # We assume there are no files in the tree with spaces in their name - set -- $(git ls-files '*.[ch]' | grep -E -v "$XDIRREGEX") + set -- '.' fi +# We assume there are no files in the tree with spaces in their name +set -- $(git ls-files "$@" | grep '\.[ch]$' | grep -E -v "$XDIRREGEX") + # Annoyingly coccinelle won't read a scriptfile unless its # name ends '.cocci', so write it out to a tempfile with the # right kind of name.
Signature · 1 line
2.47.3
PATCH v2 2/6 scripts/clean-includes: Remove outdated comment
In reply to Peter MaydellRemove an old comment suggesting a manual shell line to use to find files to run the script on. The script's exclude-list and its support for directory names make this irrelevant.
--- scripts/clean-includes | 9 --------- 1 file changed, 9 deletions(-)
scripts/clean-includes +0 -9
@@ -39,15 +39,6 @@ # removed. # Other files (including C++ and ObjectiveC) can't be handled by this script. -# The following one-liner may be handy for finding files to run this on. -# However some caution is required regarding files that might be part -# of the guest agent or standalone tests. - -# for i in $(git ls-tree --name-only HEAD) ; do test -f $i && \ -# grep -E '^# *include' $i | head -1 | grep 'osdep.h' ; test $? != 0 && \ -# echo $i ; done - - GIT=no DUPHEAD=no
Signature · 1 line
2.47.3
PATCH v2 3/6 scripts/clean-includes: Make ignore-regexes one per line
In reply to Peter MaydellCurrently we have a single extended regular expression defining files that clean-includes should ignore. This is now very long and awkward to read and edit.
Switch to having a list of newline-separated EREs that we write to a file for grep's -f option, so we can express them more legibly in the shell script. We allow for comments in the regex list, which lets us document why we have put the exclusions in.
--- scripts/clean-includes | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-)
scripts/clean-includes +22 -6
@@ -42,8 +42,6 @@ GIT=no DUPHEAD=no -# Extended regular expression defining files to ignore when using --all -XDIRREGEX='^(tests/tcg|tests/multiboot|tests/fp|tests/plugin|tests/uefi-test-tools|pc-bios|subprojects|contrib/plugins|tools/ebpf|ebpf/rss.bpf.skeleton.h|linux-user/(mips64|x86_64)/(cpu_loop|signal).c)' while true do
@@ -83,15 +81,33 @@ if [ "$1" = "--all" ]; then set -- '.' fi -# We assume there are no files in the tree with spaces in their name -set -- $(git ls-files "$@" | grep '\.[ch]$' | grep -E -v "$XDIRREGEX") - # Annoyingly coccinelle won't read a scriptfile unless its # name ends '.cocci', so write it out to a tempfile with the # right kind of name. COCCIFILE="$(mktemp --suffix=.cocci)" +REGEXFILE="$(mktemp --suffix=.regex)" + +trap 'rm -f -- "$COCCIFILE" "$REGEXFILE"' INT TERM HUP EXIT + +# List of extended regular expressions defining files to ignore +# Comments starting with '#' are permitted +grep -v '^#' >"$REGEXFILE" <<EOT +# These tests are generally standalone binaries +^tests/(tcg|multiboot|fp|plugin|uefi-test-tools) +# BIOS sources and third-party subprojects don't follow our rules +^pc-bios +^subprojects +# plugin binaries are standalone +^contrib/plugins +# the ebpf tool is standalone, and the skeleton header is autogenerated +^tools/ebpf +^ebpf/rss.bpf.skeleton.h +# These files just include some other .c file and have no content themselves +^linux-user/(mips64|x86_64)/(cpu_loop|signal).c +EOT -trap 'rm -f -- "$COCCIFILE"' INT TERM HUP EXIT +# We assume there are no files in the tree with spaces in their name +set -- $(git ls-files "$@" | grep '\.[ch]$' | grep -E -v -f "$REGEXFILE") cat >"$COCCIFILE" <<EOT @@
Signature · 1 line
2.47.3
PATCH v2 4/6 scripts/clean-includes: Do all our exclusions with REGEXFILE
In reply to Peter MaydellWe currently have two mechanisms for excluding files:
* the REGEXFILE which excludes by regex
* special cases in the "loop over each file" which make us skip the file
Roll all the "skip this" cases into REGEXFILE, so we use a single mechanism for identifying which files to exclude.
--- scripts/clean-includes | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-)
scripts/clean-includes +9 -15
@@ -104,6 +104,15 @@ grep -v '^#' >"$REGEXFILE" <<EOT ^ebpf/rss.bpf.skeleton.h # These files just include some other .c file and have no content themselves ^linux-user/(mips64|x86_64)/(cpu_loop|signal).c +# These are autogenerated headers +^include/standard-headers/ +# osdep.h itself and its friends are expected to include system headers +^include/qemu/osdep.h +^include/qemu/compiler.h +^include/glib-compat.h +^include/system/os-(posix|win32).h +# This is for use by plugins, which are standalone binaries +^include/qemu/qemu-plugin.h EOT # We assume there are no files in the tree with spaces in their name
@@ -137,21 +146,6 @@ for f in "$@"; do *.c) MODE=c ;; - *include/qemu/osdep.h | \ - *include/qemu/compiler.h | \ - *include/qemu/qemu-plugin.h | \ - *include/glib-compat.h | \ - *include/system/os-posix.h | \ - *include/system/os-win32.h | \ - *include/standard-headers/ ) - # Removing include lines from osdep.h itself would be counterproductive. - echo "SKIPPING $f (special case header)" - continue - ;; - *include/standard-headers/*) - echo "SKIPPING $f (autogenerated header)" - continue - ;; *.h) MODE=h ;;
Signature · 1 line
2.47.3
PATCH v2 5/6 scripts/clean-includes: Give the args in git commit messages
In reply to Peter MaydellIf clean-includes is creating a git commit for its changes, currently it says only "created with scripts/clean-includes". Add the command line arguments the user passed us, as useful extra information.
--- scripts/clean-includes | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
scripts/clean-includes +24 -1
@@ -42,6 +42,28 @@ GIT=no DUPHEAD=no +# Save the original arguments in case we want to put them in +# a git commit message, quoted for the shell so that we handle +# args with spaces/metacharacters correctly. +# The quote_sh() function is the same one we use in configure. + +quote_sh() { + for arg in "$@"; do + printf "%s" "$arg" | sed "s,','\\\\'',g; s,.*,'&'," + done +} + +quote_args() { + while [ $# -gt 0 ]; do + printf "%s" "$(quote_sh "$1")" + shift + if [ $# -gt 0 ]; then + printf " " + fi + done +} + +QUOTEDARGS="$(quote_args "$@")" while true do
@@ -198,7 +220,8 @@ if [ "$GIT" = "yes" ]; then git commit --signoff -F - <<EOF $GITSUBJ: Clean up includes -This commit was created with scripts/clean-includes. +This commit was created with scripts/clean-includes: + ./scripts/clean-includes $QUOTEDARGS All .c should include qemu/osdep.h first. The script performs three related cleanups:
Signature · 1 line
2.47.3
Re: [PATCH v2 5/6] scripts/clean-includes: Give the args in git commit messages
Quoted 15 lines · Peter Maydell
If clean-includes is creating a git commit for its changes, currently it says only "created with
scripts/clean-includes". Add the command line arguments the user passed us, as useful extra information.Signed-off-by Peter Maydell <[email protected]>--- scripts/clean-includes | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)scripts/clean-includes +0
-0
scripts/clean-includes line 48
Quoted 7 lines
scripts/clean-includes +4
-0@@ -42,6 +42,28 @@ GIT=no DUPHEAD=no +# Save the original arguments in case we want to put them in +# a git commit message, quoted for the shell so that we handle +# args with spaces/metacharacters correctly. +# The quote_sh() function is the same one we use in configure.
Not quite, configure's is
quote_sh() {
printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&',"
}scripts/clean-includes line 54
Quoted 6 lines
scripts/clean-includes +6
-0+ +quote_sh() { + for arg in "$@"; do + printf "%s" "$arg" | sed "s,','\\\\'',g; s,.*,'&'," + done +}
Is the loop intentional? We seem to always call the function with exactly one argument.
Quoted 25 lines
scripts/clean-includes +14
-1+ +quote_args() { + while [ $# -gt 0 ]; do + printf "%s" "$(quote_sh "$1")" + shift + if [ $# -gt 0 ]; then + printf " " + fi + done +} + +QUOTEDARGS="$(quote_args "$@")" while true do@@ -198,7 +220,8 @@ if [ "$GIT" = "yes" ]; then git commit --signoff -F - <<EOF $GITSUBJ: Clean up includes -This commit was created with scripts/clean-includes. +This commit was created with scripts/clean-includes: + ./scripts/clean-includes $QUOTEDARGS All .c should include qemu/osdep.h first. The script performs three related cleanups:
Re: [PATCH v2 5/6] scripts/clean-includes: Give the args in git commit messages
Quoted 32 lines · Markus Armbruster
Quoted 15 lines · Peter Maydell
If clean-includes is creating a git commit for its changes, currently it says only "created with
scripts/clean-includes". Add the command line arguments the user passed us, as useful extra information.Signed-off-by Peter Maydell <[email protected]>--- scripts/clean-includes | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)scripts/clean-includes +0
-0scripts/clean-includes line 48
Quoted 7 lines
scripts/clean-includes +4
-0@@ -42,6 +42,28 @@ GIT=no DUPHEAD=no +# Save the original arguments in case we want to put them in +# a git commit message, quoted for the shell so that we handle +# args with spaces/metacharacters correctly. +# The quote_sh() function is the same one we use in configure.Not quite, configure's is
quote_sh() { printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&'," }
Quoted 9 lines
scripts/clean-includes line 54
Quoted 6 lines
scripts/clean-includes +6
-0+ +quote_sh() { + for arg in "$@"; do + printf "%s" "$arg" | sed "s,','\\\\'',g; s,.*,'&'," + done +}Is the loop intentional? We seem to always call the function with exactly one argument.
Whoops, no -- I was iterating around trying to get something working and didn't notice that I'd left that loop in place. The quote_sh() function should match the configure one.
-- PMM
Markus Armbruster
Reviewed-byRe: [PATCH v2 5/6] scripts/clean-includes: Give the args in git commit messages
Quoted 43 lines · Peter Maydell
Quoted 32 lines · Markus Armbruster
Quoted 15 lines · Peter Maydell
If clean-includes is creating a git commit for its changes, currently it says only "created with
scripts/clean-includes". Add the command line arguments the user passed us, as useful extra information.Signed-off-by Peter Maydell <[email protected]>--- scripts/clean-includes | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)scripts/clean-includes +0
-0scripts/clean-includes line 48
Quoted 7 lines
scripts/clean-includes +4
-0@@ -42,6 +42,28 @@ GIT=no DUPHEAD=no +# Save the original arguments in case we want to put them in +# a git commit message, quoted for the shell so that we handle +# args with spaces/metacharacters correctly. +# The quote_sh() function is the same one we use in configure.Not quite, configure's is
quote_sh() { printf "%s" "$1" | sed "s,','\\\\'',g; s,.*,'&'," }Quoted 9 lines
scripts/clean-includes line 54
Quoted 6 lines
scripts/clean-includes +6
-0+ +quote_sh() { + for arg in "$@"; do + printf "%s" "$arg" | sed "s,','\\\\'',g; s,.*,'&'," + done +}Is the loop intentional? We seem to always call the function with exactly one argument.
Quoted 3 lines
Whoops, no -- I was iterating around trying to get something working and didn't notice that I'd left that loop in place. The
quote_sh()function should match the configure one.
Got it.
With that
PATCH v2 6/6 scripts/clean-includes: Update exclude list
In reply to Peter MaydellRemove from the exclude list:
* tests/plugin, which is a non-existent directory. This was probably intended to exclude tests/tcg/plugins/, which is caught by the tests/tcg exclude pattern anyway
Add to the exclude list:
* rust/ -- the headers in here are purely for input to bindgen
* target/hexagon has some standalone tools used at build time
* linux-user/gen-vsdo.c -- another standalone tool
* linux-user/mips64/elfload.c just includes mips/elfload.c
* scripts/xen-detect.c is feature-detection code used by meson.build
* tests/tracetool/simple.c is autogenerated
* tests/unit/ has some "C file just includes another one" files
* include/system/os-wasm.h is like os-posix.h and os-win32.h and shouldn't be adjusted
--- scripts/clean-includes | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
scripts/clean-includes +17 -2
@@ -115,10 +115,12 @@ trap 'rm -f -- "$COCCIFILE" "$REGEXFILE"' INT TERM HUP EXIT # Comments starting with '#' are permitted grep -v '^#' >"$REGEXFILE" <<EOT # These tests are generally standalone binaries -^tests/(tcg|multiboot|fp|plugin|uefi-test-tools) +^tests/(tcg|multiboot|fp|uefi-test-tools|qtest/migration/s390x) # BIOS sources and third-party subprojects don't follow our rules ^pc-bios ^subprojects +# headers under rust are only used for input to bindgen +^rust # plugin binaries are standalone ^contrib/plugins # the ebpf tool is standalone, and the skeleton header is autogenerated
@@ -126,15 +128,28 @@ grep -v '^#' >"$REGEXFILE" <<EOT ^ebpf/rss.bpf.skeleton.h # These files just include some other .c file and have no content themselves ^linux-user/(mips64|x86_64)/(cpu_loop|signal).c +^linux-user/mips64/elfload.c # These are autogenerated headers ^include/standard-headers/ # osdep.h itself and its friends are expected to include system headers ^include/qemu/osdep.h ^include/qemu/compiler.h ^include/glib-compat.h -^include/system/os-(posix|win32).h +^include/system/os-(posix|win32|wasm).h # This is for use by plugins, which are standalone binaries ^include/qemu/qemu-plugin.h +# standalone tools used in building the hexagon target code +^target/hexagon/(idef-parser|gen_semantics.c|gen_dectree_import.c) +# standalone tool +^target/s390x/gen-features.c +# gen-vdso is a standalone tool +^linux-user/gen-vdso.c +# feature-detection code used by meson.bulid +^scripts/xen-detect.c +# autogenerated by tracetool +^tests/tracetool/simple.c +# these just include another C file +^tests/unit/test-rcu-(simpleq|slist|tailq).c EOT # We assume there are no files in the tree with spaces in their name
Signature · 1 line
2.47.3