qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] qemu: replace "" with <> in headers
@ 2018-03-21 14:46 Michael S. Tsirkin
  2018-03-21 15:04 ` Paolo Bonzini
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Michael S. Tsirkin @ 2018-03-21 14:46 UTC (permalink / raw)
  To: qemu-devel, Daniel P. Berrangé
  Cc: Thomas Huth, Laurent Vivier, Peter Maydell, Dmitry Fleytman,
	Ronnie Sahlberg, Li Zhijian, David Hildenbrand, Jeff Cody,
	Zhang Chen, BALATON Zoltan, Keith Busch, Max Filippov,
	Gerd Hoffmann, Jiri Pirko, Subbaraya Sundeep, Eric Blake,
	Michael Roth, Marcelo Tosatti, Josh Durgin, Stefano Stabellini,
	Alberto Garcia, zhanghailiang, Ben Warren, Marcel Apfelbaum,
	Yongbok Kim, Markus Armbruster, Stefan Berger,
	Christian Borntraeger, kvm, Hervé Poussineau, Shannon Zhao,
	Anthony Perard, Liu Yuan, David Gibson, Andrzej Zaborowski,
	Jason Wang, Artyom Tarasenko, Riku Voipio, Fam Zheng,
	Eduardo Habkost, Corey Minyard, Amit Shah, Pavel Dovgalyuk,
	Stefan Weil, Xie Changlong, Alistair Francis, Peter Lieven,
	Dr. David Alan Gilbert, Greg Kurz, Marc-André Lureau,
	Alex Williamson, qemu-arm, Peter Chubb, Yuval Shaia,
	Stefan Hajnoczi, Paolo Bonzini, xen-devel, John Snow,
	Richard Henderson, Kevin Wolf, qemu-block, Peter Crosthwaite,
	Hitoshi Mitake, Wen Congyang, qemu-s390x, Cornelia Huck,
	Richard W.M. Jones, Juan Quintela, Max Reitz, Michael Walle,
	qemu-ppc, Andreas Färber, Igor Mammedov, Hannes Reinecke,
	Philippe Mathieu-Daudé

Our current scheme is to use
 #include ""
for internal headers, and
 #include <>
for external ones.

Unfortunately this is not based on compiler support: from C point of
view, the "" form merely looks up headers in the current directory
and then falls back on <> directories.

Thus, for example, a system header trace.h - should it be present - will
conflict with our local trace.h

As another example of problems, a header by the same name in the source
directory will always be picked up first - before any headers in
the include directory.

Let's change the scheme: make sure all headers that are not
in the source directory are included through a path
starting with qemu/ , thus:

 #include <>

headers in the same directory as source are included with

 #include ""

as per standard.

This (untested) patch is just to start the discussion and does not
change all of the codebase. If there's agreement, this will be
run on all code to converting code to this scheme.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 scripts/changeheaders.pl | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100755 scripts/changeheaders.pl

diff --git a/scripts/changeheaders.pl b/scripts/changeheaders.pl
new file mode 100755
index 0000000..22bd5b8
--- /dev/null
+++ b/scripts/changeheaders.pl
@@ -0,0 +1,20 @@
+#!/usr/bin/perl -pi
+
+if (m@^\s*#include\s+"([^"+]"@o) {
+    next;
+}
+
+my $hdr = $1;
+my $file = $ARGV;
+$file =~ s@/[^/]+$@@g;
+$file .= $hdr;
+
+if (-e $file) {
+    next;
+}
+
+if (m@^\s*#include\s+"qemu/@o) {
+    s@^(\s*#include\s+)"qemu/([^"]+)"(.*)$@$1<qemu/common/$2>$3@o) {
+} else {
+    s@^(\s*#include\s+)"([^"]+)"(.*)$@$1<qemu/$2>$3@o) {
+}
-- 
MST

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-03-22 20:34 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-21 14:46 [Qemu-devel] [PATCH v2] qemu: replace "" with <> in headers Michael S. Tsirkin
2018-03-21 15:04 ` Paolo Bonzini
2018-03-21 15:11   ` Michael S. Tsirkin
2018-03-21 15:23     ` Paolo Bonzini
2018-03-21 15:19 ` Daniel P. Berrangé
2018-03-21 15:39   ` Michael S. Tsirkin
2018-03-21 15:54     ` Daniel P. Berrangé
2018-03-21 15:34 ` Kevin Wolf
2018-03-21 15:58   ` Michael S. Tsirkin
2018-03-21 16:22     ` Kevin Wolf
2018-03-22 19:29       ` Michael S. Tsirkin
2018-03-22 20:33         ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).