--- a/tools/release/Bootstrap/Config.pm
+++ b/tools/release/Bootstrap/Config.pm
@@ -1,16 +1,17 @@
#
# Config object for release automation
#
package Bootstrap::Config;
use strict;
use POSIX "uname";
+use File::Copy qw(move);
# shared static config
my %config;
# single shared instance
my $singleton = undef;
sub new {
@@ -25,29 +26,29 @@ sub new {
$singleton = $this;
return $this;
}
sub Parse {
my $this = shift;
- open (CONFIG, "< bootstrap.cfg")
+ open(CONFIG, "< bootstrap.cfg")
|| die("Can't open config file bootstrap.cfg");
while (<CONFIG>) {
chomp; # no newline
s/#.*//; # no comments
s/^\s+//; # no leading white
s/\s+$//; # no trailing white
next unless length; # anything left?
my ($var, $value) = split(/\s*=\s*/, $_, 2);
$config{$var} = $value;
}
- close CONFIG;
+ close(CONFIG);
}
##
# Get checks to see if a variable exists and returns it.
# Returns scalar
#
# This method supports system-specific overrides, or "sysvar"s.
# For example, if a caller is on win32 and does
@@ -157,9 +158,77 @@ sub SystemInfo {
} else {
die("Unrecognized OS: $sysname");
}
} else {
die("No system info named $var");
}
}
+##
+# 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 (<INFILE>) {
+ 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;
--- a/tools/release/t/test.pl
+++ b/tools/release/t/test.pl
@@ -1,13 +1,14 @@
#!/usr/bin/perl -w
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')) {
print "FAIL: buildDir should exist\n";
}
unless ($config->Get(sysvar => 'buildDir')) {
print "FAIL: buildDir should be retrievable\n";
}
@@ -18,8 +19,17 @@ unless ($sysname) {
my $step = t::Bootstrap::Step::Dummy->new();
$step->Execute();
$step->Verify();
$step->Push();
$step->Announce();
+eval {
+ $config->Bump(
+ configFile => 't/tinder-config.pl',
+ );
+};
+
+if ($@) {
+ print("FAIL: should not have died, all matches\n");
+}