summaryrefslogtreecommitdiff
path: root/Porting/checkcfgvar.pl
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2011-09-16 19:01:33 +0200
committerNicholas Clark <nick@ccl4.org>2011-09-21 10:40:58 +0200
commit7ee20c719ab9b20eb24e3516e40805ff970cfe4a (patch)
tree64336465fbb8ab3160cdcf7a153f5404e834aa4e /Porting/checkcfgvar.pl
parent79681fc5b8f41f8bd308aa52861190289a2c9299 (diff)
downloadperl-7ee20c719ab9b20eb24e3516e40805ff970cfe4a.tar.gz
Add a --regen option to checkcfgvar.pl to regenerate config files.
Verify that the section of config file containing probed files is sorted lexically. If --regen is used, updated the file on disk with a correctly sorted version. (Except for configure.com, which has a different structure not amenable to automatic analysis and update, hence still has to be updated manually.) Ensure all config files are correctly sorted.
Diffstat (limited to 'Porting/checkcfgvar.pl')
-rwxr-xr-xPorting/checkcfgvar.pl38
1 files changed, 37 insertions, 1 deletions
diff --git a/Porting/checkcfgvar.pl b/Porting/checkcfgvar.pl
index ae1af6bc03..00967f223f 100755
--- a/Porting/checkcfgvar.pl
+++ b/Porting/checkcfgvar.pl
@@ -16,18 +16,25 @@ use autodie;
sub usage
{
my $err = shift and select STDERR;
- print "usage: $0 [--list]\n";
+ print "usage: $0 [--list] [--regen]\n";
exit $err;
} # usage
use Getopt::Long;
my $opt_l = 0;
+my $opt_r = 0;
GetOptions (
"help|?" => sub { usage (0); },
"l|list!" => \$opt_l,
+ "regen" => \$opt_r,
) or usage (1);
+require 'regen/regen_lib.pl' if $opt_r;
+
my $MASTER_CFG = "config_h.SH";
+# Inclusive bounds on the main part of the file, $section == 1 below:
+my $first = qr/^Author=/;
+my $last = qr/^zip=/;
my @CFG = (
# we check from MANIFEST whether they are expected to be present.
@@ -81,6 +88,8 @@ for my $cfg (sort @CFG) {
next;
}
my %cfg;
+ my $section = 0;
+ my @lines;
open my $fh, '<', $cfg;
@@ -94,7 +103,16 @@ for my $cfg (sort @CFG) {
}
} else {
while (<$fh>) {
+ if ($_ =~ $first) {
+ die "$cfg:$.:section=$section:$_" unless $section == 0;
+ $section = 1;
+ }
+ push @{$lines[$section]}, $_;
next if /^\#/ || /^\s*$/ || /^\:/;
+ if ($_ =~ $last) {
+ die "$cfg:$.:section=$section:$_" unless $section == 1;
+ $section = 2;
+ }
# foo='bar'
# foo=bar
# (optionally with a trailing comment)
@@ -108,6 +126,19 @@ for my $cfg (sort @CFG) {
close $fh;
my $problems;
+ if ($cfg ne 'configure.com') {
+ if (join("", @{$lines[1]}) ne join("", sort @{$lines[1]})) {
+ ++$problems;
+ if ($opt_r) {
+ @{$lines[1]} = sort @{$lines[1]};
+ } elsif ($opt_l) {
+ print "$cfg\n";
+ }
+ else {
+ print "$cfg: unsorted\n";
+ }
+ }
+ }
for my $v (@MASTER_CFG) {
exists $cfg{$v} and next;
if ($opt_l) {
@@ -118,4 +149,9 @@ for my $cfg (sort @CFG) {
print "$cfg: missing '$v'\n";
}
}
+ if ($problems && $opt_r) {
+ my $fh = open_new($cfg);
+ print $fh @{$_} foreach @lines;
+ close_and_rename($fh);
+ }
}