diff mbox

[1/2] script/clean-includes: added duplicate #include check

Message ID 1476786796-15269-1-git-send-email-anand.indukala@gmail.com
State New
Headers show

Commit Message

Anand J Oct. 18, 2016, 10:33 a.m. UTC
Added script to check duplicate #include entries. This check will scan
and print the files in which duplicate #include entries are present.

Script might output false positive entries as well. Such entries should
not be removed. So if it finds any duplicate entries script will
terminate with an exit status 1. Then each and every file should be
checked manually and corrected if necessary.

In order to enable the check use --check-duphead option with
script/clean-includes.

Signed-off-by: Anand J <anand.indukala@gmail.com>
---
 scripts/clean-includes | 50 +++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 37 insertions(+), 13 deletions(-)

Comments

Anand J Oct. 18, 2016, 12:38 p.m. UTC | #1
On Tue, Oct 18, 2016 at 4:03 PM, Anand J <anand.indukala@gmail.com> wrote:

> Added script to check duplicate #include entries. This check will scan
> and print the files in which duplicate #include entries are present.
>
> Script might output false positive entries as well. Such entries should
> not be removed. So if it finds any duplicate entries script will
> terminate with an exit status 1. Then each and every file should be
> checked manually and corrected if necessary.
>
> In order to enable the check use --check-duphead option with
> script/clean-includes.
>
> Signed-off-by: Anand J <anand.indukala@gmail.com>
> ---
>  scripts/clean-includes | 50 ++++++++++++++++++++++++++++++
> +++++++-------------
>  1 file changed, 37 insertions(+), 13 deletions(-)
>
> diff --git a/scripts/clean-includes b/scripts/clean-includes
> index 4412a55..76dd0e4 100755
> --- a/scripts/clean-includes
> +++ b/scripts/clean-includes
> @@ -14,15 +14,18 @@
>  # the top-level directory.
>
>  # Usage:
> -#   clean-includes [--git subjectprefix] file ...
> +#   clean-includes [--git subjectprefix] [--check-duphead] file ...
>  # or
> -#   clean-includes [--git subjectprefix] --all
> +#   clean-includes [--git subjectprefix] [--check-duphead] --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.
>  #
> +# If --check-duphead option is used, then check for duplicate
> +# header files will be enabled.
> +#
>  # Using --all will cause clean-includes to run on the whole source
>  # tree (excluding certain directories which are known not to need
>  # handling).
> @@ -45,23 +48,36 @@
>
>
>  GIT=no
> +DUPHEAD=no
>
>  # Extended 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"
> -        exit 1
> -    fi
> -    GITSUBJ="$2"
> -    GIT=yes
> -    shift
> -    shift
> -fi
> +while true
> +do
> +    case $1 in
> +    "--git")
> +         if [ $# -eq 1 ]; then
> +             echo "--git option requires an argument"
> +             exit 1
> +         fi
> +         GITSUBJ="$2"
> +         GIT=yes
> +         shift
> +         shift
> +         ;;
> +    "--check-duphead")
> +        DUPHEAD=yes
> +        shift
> +        ;;
> +    *)
> +        break
> +        ;;
> +   esac
> +done
>
>  if [ $# -eq 0 ]; then
> -    echo "Usage: clean-includes [--git subjectprefix] [--all | foo.c ...]"
> +    echo "Usage: clean-includes [--git subjectprefix] [--check-duphead]
> [--all | foo.c ...]"
>      echo "(modifies the files in place)"
>      exit 1
>  fi
> @@ -154,6 +170,14 @@ for f in "$@"; do
>
>  done
>
> +if [ "$DUPHEAD" = "yes" ]; then
> +    grep "^#include" $@ | sort | uniq -c | awk '{if ($1 > 1) print $0}'
> +    if [ $? -eq 0 ]; then
> +        echo "Found duplicate header file includes. Please check the
> above files manually."
> +        exit 1
> +    fi
> +fi
> +
>  if [ "$GIT" = "yes" ]; then
>      git add -- "$@"
>      git commit --signoff -F - <<EOF
> --
> 2.7.4
>
>
Thomas Huth Oct. 20, 2016, 9:08 a.m. UTC | #2
On 18.10.2016 14:38, Anand J wrote:
> 
> 
> On Tue, Oct 18, 2016 at 4:03 PM, Anand J <anand.indukala@gmail.com
> <mailto:anand.indukala@gmail.com>> wrote:
> 
>     Added script to check duplicate #include entries. This check will scan
>     and print the files in which duplicate #include entries are present.
> 
>     Script might output false positive entries as well. Such entries should
>     not be removed. So if it finds any duplicate entries script will
>     terminate with an exit status 1. Then each and every file should be
>     checked manually and corrected if necessary.
> 
>     In order to enable the check use --check-duphead option with
>     script/clean-includes.
> 
>     Signed-off-by: Anand J <anand.indukala@gmail.com
>     <mailto:anand.indukala@gmail.com>>
>     ---
>      scripts/clean-includes | 50
>     +++++++++++++++++++++++++++++++++++++-------------
>      1 file changed, 37 insertions(+), 13 deletions(-)

Thanks for the update, this patch looks fine to me now, so feel free to
add my:

Reviewed-by: Thomas Huth <thuth@redhat.com>

But please avoid sending patches in HTML e-mails. Could you maybe please
resend the patch as plain text mail? And while you're at it, add CC: to
qemu-trivial@nongnu.org, I think the patch is simple enough to go
through the trivial tree.

 Thanks,
  Thomas
Anand J Oct. 20, 2016, 9:56 a.m. UTC | #3
send a new patch. please check http://patchwork.ozlabs.org/patch/684533/

Thanks,
Anand

On Thu, Oct 20, 2016 at 2:38 PM, Thomas Huth <thuth@redhat.com> wrote:

> On 18.10.2016 14:38, Anand J wrote:
> >
> >
> > On Tue, Oct 18, 2016 at 4:03 PM, Anand J <anand.indukala@gmail.com
> > <mailto:anand.indukala@gmail.com>> wrote:
> >
> >     Added script to check duplicate #include entries. This check will
> scan
> >     and print the files in which duplicate #include entries are present.
> >
> >     Script might output false positive entries as well. Such entries
> should
> >     not be removed. So if it finds any duplicate entries script will
> >     terminate with an exit status 1. Then each and every file should be
> >     checked manually and corrected if necessary.
> >
> >     In order to enable the check use --check-duphead option with
> >     script/clean-includes.
> >
> >     Signed-off-by: Anand J <anand.indukala@gmail.com
> >     <mailto:anand.indukala@gmail.com>>
> >     ---
> >      scripts/clean-includes | 50
> >     +++++++++++++++++++++++++++++++++++++-------------
> >      1 file changed, 37 insertions(+), 13 deletions(-)
>
> Thanks for the update, this patch looks fine to me now, so feel free to
> add my:
>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
>
> But please avoid sending patches in HTML e-mails. Could you maybe please
> resend the patch as plain text mail? And while you're at it, add CC: to
> qemu-trivial@nongnu.org, I think the patch is simple enough to go
> through the trivial tree.
>
>  Thanks,
>   Thomas
>
>
diff mbox

Patch

diff --git a/scripts/clean-includes b/scripts/clean-includes
index 4412a55..76dd0e4 100755
--- a/scripts/clean-includes
+++ b/scripts/clean-includes
@@ -14,15 +14,18 @@ 
 # the top-level directory.
 
 # Usage:
-#   clean-includes [--git subjectprefix] file ...
+#   clean-includes [--git subjectprefix] [--check-duphead] file ...
 # or
-#   clean-includes [--git subjectprefix] --all
+#   clean-includes [--git subjectprefix] [--check-duphead] --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.
 #
+# If --check-duphead option is used, then check for duplicate
+# header files will be enabled.
+#
 # Using --all will cause clean-includes to run on the whole source
 # tree (excluding certain directories which are known not to need
 # handling).
@@ -45,23 +48,36 @@ 
 
 
 GIT=no
+DUPHEAD=no
 
 # Extended 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"
-        exit 1
-    fi
-    GITSUBJ="$2"
-    GIT=yes
-    shift
-    shift
-fi
+while true
+do
+    case $1 in
+    "--git")
+         if [ $# -eq 1 ]; then
+             echo "--git option requires an argument"
+             exit 1
+         fi
+         GITSUBJ="$2"
+         GIT=yes
+         shift
+         shift
+         ;;
+    "--check-duphead")
+        DUPHEAD=yes
+        shift
+        ;;
+    *)
+        break
+        ;;
+   esac
+done
 
 if [ $# -eq 0 ]; then
-    echo "Usage: clean-includes [--git subjectprefix] [--all | foo.c ...]"
+    echo "Usage: clean-includes [--git subjectprefix] [--check-duphead] [--all | foo.c ...]"
     echo "(modifies the files in place)"
     exit 1
 fi
@@ -154,6 +170,14 @@  for f in "$@"; do
 
 done
 
+if [ "$DUPHEAD" = "yes" ]; then
+    grep "^#include" $@ | sort | uniq -c | awk '{if ($1 > 1) print $0}'
+    if [ $? -eq 0 ]; then
+        echo "Found duplicate header file includes. Please check the above files manually."
+        exit 1
+    fi
+fi
+
 if [ "$GIT" = "yes" ]; then
     git add -- "$@"
     git commit --signoff -F - <<EOF