This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Script for checking config symbol use.
authorJarkko Hietaniemi <jhi@iki.fi>
Sat, 15 Aug 2015 15:24:58 +0000 (11:24 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Fri, 2 Oct 2015 22:34:56 +0000 (18:34 -0400)
MANIFEST
Porting/README.pod
Porting/checkcfguse.pl [new file with mode: 0755]
Porting/exec-bit.txt

index 864dd4a..87ca47b 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -4729,6 +4729,7 @@ Porting/check83.pl                Check whether we are 8.3-friendly
 Porting/checkansi.pl           Check source code for ANSI-C violations
 Porting/checkAUTHORS.pl                Check that the AUTHORS file is complete
 Porting/checkcfgvar.pl         Check that config scripts define all symbols
+Porting/checkcfguse.pl         Check that config symbols are being used
 Porting/check-cpan-pollution   Check for commits that may wrongly touch CPAN distros
 Porting/checkpodencoding.pl    Check POD encoding
 Porting/checkURL.pl            Check whether we have working URLs
index 84020f6..21a0414 100644 (file)
@@ -42,6 +42,11 @@ Check source code for ANSI-C violations.
 
 Used by F<t/porting/authors.t> to ensure the F<AUTHORS> list is up to date.
 
+=head2 F<checkcfguse.pl>
+
+Check where the symbols defined in the various F<config.sh>-clones
+are being used.  VMS is probably not handled properly here.
+
 =head2 F<checkcfgvar.pl>
 
 Check that the various F<config.sh>-clones have (at least) all the same
diff --git a/Porting/checkcfguse.pl b/Porting/checkcfguse.pl
new file mode 100755 (executable)
index 0000000..af3dd12
--- /dev/null
@@ -0,0 +1,99 @@
+#!/usr/bin/perl -w
+
+#
+# checkcfguse.pl
+#
+# (1) finds all the Configure/config symbols
+#
+# (2) greps for their use in the core files and shows which ones.
+#
+
+use strict;
+use warnings;
+
+my %SYM;
+
+my @PAT =
+    (
+     [
+      # The format is:
+      # (1) aref of filename glob patterns
+      # (2) aref of qr patterns, the submatch $1 is the symbol name
+      [
+       "config_h.SH",
+      ],
+      [
+       qr/^#\$(\w+)\s+(\w+)/,
+      ],
+     ],
+     [
+      [
+       "NetWare/config_H.??",
+       "Porting/config.sh",
+       "plan9/config_h.sample",
+       "win32/config_H.??",
+      ],
+      qr{^(?:\Q/*\E)?#(?:define|undef)\s+(\w+)},
+     ],
+     [
+      [
+       "configure.com",
+      ],
+      qr{^(\w+)="(?:define|undef)"},
+     ],
+    );
+
+{
+  print STDERR "$0: Looking for symbols...\n";
+  for my $pat (@PAT) {
+    for my $fn (map { glob($_) } @{ $pat->[0] }) {
+      if (open(my $fh, $fn)) {
+        while (<$fh>) {
+          for my $p (@$pat) {
+            for my $sym (/$p/g) {
+              $SYM{$sym}{$fn}++;
+            }
+          }
+        }
+      }
+    }
+  }
+}
+
+printf(STDERR "$0: Found %d symbols\n", scalar keys %SYM);
+
+print STDERR "$0: Looking for their uses...\n";
+
+# Much too noisy grepping.
+delete $SYM{'_'};
+delete $SYM{'const'};
+
+my $SYM = join("|", sort { length($b) <=> length($a) || $a cmp $b } keys %SYM);
+
+open(my $mani, "MANIFEST") or die "$0: Failed to open MANIFEST\n";
+
+my %found;
+while (<$mani>) {
+  if (/^(\S+)\s+/) {
+    my $fn = $1;
+    # Skip matches from the config files themselves,
+    # from metaconfig generated files that refer to
+    # the config symbols, and from pods.
+    next if $fn =~ m{^(?:config_h.SH|Configure|configure\.com|Porting/(?:config|Glossary)|(?:NetWare|plan9|win32)/(?:config|(?:GNU)?[Mm]akefile)|uconfig)|\.pod$};
+    open my $fh, $fn or die qq[$0: Failed to open $fn: $!];
+    while (<$fh>) {
+      while (/\b($SYM)\b/go) {
+        $found{$1}{$fn}++;
+      }
+    }
+  }
+}
+
+for my $sym (sort keys %SYM) {
+  if (exists $found{$sym}) {
+    my @found = keys %{$found{$sym}};
+    print "$sym\t", join(" ", sort @found), "\n";
+  } else {
+    print "$sym\n";
+  }
+}
index a0c91e0..4504c52 100644 (file)
@@ -38,6 +38,7 @@ Porting/checkAUTHORS.pl
 Porting/checkURL.pl
 Porting/checkVERSION.pl
 Porting/checkansi.pl
+Porting/checkcfguse.pl
 Porting/checkcfgvar.pl
 Porting/checkpodencoding.pl
 Porting/cmpVERSION.pl