diff mbox series

[v2,01/19] Use #include "..." for our own headers, <...> for others

Message ID 20180131144846.31697-2-armbru@redhat.com
State New
Headers show
Series [v2,01/19] Use #include "..." for our own headers, <...> for others | expand

Commit Message

Markus Armbruster Jan. 31, 2018, 2:48 p.m. UTC
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>
---
 contrib/vhost-user-scsi/vhost-user-scsi.c             | 4 ++--
 hw/ide/sii3112.c                                      | 4 ++--
 hw/s390x/s390-ccw.c                                   | 3 ++-
 include/hw/loader-fit.h                               | 2 +-
 include/hw/registerfields.h                           | 2 +-
 include/hw/s390x/storage-attributes.h                 | 2 +-
 target/i386/hax-all.c                                 | 2 +-
 target/i386/hvf/hvf.c                                 | 2 +-
 target/i386/hvf/x86_decode.c                          | 2 +-
 target/i386/hvf/x86_mmu.c                             | 7 +++----
 target/i386/hvf/x86_task.c                            | 2 +-
 target/s390x/gen-features.c                           | 4 ++--
 target/xtensa/core-dc232b/xtensa-modules.c            | 2 +-
 target/xtensa/core-dc233c/xtensa-modules.c            | 2 +-
 target/xtensa/core-de212/xtensa-modules.c             | 2 +-
 target/xtensa/core-fsf/xtensa-modules.c               | 2 +-
 target/xtensa/core-sample_controller/xtensa-modules.c | 2 +-
 target/xtensa/xtensa-isa.h                            | 2 +-
 vl.c                                                  | 2 +-
 19 files changed, 25 insertions(+), 25 deletions(-)

Comments

Eric Blake Jan. 31, 2018, 2:59 p.m. UTC | #1
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.

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.

Reviewed-by: Eric Blake <eblake@redhat.com>
Thomas Huth Jan. 31, 2018, 3:40 p.m. UTC | #2
On 31.01.2018 15:48, 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.

That's a little bit of code churn ... why not delete them here
immediately, or simply ignore these headers here and just delete them in
the next patch?

> While there, separate #include from file comment with a blank line,
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
[...]
> diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
> index 0570f597ec..9968974fbe 100644
> --- a/target/s390x/gen-features.c
> +++ b/target/s390x/gen-features.c
> @@ -13,8 +13,8 @@
>   */
>  
>  

While you're at it, remove one of the two blank lines?

> -#include "inttypes.h"
> -#include "stdio.h"
> +#include <inttypes.h>
> +#include <stdio.h>
>  #include "cpu_features_def.h"

Above remarks are just nits, anyway patch looks fine, so:

Reviewed-by: Thomas Huth <thuth@redhat.com>
Markus Armbruster Feb. 1, 2018, 6:57 a.m. UTC | #3
Thomas Huth <thuth@redhat.com> writes:

> On 31.01.2018 15:48, 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.
>
> That's a little bit of code churn ... why not delete them here
> immediately, or simply ignore these headers here and just delete them in
> the next patch?

Ignore won't do, as scripts/clean-includes won't find them then.

Delete is possible, but requires still more explanation in the commit
message.  Worthwhile?

>> While there, separate #include from file comment with a blank line,
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
> [...]
>> diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
>> index 0570f597ec..9968974fbe 100644
>> --- a/target/s390x/gen-features.c
>> +++ b/target/s390x/gen-features.c
>> @@ -13,8 +13,8 @@
>>   */
>>  
>>  
>
> While you're at it, remove one of the two blank lines?

Yes.

>> -#include "inttypes.h"
>> -#include "stdio.h"
>> +#include <inttypes.h>
>> +#include <stdio.h>
>>  #include "cpu_features_def.h"
>
> Above remarks are just nits, anyway patch looks fine, so:
>
> Reviewed-by: Thomas Huth <thuth@redhat.com>

