All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, f4bug@amsat.org
Subject: Re: [Qemu-devel] [PATCH v2 01/19] Use #include "..." for our own headers, <...> for others
Date: Thu, 01 Feb 2018 08:12:03 +0100	[thread overview]
Message-ID: <87fu6lrxoc.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <fd604c0a-bf97-edba-f648-820294447fa5@redhat.com> (Eric Blake's message of "Wed, 31 Jan 2018 08:59:00 -0600")

Eric Blake <eblake@redhat.com> writes:

> On 01/31/2018 08:48 AM, Markus Armbruster wrote:
>> System headers should be included with <...>, our own headers with
>> "...".  Offenders tracked down with an ugly, brittle and probably
>> buggy Perl script.  Previous iteration was commit a9c94277f0.
>> 
>> Put the cleaned up system header includes first, except for the ones
>> the next commit will delete.
>> 
>> While there, separate #include from file comment with a blank line,
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>
>> +++ b/target/i386/hvf/x86_mmu.c
>> @@ -15,18 +15,17 @@
>>   * You should have received a copy of the GNU Lesser General Public
>>   * License along with this program; if not, see <http://www.gnu.org/licenses/>.
>>   */
>> +
>>  #include "qemu/osdep.h"
>> +#include <memory.h>
>
> <memory.h> is an obsolete spelling for the now-universal <string.h>.  We
> should NEVER need to include it; scripts/clean-includes should be taught
> to blacklist this one.

"Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe trying to
produce bigger and better idiots.  So far, the Universe is winning."

My point is: if we extended our tooling every time we see a mistake,
we'll drown in tooling.  I think we should limit ourselves to *common*
mistakes.  Is this one common?

> But that's a matter for another patch; this one does exactly what it
> promises, and was mechanical (even if the brittle perl script isn't
> published), so it's best to keep it as-is.

I append my Perl script.

Its simpleminded approach to locating headers in the source tree fails
frequently.  It should really use the compiler to find them.

I reviewed inclusions of headers the script flags as "(included
inconsistently)".  I also reviewed "(included with <>)" where the script
can find a header in the tree.  I patched only obvious mistakes.  There
are a few unobvious cases: headers in tree with the same name as a
system header, e.g. elf.h, io.h.

> Reviewed-by: Eric Blake <eblake@redhat.com>

Thanks!


#!/usr/bin/perl -w

use strict;

my %ihdr = ();
my %idir = ();
my @sall = ();
my @sinc = ();

open(my $fh, "-|", "git grep '^[ \t]*#[ \t]*include[ \t]'")
    or die "can't run git grep: $!";
while (<$fh>) {
    m,^(([^:]*)/)?[^:/]*:[ \t]*\#[ \t]*include[ \t]*(["<])([^">]*), or next;
    my $dir = $2 // ".";
    my $delim = $3;
    my $h = $4;
    $ihdr{$h} |= 1 << ($delim eq "<");
    if (exists $idir{$h}) {
	my $aref = $idir{$h};
	push @$aref, $dir unless grep($_ eq $dir, @$aref);
    } else {
	$idir{$h} = [$dir];
    }
}
close ($fh);

open($fh, "-|", "git ls-tree -r --name-only HEAD")
    or die "can't run git ls-tree: $!";
while (<$fh>) {
    chomp;
    push @sall, $_;
}
close ($fh);

@sinc = grep(/^include\//, @sall);

sub pr {
    my ($h, $fn, $src) = @_;

    print "$h -> $fn";
    if ($ihdr{$h} == 3) {
	print " (included inconsistently)";
    } elsif ($src) {
	print " (included with <>)" if ($ihdr{$h} != 1);
    } else {
	print " (included with \"\")" if ($ihdr{$h} != 2);
    }
    print "\n";
}

for my $h (keys %ihdr) {
    $h =~ m,^(\.\./)*(include/)?(.*), or die;
    my $hh = $3;
    my @fn = grep(/^include\/\Q$hh\E$/, @sinc);
    if (@fn) {
	pr($h, $fn[0], 1);
	next;
    }
    @fn = grep(/^\Q$hh\E$/, @sall);
    if (@fn) {
	pr($h, $fn[0], 1);
	next;
    }
    for my $dir (@{$idir{$h}}) {
	next if $dir eq ".";
	print "## $dir/$hh\n";
	@fn = grep(/^\Q$dir\/$hh\E$/, @sall);
	if (@fn) {
	    pr($h, $fn[0], 1);
	} else {
	    pr($h, "? (in $dir)", 0);
	}
    }
}

  reply	other threads:[~2018-02-01  7:12 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-31 14:48 [Qemu-devel] [PATCH v2 00/19] Clean up includes to reduce compile time Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 01/19] Use #include "..." for our own headers, <...> for others Markus Armbruster
2018-01-31 14:59   ` Eric Blake
2018-02-01  7:12     ` Markus Armbruster [this message]
2018-02-01 13:08       ` Eric Blake
2018-01-31 15:40   ` Thomas Huth
2018-02-01  6:57     ` Markus Armbruster
2018-02-01  8:17       ` Thomas Huth
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 02/19] Clean up includes Markus Armbruster
2018-01-31 15:06   ` Eric Blake
2018-02-01  7:15     ` Markus Armbruster
2018-01-31 15:48   ` Thomas Huth
2018-02-01  2:27     ` Fam Zheng
2018-02-01  7:15       ` Markus Armbruster
2018-01-31 16:39   ` Philippe Mathieu-Daudé
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 03/19] Drop superfluous includes of qapi-types.h and test-qapi-types.h Markus Armbruster
2018-01-31 15:07   ` Eric Blake
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 04/19] Include qapi/error.h exactly where needed Markus Armbruster
2018-01-31 15:16   ` Eric Blake
2018-02-01  7:18     ` Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 05/19] Drop superfluous includes of qapi/qmp/qerror.h Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 06/19] Include qmp-commands.h exactly where needed Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 07/19] Typedef the subtypes of QObject in qemu/typedefs.h, too Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 08/19] Eliminate qapi/qmp/types.h Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 09/19] qdict qlist: Make most helper macros functions Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 10/19] Include qapi/qmp/qobject.h exactly where needed Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 11/19] Include qapi/qmp/qlist.h " Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 12/19] Include qapi/qmp/qdict.h " Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 13/19] Include qapi/qmp/qstring.h " Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 14/19] Include qapi/qmp/qbool.h " Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 15/19] Include qapi/qmp/qnum.h " Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 16/19] Include qapi/qmp/qnull.h " Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 17/19] Drop superfluous includes of qapi/qmp/dispatch.h Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 18/19] Drop superfluous includes of qapi/qmp/qjson.h Markus Armbruster
2018-01-31 14:48 ` [Qemu-devel] [PATCH v2 19/19] Move include qemu/option.h from qemu-common.h to actual users Markus Armbruster
2018-01-31 15:39 ` [Qemu-devel] [PATCH v2 00/19] Clean up includes to reduce compile time no-reply

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=87fu6lrxoc.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=f4bug@amsat.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.