From patchwork Thu Feb 18 18:05:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 8353431 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3E007C0553 for ; Thu, 18 Feb 2016 18:28:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9394320357 for ; Thu, 18 Feb 2016 18:28:47 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CC6092034C for ; Thu, 18 Feb 2016 18:28:46 +0000 (UTC) Received: from localhost ([::1]:44216 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWTJm-0007Wc-3U for patchwork-qemu-devel@patchwork.kernel.org; Thu, 18 Feb 2016 13:28:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWTFO-0007gk-DA for qemu-devel@nongnu.org; Thu, 18 Feb 2016 13:24:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aWTFM-00072d-VD for qemu-devel@nongnu.org; Thu, 18 Feb 2016 13:24:14 -0500 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:38439) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aWTFM-0006yz-OU for qemu-devel@nongnu.org; Thu, 18 Feb 2016 13:24:12 -0500 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.84) (envelope-from ) id 1aWSxC-000208-65; Thu, 18 Feb 2016 18:05:26 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 18 Feb 2016 18:05:21 +0000 Message-Id: <1455818725-7647-5-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1455818725-7647-1-git-send-email-peter.maydell@linaro.org> References: <1455818725-7647-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:8b0:1d0::1 Cc: patches@linaro.org Subject: [Qemu-devel] [PATCH 4/8] scripts/clean-includes: Enhance to handle header files X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Eric Blake --- 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*(["<][^>"]*[">])/ ||