Thanks!
Markus Armbruster Feb. 1, 2018, 7:12 a.m. UTC | #4
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);
	}
    }
}
Thomas Huth Feb. 1, 2018, 8:17 a.m. UTC | #5
On 01.02.2018 07:57, Markus Armbruster wrote:
> Thomas Huth <thuth@redhat.com> writes:
> 
>> On 31.01.2018 15:48, 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.
>>
>> That's a little bit of code churn ... why not delete them here
>> immediately, or simply ignore these headers here and just delete them in
>> the next patch?
> 
> Ignore won't do, as scripts/clean-includes won't find them then.
> 
> Delete is possible, but requires still more explanation in the commit
> message.  Worthwhile?

I'd prefer to do it. Otherwise, if you look at the commit log of such a
file later, it just looks weird (first change the quotes, then
immediately delete it afterwards again). But if it's too cumbersome to
rework your patch this way right now, I'm also fine if you keep it as it
currently is.

 Thomas
Eric Blake Feb. 1, 2018, 1:08 p.m. UTC | #6
On 02/01/2018 01:12 AM, Markus Armbruster wrote:

>>> +
>>>  #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?

Perhaps not; a tendency when writing a new file is to copy-and-paste a
list of includes from another file, then add more if things still don't
compile.  Since adding memory.h never changes whether compilation will
work (unless you forgot osdep.h in the first place, and thereby missed
string.h), and if we eradicate all current uses of memory.h, new uses
won't have the bad example to copy from.
diff mbox series

Patch

diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
index 54c1191db0..02c29019d1 100644
--- a/contrib/vhost-user-scsi/vhost-user-scsi.c
+++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
@@ -11,10 +11,10 @@ 
  */
 
 #include "qemu/osdep.h"
+#include <iscsi/iscsi.h>
+#include <iscsi/scsi-lowlevel.h>
 #include "contrib/libvhost-user/libvhost-user-glib.h"
 #include "standard-headers/linux/virtio_scsi.h"
-#include "iscsi/iscsi.h"
-#include "iscsi/scsi-lowlevel.h"
 
 #include <glib.h>
 
diff --git a/hw/ide/sii3112.c b/hw/ide/sii3112.c
index 17aa930e39..e3896c65b4 100644
--- a/hw/ide/sii3112.c
+++ b/hw/ide/sii3112.c
@@ -12,8 +12,8 @@ 
  * http://wiki.osdev.org/User:Quok/Silicon_Image_Datasheets
  */
 
-#include <qemu/osdep.h>
-#include <hw/ide/pci.h>
+#include "qemu/osdep.h"
+#include "hw/ide/pci.h"
 #include "trace.h"
 
 #define TYPE_SII3112_PCI "sii3112"
diff --git a/hw/s390x/s390-ccw.c b/hw/s390x/s390-ccw.c
index 4a9d4d2534..7fc1c603c0 100644
--- a/hw/s390x/s390-ccw.c
+++ b/hw/s390x/s390-ccw.c
@@ -10,10 +10,11 @@ 
  * or (at your option) any later version. See the COPYING file in the
  * top-level directory.
  */
+
 #include "qemu/osdep.h"
+#include <libgen.h>
 #include "qapi/error.h"
 #include "hw/sysbus.h"
-#include "libgen.h"
 #include "hw/s390x/css.h"
 #include "hw/s390x/css-bridge.h"
 #include "hw/s390x/s390-ccw.h"
diff --git a/include/hw/loader-fit.h b/include/hw/loader-fit.h
index 9e2a068a20..0284c3e02c 100644
--- a/include/hw/loader-fit.h
+++ b/include/hw/loader-fit.h
@@ -20,7 +20,7 @@ 
 #ifndef HW_LOADER_FIT_H
 #define HW_LOADER_FIT_H
 
