[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 4/8] scripts/clean-includes: Enhance to handle heade
From: |
Peter Maydell |
Subject: |
[Qemu-devel] [PATCH 4/8] scripts/clean-includes: Enhance to handle header files |
Date: |
Thu, 18 Feb 2016 18:05:21 +0000 |
Enhance clean-includes to handle header files as well as .c source
files. For headers we merely remove all the redundant #include
lines, including any includes of qemu/osdep.h itself.
There is a simple mollyguard on the include file processing to
skip a few key headers like osdep.h itself, to avoid producing
bad patches if the script is run on every file in include/.
Signed-off-by: Peter Maydell <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
scripts/clean-includes | 50 ++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 42 insertions(+), 8 deletions(-)
diff --git a/scripts/clean-includes b/scripts/clean-includes
index 1af1f82..737a5ce 100755
--- a/scripts/clean-includes
+++ b/scripts/clean-includes
@@ -1,7 +1,8 @@
#!/bin/sh -e
#
# Clean up QEMU #include lines by ensuring that qemu/osdep.h
-# is the first include listed.
+# is the first include listed, and no headers provided by
+# osdep.h itself are redundantly included.
#
# Copyright (c) 2015 Linaro Limited
#
@@ -22,6 +23,11 @@
# This script requires Coccinelle to be installed.
+# .c files will have the osdep.h included added, and redundant
+# includes removed.
+# .h files will have redundant includes (including includes of osdep.h)
+# 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
@@ -73,13 +79,41 @@ EOT
for f in "$@"; do
- # First, use coccinelle to add qemu/osdep.h before the first existing include
- # (this will add two lines if the file uses both "..." and <...> #includes,
- # but we will remove the extras in the next step)
- spatch --in-place --no-show-diff --cocci-file "$COCCIFILE" "$f"
-
- # Now remove any duplicate osdep.h includes
- perl -n -i -e 'print if !/#include "qemu\/osdep.h"/ || !$n++;' "$f"
+ case "$f" in
+ *.c)
+ MODE=c
+ ;;
+
*include/qemu/osdep.h|include/qemu/compiler.h|include/config.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
+ ;;
+ *)
+ echo "WARNING: ignoring $f (cannot handle non-C files)"
+ continue
+ ;;
+ esac
+
+ if [ "$MODE" = "c" ]; then
+ # First, use coccinelle to add qemu/osdep.h before the first existing
include
+ # (this will add two lines if the file uses both "..." and <...> #includes,
+ # but we will remove the extras in the next step)
+ spatch --in-place --no-show-diff --cocci-file "$COCCIFILE" "$f"
+
+ # Now remove any duplicate osdep.h includes
+ perl -n -i -e 'print if !/#include "qemu\/osdep.h"/ || !$n++;' "$f"
+ else
+ # Remove includes of osdep.h itself
+ perl -n -i -e 'print if !/\s*#\s*include\s*(["<][^>"]*[">])/ ||
+ ! (grep { $_ eq $1 } qw ("qemu/osdep.h"))' "$f"
+ fi
# Remove includes that osdep.h already provides
perl -n -i -e 'print if !/\s*#\s*include\s*(["<][^>"]*[">])/ ||
--
1.9.1
- Re: [Qemu-devel] [PATCH 7/8] all: Clean up includes, (continued)
- [Qemu-devel] [PATCH 8/8] include: Clean up includes, Peter Maydell, 2016/02/18
- [Qemu-devel] [PATCH 2/8] osdep.h: Define macros for the benefit of C++ before C++11, Peter Maydell, 2016/02/18
- [Qemu-devel] [PATCH 6/8] osdep.h: Include config-target.h if NEED_CPU_H is defined, Peter Maydell, 2016/02/18
- [Qemu-devel] [PATCH 3/8] disas/arm-a64.cc: Include osdep.h first, Peter Maydell, 2016/02/18
- [Qemu-devel] [PATCH 4/8] scripts/clean-includes: Enhance to handle header files,
Peter Maydell <=
- [Qemu-devel] [PATCH 5/8] scripts/clean-includes: Add --all option, Peter Maydell, 2016/02/18
- [Qemu-devel] [PATCH 1/8] cpu: Clean up includes, Peter Maydell, 2016/02/18
- Re: [Qemu-devel] [PATCH 0/8] more include cleaning, Eric Blake, 2016/02/18