qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

scripts/clean-includes: added duplicate #include check

Enhance the clean-includes script to optionally check for duplicate #include
entries.

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-dup-head option with
scripts/clean-includes.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Anand J <anand.indukala@gmail.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>

authored by

Anand J and committed by
Michael Tokarev
d66253e4 bdbcb547

+42 -14
+42 -14
scripts/clean-includes
··· 14 14 # the top-level directory. 15 15 16 16 # Usage: 17 - # clean-includes [--git subjectprefix] file ... 17 + # clean-includes [--git subjectprefix] [--check-dup-head] file ... 18 18 # or 19 - # clean-includes [--git subjectprefix] --all 19 + # clean-includes [--git subjectprefix] [--check-dup-head] --all 20 20 # 21 21 # If the --git subjectprefix option is given, then after making 22 22 # the changes to the files this script will create a git commit 23 23 # with the subject line "subjectprefix: Clean up includes" 24 24 # and a boilerplate commit message. 25 + # 26 + # If --check-dup-head is specified, additionally check for duplicate 27 + # header includes. 25 28 # 26 29 # Using --all will cause clean-includes to run on the whole source 27 30 # tree (excluding certain directories which are known not to need ··· 45 48 46 49 47 50 GIT=no 51 + DUPHEAD=no 48 52 49 53 # Extended regular expression defining files to ignore when using --all 50 54 XDIRREGEX='^(tests/tcg|tests/multiboot|pc-bios|disas/libvixl)' 51 55 52 - if [ $# -ne 0 ] && [ "$1" = "--git" ]; then 53 - if [ $# -eq 1 ]; then 54 - echo "--git option requires an argument" 55 - exit 1 56 - fi 57 - GITSUBJ="$2" 58 - GIT=yes 59 - shift 60 - shift 61 - fi 56 + while true 57 + do 58 + case $1 in 59 + "--git") 60 + if [ $# -eq 1 ]; then 61 + echo "--git option requires an argument" 62 + exit 1 63 + fi 64 + GITSUBJ="$2" 65 + GIT=yes 66 + shift 67 + shift 68 + ;; 69 + "--check-dup-head") 70 + DUPHEAD=yes 71 + shift 72 + ;; 73 + "--") 74 + shift 75 + break 76 + ;; 77 + *) 78 + break 79 + ;; 80 + esac 81 + done 62 82 63 83 if [ $# -eq 0 ]; then 64 - echo "Usage: clean-includes [--git subjectprefix] [--all | foo.c ...]" 84 + echo "Usage: clean-includes [--git subjectprefix] [--check-dup-head] [--all | foo.c ...]" 65 85 echo "(modifies the files in place)" 66 86 exit 1 67 87 fi ··· 90 110 #include <...> 91 111 ) 92 112 EOT 93 - 94 113 95 114 for f in "$@"; do 96 115 case "$f" in ··· 153 172 ))' "$f" 154 173 155 174 done 175 + 176 + if [ "$DUPHEAD" = "yes" ]; then 177 + egrep "^[[:space:]]*#[[:space:]]*include" "$@" | tr -d '[:blank:]' \ 178 + | sort | uniq -c | awk '{if ($1 > 1) print $0}' 179 + if [ $? -eq 0 ]; then 180 + echo "Found duplicate header file includes. Please check the above files manually." 181 + exit 1 182 + fi 183 + fi 156 184 157 185 if [ "$GIT" = "yes" ]; then 158 186 git add -- "$@"