-#include <exec/hwaddr.h>
+#include "exec/hwaddr.h"
 
 struct fit_loader_match {
     const char *compatible;
diff --git a/include/hw/registerfields.h b/include/hw/registerfields.h
index 44e0b94edf..2659a58737 100644
--- a/include/hw/registerfields.h
+++ b/include/hw/registerfields.h
@@ -11,7 +11,7 @@ 
 #ifndef REGISTERFIELDS_H
 #define REGISTERFIELDS_H
 
-#include <qemu/bitops.h>
+#include "qemu/bitops.h"
 
 /* Define constants for a 32 bit register */
 
diff --git a/include/hw/s390x/storage-attributes.h b/include/hw/s390x/storage-attributes.h
index 9be954d163..d6403a0a7e 100644
--- a/include/hw/s390x/storage-attributes.h
+++ b/include/hw/s390x/storage-attributes.h
@@ -12,7 +12,7 @@ 
 #ifndef S390_STORAGE_ATTRIBUTES_H
 #define S390_STORAGE_ATTRIBUTES_H
 
-#include <hw/qdev.h>
+#include "hw/qdev.h"
 #include "monitor/monitor.h"
 
 #define TYPE_S390_STATTRIB "s390-storage_attributes"
diff --git a/target/i386/hax-all.c b/target/i386/hax-all.c
index 934ec4afd1..6874018738 100644
--- a/target/i386/hax-all.c
+++ b/target/i386/hax-all.c
@@ -30,7 +30,7 @@ 
 #include "exec/ioport.h"
 
 #include "qemu-common.h"
-#include "strings.h"
+#include <strings.h>
 #include "hax-i386.h"
 #include "sysemu/accel.h"
 #include "sysemu/sysemu.h"
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 010866ed22..5d00c58129 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -43,7 +43,7 @@ 
 #include "hw/i386/apic_internal.h"
 #include "hw/boards.h"
 #include "qemu/main-loop.h"
-#include "strings.h"
+#include <strings.h>
 #include "sysemu/accel.h"
 #include "sysemu/sysemu.h"
 #include "target/i386/cpu.h"
diff --git a/target/i386/hvf/x86_decode.c b/target/i386/hvf/x86_decode.c
index bf93e8207d..dcff2073a7 100644
--- a/target/i386/hvf/x86_decode.c
+++ b/target/i386/hvf/x86_decode.c
@@ -21,7 +21,7 @@ 
 #include "qemu-common.h"
 #include "panic.h"
 #include "x86_decode.h"
-#include "string.h"
+#include <string.h>
 #include "vmx.h"
 #include "x86_mmu.h"
 #include "x86_descr.h"
diff --git a/target/i386/hvf/x86_mmu.c b/target/i386/hvf/x86_mmu.c
index 5c1f35acd0..2ad8fcdf70 100644
--- a/target/i386/hvf/x86_mmu.c
+++ 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>
 #include "panic.h"
-
 #include "qemu-common.h"
 #include "cpu.h"
 #include "x86.h"
 #include "x86_mmu.h"
-#include "string.h"
+#include <string.h>
 #include "vmcs.h"
 #include "vmx.h"
-
-#include "memory.h"
 #include "exec/address-spaces.h"
 
 #define pte_present(pte) (pte & PT_PRESENT)
diff --git a/target/i386/hvf/x86_task.c b/target/i386/hvf/x86_task.c
index d7f665f8fa..452fad6b2d 100644
--- a/target/i386/hvf/x86_task.c
+++ b/target/i386/hvf/x86_task.c
@@ -32,7 +32,7 @@ 
 #include "hw/i386/apic_internal.h"
 #include "hw/boards.h"
 #include "qemu/main-loop.h"
-#include "strings.h"
+#include <strings.h>
 #include "sysemu/accel.h"
 #include "sysemu/sysemu.h"
 #include "target/i386/cpu.h"
diff --git a/target/s390x/gen-features.c b/target/s390x/gen-features.c
index 0570f597ec..9968974fbe 100644
--- a/target/s390x/gen-features.c
+++ b/target/s390x/gen-features.c
@@ -13,8 +13,8 @@ 
  */
 
 
-#include "inttypes.h"
-#include "stdio.h"
+#include <inttypes.h>
+#include <stdio.h>
 #include "cpu_features_def.h"
 
 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
diff --git a/target/xtensa/core-dc232b/xtensa-modules.c b/target/xtensa/core-dc232b/xtensa-modules.c
index 2e103cd2f5..0af43c84bb 100644
--- a/target/xtensa/core-dc232b/xtensa-modules.c
+++ b/target/xtensa/core-dc232b/xtensa-modules.c
@@ -18,7 +18,7 @@ 
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
    02110-1301, USA.  */
 
-#include <xtensa-isa.h>
+#include "xtensa-isa.h"
 #include "xtensa-isa-internal.h"
 
 
diff --git a/target/xtensa/core-dc233c/xtensa-modules.c b/target/xtensa/core-dc233c/xtensa-modules.c
index 2728311c9a..8a41e73659 100644
--- a/target/xtensa/core-dc233c/xtensa-modules.c
+++ b/target/xtensa/core-dc233c/xtensa-modules.c
@@ -21,7 +21,7 @@ 
    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
 
-#include <xtensa-isa.h>
+#include "xtensa-isa.h"
 #include "xtensa-isa-internal.h"
 
 
diff --git a/target/xtensa/core-de212/xtensa-modules.c b/target/xtensa/core-de212/xtensa-modules.c
index 4a8735889e..21f3bd8797 100644
--- a/target/xtensa/core-de212/xtensa-modules.c
+++ b/target/xtensa/core-de212/xtensa-modules.c
@@ -21,7 +21,7 @@ 
    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
 
-#include <xtensa-isa.h>
+#include "xtensa-isa.h"
 #include "xtensa-isa-internal.h"
 
 
diff --git a/target/xtensa/core-fsf/xtensa-modules.c b/target/xtensa/core-fsf/xtensa-modules.c
index 238800d823..9621f5142a 100644
--- a/target/xtensa/core-fsf/xtensa-modules.c
+++ b/target/xtensa/core-fsf/xtensa-modules.c
@@ -18,7 +18,7 @@ 
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
    02110-1301, USA.  */
 
-#include <xtensa-isa.h>
+#include "xtensa-isa.h"
 #include "xtensa-isa-internal.h"
 
 
diff --git a/target/xtensa/core-sample_controller/xtensa-modules.c b/target/xtensa/core-sample_controller/xtensa-modules.c
index 2f000199b8..39810e532a 100644
--- a/target/xtensa/core-sample_controller/xtensa-modules.c
+++ b/target/xtensa/core-sample_controller/xtensa-modules.c
@@ -21,7 +21,7 @@ 
    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
 
-#include <xtensa-isa.h>
+#include "xtensa-isa.h"
 #include "xtensa-isa-internal.h"
 
 
diff --git a/target/xtensa/xtensa-isa.h b/target/xtensa/xtensa-isa.h
index d06614c187..0f0211f841 100644
--- a/target/xtensa/xtensa-isa.h
+++ b/target/xtensa/xtensa-isa.h
@@ -1 +1 @@ 
-#include <hw/xtensa/xtensa-isa.h>
+#include "hw/xtensa/xtensa-isa.h"
diff --git a/vl.c b/vl.c
index e517a8d995..d7e4d97814 100644
--- a/vl.c
+++ b/vl.c
@@ -28,8 +28,8 @@ 
 #include "qemu/uuid.h"
 
 #ifdef CONFIG_SECCOMP
+#include <sys/prctl.h>
 #include "sysemu/seccomp.h"
-#include "sys/prctl.h"
 #endif
 
 #ifdef CONFIG_SDL