diff mbox

[5/8] scripts/clean-includes: Add --all option

Message ID 1455818725-7647-6-git-send-email-peter.maydell@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Peter Maydell Feb. 18, 2016, 6:05 p.m. UTC
Add a --all option which will run the script on every C
source and header file in the repository (except for those
in a few directories which contain standalone guest code).

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 scripts/clean-includes | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

Eric Blake Feb. 18, 2016, 7:09 p.m. UTC | #1
On 02/18/2016 11:05 AM, Peter Maydell wrote:
> Add a --all option which will run the script on every C
> source and header file in the repository (except for those
> in a few directories which contain standalone guest code).
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  scripts/clean-includes | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 

> +# Regular expression defining files to ignore when using --all

s/Regular/Extended regular/, to make it obvious which flavor we are
using? (But yes to ERE; it's a pain to write \(..\|..\) in BRE).

> +XDIRREGEX='^(tests/tcg|tests/multiboot|pc-bios|disas/libvixl)'
> +
>  if [ $# -ne 0 ] && [ "$1" = "--git" ]; then

>  
> +if [ "$1" = "--all" ]; then
> +    # We assume there are no files in the tree with spaces in their name
> +    set -- $(git ls-files '*.[ch]' | egrep -v "$XDIRREGEX")

'grep -E' is slightly more portable than 'egrep'.

We could perhaps patch checkpatch.pl to enforce that no new files with
stupid names are checked in...

Reviewed-by: Eric Blake <eblake@redhat.com>
diff mbox

Patch

diff --git a/scripts/clean-includes b/scripts/clean-includes
index 737a5ce..6acf120 100755
--- a/scripts/clean-includes
+++ b/scripts/clean-includes
@@ -15,11 +15,17 @@ 
 
 # Usage:
 #   clean-includes [--git subjectprefix] file ...
+# or
+#   clean-includes [--git subjectprefix] --all
 #
 # If the --git subjectprefix option is given, then after making
 # the changes to the files this script will create a git commit
 # with the subject line "subjectprefix: Clean up includes"
 # and a boilerplate commit message.
+#
+# Using --all will cause clean-includes to run on the whole source
+# tree (excluding certain directories which are known not to need
+# handling).
 
 # This script requires Coccinelle to be installed.
 
@@ -40,6 +46,9 @@ 
 
 GIT=no
 
+# Regular expression defining files to ignore when using --all
+XDIRREGEX='^(tests/tcg|tests/multiboot|pc-bios|disas/libvixl)'
+
 if [ $# -ne 0 ] && [ "$1" = "--git" ]; then
     if [ $# -eq 1 ]; then
         echo "--git option requires an argument"
@@ -52,11 +61,16 @@  if [ $# -ne 0 ] && [ "$1" = "--git" ]; then
 fi
 
 if [ $# -eq 0 ]; then
-    echo "Usage: clean-includes [--git subjectprefix] foo.c ..."
+    echo "Usage: clean-includes [--git subjectprefix] [--all | foo.c ...]"
     echo "(modifies the files in place)"
     exit 1
 fi
 
+if [ "$1" = "--all" ]; then
+    # We assume there are no files in the tree with spaces in their name
+    set -- $(git ls-files '*.[ch]' | egrep -v "$XDIRREGEX")
+fi
+
 # 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.