From: "Daniel P. Berrange" <berrange@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>,
patches@linaro.org
Subject: Re: [Qemu-devel] [PATCH 1/3] scripts: Add new clean-includes script to fix C include directives
Date: Mon, 11 Jan 2016 15:23:57 +0000 [thread overview]
Message-ID: <20160111152357.GB12607@redhat.com> (raw)
In-Reply-To: <1449505425-32022-2-git-send-email-peter.maydell@linaro.org>
On Mon, Dec 07, 2015 at 04:23:43PM +0000, Peter Maydell wrote:
> Add a new scripts/clean-includes, which can be used to automatically
> ensure that a C source file includes qemu/osdep.h first and doesn't
> then include any headers which osdep.h provides already.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> scripts/clean-includes | 109 +++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 109 insertions(+)
> create mode 100755 scripts/clean-includes
>
> diff --git a/scripts/clean-includes b/scripts/clean-includes
> new file mode 100755
> index 0000000..1af1f82
> --- /dev/null
> +++ b/scripts/clean-includes
> @@ -0,0 +1,109 @@
> +#!/bin/sh -e
> +#
> +# Clean up QEMU #include lines by ensuring that qemu/osdep.h
> +# is the first include listed.
> +#
> +# Copyright (c) 2015 Linaro Limited
> +#
> +# Authors:
> +# Peter Maydell <peter.maydell@linaro.org>
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2
> +# or (at your option) any later version. See the COPYING file in
> +# the top-level directory.
> +
> +# Usage:
> +# clean-includes [--git subjectprefix] file ...
> +#
> +# 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.
> +
> +# This script requires Coccinelle to be installed.
> +
> +
> +# 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
> +# of the guest agent or standalone tests.
> +
> +# for i in `git ls-tree --name-only HEAD` ; do test -f $i && \
> +# grep -E '^# *include' $i | head -1 | grep 'osdep.h' ; test $? != 0 && \
> +# echo $i ; done
> +
> +
> +GIT=no
> +
> +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
> +
> +if [ $# -eq 0 ]; then
> + echo "Usage: clean-includes [--git subjectprefix] foo.c ..."
> + echo "(modifies the files in place)"
> + exit 1
> +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.
> +COCCIFILE="$(mktemp --suffix=.cocci)"
> +
> +trap 'rm -f -- "$COCCIFILE"' INT TERM HUP EXIT
> +
> +cat >"$COCCIFILE" <<EOT
> +@@
> +@@
> +
> +(
> ++ #include "qemu/osdep.h"
> + #include "..."
> +|
> ++ #include "qemu/osdep.h"
> + #include <...>
> +)
> +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"
> +
> + # Remove includes that osdep.h already provides
> + perl -n -i -e 'print if !/\s*#\s*include\s*(["<][^>"]*[">])/ ||
> + ! (grep { $_ eq $1 } qw (
> + "config-host.h" "qemu/compiler.h" "config.h"
> + <stdarg.h> <stddef.h> <stdbool.h> <stdint.h> <sys/types.h>
> + <stdlib.h> <stdio.h> <string.h> <strings.h> <inttypes.h>
> + <limits.h> <unistd.h> <time.h> <ctype.h> <errno.h> <fcntl.h>
> + <sys/stat.h> <sys/time.h> <assert.h> <signal.h>
> + "glib-compat.h" "qapi/error.h"
> + ))' "$f"
> +
> +done
> +
> +if [ "$GIT" = "yes" ]; then
> + git add -- "$@"
> + git commit --signoff -F - <<EOF
> +$GITSUBJ: Clean up includes
> +
> +Clean up includes so that osdep.h is included first and headers
> +which it implies are not included manually.
> +
> +This commit was created with scripts/clean-includes.
> +
> +EOF
> +
> +fi
> --
Reviewed-by: Daniel P. Berrange <berrange@redhat.com>
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
next prev parent reply other threads:[~2016-01-11 15:24 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-07 16:23 [Qemu-devel] [PATCH 0/3] clean-includes script to add osdep.h to everything Peter Maydell
2015-12-07 16:23 ` [Qemu-devel] [PATCH 1/3] scripts: Add new clean-includes script to fix C include directives Peter Maydell
2016-01-11 15:23 ` Daniel P. Berrange [this message]
2015-12-07 16:23 ` [Qemu-devel] [PATCH 2/3] target-arm: Clean up includes Peter Maydell
2016-01-11 15:26 ` Daniel P. Berrange
2015-12-07 16:23 ` [Qemu-devel] [PATCH 3/3] hw/arm: " Peter Maydell
2016-01-11 13:08 ` [Qemu-devel] [PATCH 0/3] clean-includes script to add osdep.h to everything Peter Maydell
2016-01-11 15:19 ` Daniel P. Berrange
2016-01-18 16:33 ` Peter Maydell
2016-01-18 17:08 ` Peter Maydell
2016-01-19 7:27 ` Markus Armbruster
2016-01-19 8:46 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160111152357.GB12607@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=patches@linaro.org \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.