From 8852f3ac50955266b930f1d05eb4b25fe090f42b Mon Sep 17 00:00:00 2001 From: "rhelmer%mozilla.com" Date: Tue, 17 Apr 2007 22:49:31 +0000 Subject: [PATCH] config bumper b=371325 r=preed --- tools/release/Bootstrap/Config.pm | 73 ++++++++++++++++++++++++++++++- tools/release/t/test.pl | 10 +++++ 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/tools/release/Bootstrap/Config.pm b/tools/release/Bootstrap/Config.pm index a08befdcc9e..33354488576 100644 --- a/tools/release/Bootstrap/Config.pm +++ b/tools/release/Bootstrap/Config.pm @@ -6,6 +6,7 @@ package Bootstrap::Config; use strict; use POSIX "uname"; +use File::Copy qw(move); # shared static config my %config; @@ -30,7 +31,7 @@ sub new { sub Parse { my $this = shift; - open (CONFIG, "< bootstrap.cfg") + open(CONFIG, "< bootstrap.cfg") || die("Can't open config file bootstrap.cfg"); while () { @@ -42,7 +43,7 @@ sub Parse { my ($var, $value) = split(/\s*=\s*/, $_, 2); $config{$var} = $value; } - close CONFIG; + close(CONFIG); } ## @@ -162,4 +163,72 @@ sub SystemInfo { } } +## +# Bump - modifies config files +# +# Searches and replaces lines of the form: +# # CONFIG: $BuildTag = '%productTag%_RELEASE'; +# $BuildTag = 'FIREFOX_1_5_0_9_RELEASE'; +# +# The comment containing "CONFIG:" is parsed, and the value in between %% +# is treated as the key. The next line will be overwritten by the value +# matching this key in the private %config hash. +# +# If any of the requested keys are not found, this function calls die(). +## + +sub Bump { + my $this = shift; + my %args = @_; + + my $config = new Bootstrap::Config(); + + my $configFile = $args{'configFile'}; + if (! defined($configFile)) { + die('ASSERT: Bootstrap::Config::Bump - configFile is a required argument'); + } + + my $tmpFile = $configFile . '.tmp'; + + open(INFILE, "< $configFile") + or die ("Bootstrap::Config::Bump - Could not open $configFile for reading: $!"); + open(OUTFILE, "> $tmpFile") + or die ("Bootstrap::Config::Bump - Could not open $tmpFile for writing: $!"); + + my $skipNextLine = 0; + foreach my $line () { + if ($skipNextLine) { + $skipNextLine = 0; + next; + } elsif ($line =~ /^# CONFIG:\s+/) { + print OUTFILE $line; + $skipNextLine = 1; + my $interpLine = $line; + $interpLine =~ s/^#\s+CONFIG:\s+//; + foreach my $variable (grep(/%\w+\-*%/, split(/\s+/, $line))) { + my $key = $variable; + if (! ($key =~ s/.*%(\w+\-*)%.*/$1/g)) { + die("ASSERT: could not parse $variable"); + } + + if (! $config->Exists(var => $key)) { + die("ASSERT: no replacement found for $key"); + } + my $value = $config->Get(var => $key); + $interpLine =~ s/\%$key\%/$value/g; + } + print OUTFILE $interpLine; + } else { + print OUTFILE $line; + } + } + + close(INFILE) or die ("Bootstrap::Config::Bump - Could not close $configFile for reading: $!"); + close(OUTFILE) or die ("Bootstrap::Config::Bump - Could not close $tmpFile for writing: $!"); + + move($tmpFile, $configFile) + or die("Cannot rename $tmpFile to $configFile: $!"); + +} + 1; diff --git a/tools/release/t/test.pl b/tools/release/t/test.pl index 0c4fbfb188f..b043078eebe 100755 --- a/tools/release/t/test.pl +++ b/tools/release/t/test.pl @@ -3,6 +3,7 @@ use strict; use Bootstrap::Step; use Bootstrap::Config; use t::Bootstrap::Step::Dummy; +use MozBuild::Util; my $config = new Bootstrap::Config(); unless ($config->Exists(sysvar => 'buildDir')) { @@ -23,3 +24,12 @@ $step->Verify(); $step->Push(); $step->Announce(); +eval { + $config->Bump( + configFile => 't/tinder-config.pl', + ); +}; + +if ($@) { + print("FAIL: should not have died, all matches\n"); +}