From: David Howells <dhowells@redhat.com>
To: torvalds@osdl.org
Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org,
David Howells <dhowells@redhat.com>
Subject: [PATCH 01/40] UAPI: Add script to convert #include "..." to #include <path/...> in sys headers [ver #3]
Date: Thu, 28 Jul 2011 16:49:30 +0100 [thread overview]
Message-ID: <20110728154930.16618.64116.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20110728154920.16618.89358.stgit@warthog.procyon.org.uk>
Add a script to convert #include "..." to #include <path/...> in kernel system
headers.
Observations:
(1) There are quite a lot of #includes of things like "linux/fs.h" which
should really use <...>. These are changed within include/ dirs.
(2) Some referenced header files are missing for no obvious reason - pm2fb.h
and via_drmclient.h for example.
(3) The DRM video driving code uses -Iinclude/drm when it should probably
just preface its header file names with drm/ in #include. These are
changed within include/drm/.
(4) Under arch/cris/include/ there are some directories (arch-v10 and
arch-v32) that should perhaps be renamed to arch/cris/arch-vXX/include.
Similarly, under arch/sh/, arch/sh/include/mach-X/ should perhaps be
arch/sh/boards/mach-X/include/.
However, I've left these alone as they aren't really a problem.
Signed-off-by: David Howells <dhowells@redhat.com>
---
| 165 +++++++++++++++++++++++++
1 files changed, 165 insertions(+), 0 deletions(-)
create mode 100755 scripts/uapi-disintegration/system-headers.pl
--git a/scripts/uapi-disintegration/system-headers.pl b/scripts/uapi-disintegration/system-headers.pl
new file mode 100755
index 0000000..c905568
--- /dev/null
+++ b/scripts/uapi-disintegration/system-headers.pl
@@ -0,0 +1,165 @@
+#!/usr/bin/perl -w
+
+use File::Find;
+
+my @sys_header_dirs = (
+ "include"
+ );
+
+#
+# Changes must be committed first
+#
+system("git diff --quiet") == 0 or die "Uncommitted changes; aborting\n";
+
+#
+# Delete the old patch under StGIT
+#
+system("stg delete uapi-convert-include-quote-to-angle.diff");
+
+#
+# Set up the patch under StGIT
+#
+system("stg new -m '" .
+ "UAPI: Convert #include \"...\" to #include <path/...> in kernel system headers\n" .
+ "\n" .
+ "Convert #include \"...\" to #include <path/...> in kernel system headers.\n" .
+ "\n" .
+ "scripts/uapi-disintegrate/system-headers.pl was used\n" .
+ "' --sign uapi-convert-include-quote-to-angle.diff"
+ ) == 0 or die;
+
+#
+# Find all the system header directories under arch
+#
+opendir DIR, "arch" or die;
+push @sys_header_dirs,
+ map { "arch/$_/include"; }
+sort grep { -d "arch/$_/include"; }
+grep { $_ !~ /^[.]/ }
+readdir DIR;
+closedir DIR;
+
+#
+# Find all the header files
+#
+%headers = ();
+sub find_header()
+{
+ $headers{$File::Find::name} = 1 if ($_ =~ /[.]h$/);
+}
+
+find(\&find_header, @sys_header_dirs);
+
+#print join("\n", sort keys %headers), "\n";
+
+foreach my $hdr (sort grep { $_ !~ m@arch/um/@} keys %headers) {
+ my $dir = $hdr;
+ $dir =~ m@(^.*/)@, $dir = $1;
+
+ open FD, '<', $hdr or die "open $hdr: $!\n";
+ my @lines = <FD>;
+ close FD or die;
+
+ my $printed_name = 0;
+ my $alter_header = 0;
+
+ for (my $l = 0; $l <= $#lines; $l++) {
+ my $line = $lines[$l];
+
+ if ($line =~ /^(#\s*include\s+)["]([^"]+)["](.*[\n])/) {
+ #print $1, '@', $2, '@', $3;
+
+ if (!$printed_name) {
+ #print "[[[ $hdr [\e[36m$dir\e[m] ]]]\n";
+ $printed_name = 1;
+ }
+
+ my $pre = $1;
+ my $name = $2;
+ my $post = $3;
+
+ my $inc = undef;
+ my $base = "??";
+ my $path = "??";
+ my $realpath = "??";
+ my $do_existence_check = 1;
+
+ if ($name eq "platform/acenv.h") {
+ # ACPI includes this relative to the current dir
+ $inc = $dir . $name;
+ } elsif ($name =~ m@^[a-z].*/@) {
+ # We found something like "linux/foo.h" so just accept as is
+ $base = "";
+ $realpath = $path = $name;
+ $do_existence_check = 0;
+ goto no_disassemble;
+ } elsif ($name =~ m@^[.][.]/@) {
+ # We found something like "../foo.h" so we jam the dir on the
+ # front and then remove "dir/.." pairs
+ $inc = $dir . $name;
+ while ($inc =~ m@[^/]*/[.][.]/@) {
+ $inc =~ s@[^/]*/[.][.]/@@;
+ }
+ } elsif ($name !~ m@/@) {
+ # We found something like "foo.h" so we again stick the dir on
+ # the front and then cut off the "include/" prefix.
+ if ($name =~ m@^drm_@) {
+ # Unless it's a DRM header - the drm stuff adds
+ # -Iinclude/drm to the build flags rather than use
+ # <drm/foo.h> for some reason
+ $inc = "include/drm/$name";
+ } else {
+ $inc = $dir . $name;
+ }
+ } else {
+ die "Don't handle \"$name\"\n";
+ }
+
+ $inc =~ m@(.*include/)(.*/[^/]*)@, $base = $1, $path = $2;
+
+ $realpath = $path;
+ if ($dir =~ m@^arch/cris/@ && $path =~ m@^arch-v[0-9]+/(arch/.*)@) {
+ $realpath = $1;
+ } elsif ($dir =~ m@^arch/sh/@ && $path =~ m@^mach-[^/]+/(mach/.*)@) {
+ $realpath = $1;
+ }
+
+ no_disassemble:
+ print $hdr, ": ", $name, " -> \e[36m", $base, "\e[m", $path;
+
+ if ($do_existence_check && ! -f $inc) {
+ if (($hdr eq "arch/powerpc/include/asm/bootx.h" && $name eq "linux_type_defs.h") ||
+ ($hdr eq "include/acpi/platform/acenv.h" && $name =~ /ac[a-z]*[0-9]*[.]h/) ||
+ ($hdr eq "include/linux/jbd.h" && $name eq "jfs_compat.h") ||
+ ($hdr eq "include/linux/jbd2.h" && $name eq "jfs_compat.h") ||
+ ($hdr eq "include/video/cvisionppc.h" && $name eq "pm2fb.h") ||
+ ($hdr eq "include/drm/via_drm.h" && $name eq "via_drmclient.h")
+ ) {
+ print " \e[33mnot present\e[m\n";
+ } else {
+ print " \e[31mnot found\e[m\n";
+ die;
+ }
+ } else {
+ $lines[$l] = $pre . "<" . $realpath . ">" . $post;
+ $alter_header = 1;
+ print "\n";
+ }
+ }
+ }
+
+ if ($alter_header) {
+ my $temp = $hdr . ".syshdr";
+ open FD, '>', $temp or die "create $temp: $!\n";
+ print FD @lines or die "write $temp: $!\n";
+ close FD or die "close $temp: $!\n";
+ rename $temp, $hdr or die "move $temp -> $hdr: $!\n";
+ }
+}
+
+#
+# Commit the changes
+#
+system("stg ref") == 0 or die;
+
+exit 0;
next prev parent reply other threads:[~2011-07-28 15:50 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-28 15:49 [PATCH 00/40] UAPI header file split " David Howells
2011-07-28 15:49 ` David Howells [this message]
2011-07-28 15:49 ` [PATCH 02/40] UAPI: Convert #include "..." to #include <path/...> in kernel system headers " David Howells
2011-07-28 15:49 ` [PATCH 03/40] UAPI: Add script to audit drivers/gpu/ for #including system headers with "..." " David Howells
2011-07-28 15:49 ` [PATCH 04/40] UAPI: Convert #include "..." to #include <path/...> in kernel system headers " David Howells
2011-07-28 15:50 ` [PATCH 05/40] UAPI: Add include/uapi/ directories to build " David Howells
2011-07-28 15:50 ` [PATCH 06/40] UAPI: Differentiate userspace build and kernelspace build include path sets " David Howells
2011-07-28 15:50 ` [PATCH 07/40] UAPI: Fix AHZ multiple inclusion when __KERNEL__ is removed " David Howells
2011-07-28 15:50 ` [PATCH 08/40] UAPI: ac_etime in linux/acct.h must keep its __KERNEL__ guards " David Howells
2011-07-28 15:50 ` [PATCH 09/40] UAPI: Make linux/patchkey.h easier to parse " David Howells
2011-07-28 15:50 ` [PATCH 10/40] UAPI: Don't have a #elif clause in a __KERNEL__ guard in linux/soundcard.h " David Howells
2011-07-28 15:51 ` [PATCH 11/40] UAPI: Fix nested __KERNEL__ guards in video/edid.h " David Howells
2011-07-28 15:51 ` [PATCH 12/40] UAPI: Split trivial #if defined(__KERNEL__) && X conditionals " David Howells
2011-07-28 15:51 ` [PATCH 13/40] UAPI: Remove the inclusion of linux/types.h from x86's asm/page.h " David Howells
2011-07-28 15:51 ` [PATCH 14/40] UAPI: Fix definition of HZ in asm-generic/param.h " David Howells
2011-07-28 15:51 ` [PATCH 15/40] UAPI: elf_read_implies_exec() is a kernel-only feature - so hide from userspace " David Howells
2011-07-28 15:51 ` [PATCH 16/40] UAPI: Fix sigset_t ordering problem " David Howells
2011-07-28 15:52 ` [PATCH 17/40] UAPI: Fix E820_X_MAX " David Howells
2011-07-28 15:52 ` [PATCH 18/40] UAPI: Fix linux/netfilter.h inclusion order " David Howells
2011-07-28 15:52 ` [PATCH 19/40] UAPI: Fix linux/input.h " David Howells
2011-07-28 15:52 ` [PATCH 20/40] UAPI: Fix up linux/netfilter/xt_policy.h " David Howells
2011-07-28 15:52 ` [PATCH 21/40] UAPI: Fix linux/auto_fs.h inclusion order " David Howells
2011-07-28 15:52 ` [PATCH 22/40] UAPI: Fix drmP.h to use #include <...> when referring to system header files " David Howells
2011-07-28 15:53 ` [PATCH 23/40] UAPI: sound/sound_core.c should include linux/fs.h " David Howells
2011-07-28 15:53 ` [PATCH 24/40] UAPI: Fix SNDRV_*_ENDIAN ordering problem " David Howells
2011-07-28 15:53 ` [PATCH 25/40] UAPI: Fix u_quad_t ordering problem in linux/coda.h " David Howells
2011-07-28 15:53 ` [PATCH 26/40] UAPI: Fix " David Howells
2011-07-28 15:53 ` [PATCH 27/40] UAPI: Guard linux/isdn_divertif.h " David Howells
2011-07-28 15:53 ` [PATCH 28/40] UAPI: Guard linux/sound.h " David Howells
2011-07-28 15:53 ` [PATCH 29/40] UAPI: Fix linux/ncp.h " David Howells
2011-07-28 15:54 ` [PATCH 30/40] UAPI: Fix x86_64 system call count and generation " David Howells
2011-07-28 15:54 ` [PATCH 31/40] UAPI: Fix arch/mips/include/asm/Kbuild to have separate header-y lines " David Howells
2011-07-28 15:54 ` [PATCH 32/40] UAPI: Add a script to create a commit to set up new UAPI dirs " David Howells
2011-07-28 15:54 ` [PATCH 33/40] UAPI: Set up UAPI Kbuild files " David Howells
2011-07-28 15:54 ` [PATCH 34/40] UAPI: Plumb the UAPI Kbuilds into the user header handling system " David Howells
2011-07-28 15:54 ` [PATCH 35/40] UAPI: Set up uapi/asm/Kbuild.asm " David Howells
2011-07-28 15:55 ` [PATCH 36/40] UAPI: Move linux/version.h " David Howells
2011-07-28 15:55 ` [PATCH 37/40] UAPI: Make UAPI headers install to usr/include/ " David Howells
2011-07-28 15:55 ` [PATCH 38/40] UAPI: Fix the page-types query program in the docs " David Howells
2011-07-28 15:55 ` [PATCH 39/40] UAPI: Fix the x86 test_get_len tool " David Howells
2011-07-28 15:55 ` [PATCH 40/40] UAPI: Scripts to disintegrate header files " David Howells
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=20110728154930.16618.64116.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®