зеркало из https://github.com/mozilla/pjs.git
support variable fallback b=372757 r=preed r=cf
This commit is contained in:
Родитель
5754dbd865
Коммит
3447cc03fa
|
@ -5,6 +5,7 @@
|
|||
package Bootstrap::Config;
|
||||
|
||||
use strict;
|
||||
use POSIX "uname";
|
||||
|
||||
# shared static config
|
||||
my %config;
|
||||
|
@ -44,31 +45,121 @@ sub Parse {
|
|||
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
|
||||
# Get(sysvar => "buildDir") and win32_buildDir exists, the value of
|
||||
# win32_buildDir will be returned. If not, the value of buildDir will
|
||||
# be returned. Otherwise, the die() assertion will be hit.
|
||||
##
|
||||
|
||||
sub Get {
|
||||
my $this = shift;
|
||||
|
||||
my %args = @_;
|
||||
my $var = $args{'var'};
|
||||
# sysvar will attempt to prepend the OS name to the requested var
|
||||
my $sysvar = $args{'sysvar'};
|
||||
|
||||
die "ASSERT: Bootstep::Config::Get(): null var requested" if (not
|
||||
defined($args{'var'}));
|
||||
if ((! defined($args{'var'})) && (! defined($args{'sysvar'}))) {
|
||||
die "ASSERT: Bootstep::Config::Get(): null var requested";
|
||||
} elsif ((defined($args{'var'})) && (defined($args{'sysvar'}))) {
|
||||
die "ASSERT: Bootstep::Config::Get(): both var and sysvar requested";
|
||||
}
|
||||
|
||||
if ($this->Exists(var => $var)) {
|
||||
if (defined($args{'sysvar'})) {
|
||||
# look for a system specific var first
|
||||
my $osname = $this->SystemInfo(var => 'osname');
|
||||
my $sysvarOverride = $osname . '_' . $sysvar;
|
||||
|
||||
if ($this->Exists(var => $sysvarOverride)) {
|
||||
return $config{$sysvarOverride};
|
||||
} elsif ($this->Exists(var => $sysvar)) {
|
||||
return $config{$sysvar};
|
||||
} else {
|
||||
die("No such system config variable: $sysvar");
|
||||
}
|
||||
} elsif ($this->Exists(var => $var)) {
|
||||
return $config{$var};
|
||||
} else {
|
||||
die("No such config variable: $var\n");
|
||||
die("No such config variable: $var");
|
||||
}
|
||||
}
|
||||
|
||||
##
|
||||
# Exists checks to see if a config variable exists.
|
||||
# Returns boolean (1 or 0)
|
||||
#
|
||||
# This method supports system-specific overrides, or "sysvar"s.
|
||||
# For example, if a caller is on win32 and does
|
||||
# Exists(sysvar => "win32_buildDir") and only buildDir exists, a 0
|
||||
# will be returned. There is no "fallback" as in the case of Get.
|
||||
##
|
||||
|
||||
sub Exists {
|
||||
my $this = shift;
|
||||
my %args = @_;
|
||||
my $var = $args{'var'};
|
||||
# sysvar will attempt to prepend the OS name to the requested var
|
||||
my $sysvar = $args{'sysvar'};
|
||||
|
||||
die "ASSERT: Bootstep::Config::Exists(): null var requested" if (not
|
||||
defined($args{'var'}));
|
||||
if ((! defined($args{'var'})) && (! defined($args{'sysvar'}))) {
|
||||
die "ASSERT: Bootstep::Config::Get(): null var requested";
|
||||
} elsif ((defined($args{'var'})) && (defined($args{'sysvar'}))) {
|
||||
die "ASSERT: Bootstep::Config::Get(): both var and sysvar requested";
|
||||
}
|
||||
|
||||
if (defined($args{'sysvar'})) {
|
||||
# look for a system specific var first
|
||||
my $osname = $this->SystemInfo(var => 'osname');
|
||||
my $sysvarOverride = $osname . '_' . $sysvar;
|
||||
|
||||
if (exists($config{$sysvarOverride})) {
|
||||
return 1;
|
||||
} elsif (exists($config{$sysvar})) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return exists($config{$var});
|
||||
}
|
||||
}
|
||||
|
||||
sub SystemInfo {
|
||||
my $this = shift;
|
||||
my %args = @_;
|
||||
|
||||
my $var = $args{'var'};
|
||||
return exists($config{$var});
|
||||
|
||||
my ($sysname, $hostname, $release, $version, $machine ) = uname;
|
||||
|
||||
if ($var eq 'sysname') {
|
||||
return $sysname;
|
||||
} elsif ($var eq 'hostname') {
|
||||
return $hostname;
|
||||
} elsif ($var eq 'release') {
|
||||
return $release;
|
||||
} elsif ($var eq 'version') {
|
||||
return $version;
|
||||
} elsif ($var eq 'machine') {
|
||||
return $machine;
|
||||
} elsif ($var eq 'osname') {
|
||||
if ($sysname =~ /cygwin/i) {
|
||||
return 'win32';
|
||||
} elsif ($sysname =~ /darwin/i) {
|
||||
return 'macosx';
|
||||
} elsif ($sysname =~ /linux/i) {
|
||||
return 'linux';
|
||||
} else {
|
||||
die("Unrecognized OS: $sysname");
|
||||
}
|
||||
} else {
|
||||
die("No system info named $var");
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -10,10 +10,10 @@ sub Execute {
|
|||
my $this = shift;
|
||||
|
||||
my $config = new Bootstrap::Config();
|
||||
my $buildDir = $config->Get(var => 'buildDir');
|
||||
my $buildDir = $config->Get(sysvar => 'buildDir');
|
||||
my $productTag = $config->Get(var => 'productTag');
|
||||
my $rc = $config->Get(var => 'rc');
|
||||
my $buildPlatform = $config->Get(var => 'buildPlatform');
|
||||
my $buildPlatform = $config->Get(sysvar => 'buildPlatform');
|
||||
my $logDir = $config->Get(var => 'logDir');
|
||||
my $rcTag = $productTag . '_RC' . $rc;
|
||||
|
||||
|
|
|
@ -12,15 +12,15 @@ sub Execute {
|
|||
my $this = shift;
|
||||
|
||||
my $config = new Bootstrap::Config();
|
||||
my $buildDir = $config->Get(var => 'l10n_buildDir');
|
||||
my $l10n_buildDir = $config->Get(sysvar => 'l10n_buildDir');
|
||||
my $productTag = $config->Get(var => 'productTag');
|
||||
my $rc = $config->Get(var => 'rc');
|
||||
my $logDir = $config->Get(var => 'logDir');
|
||||
my $buildPlatform = $config->Get(var => 'buildPlatform');
|
||||
my $buildPlatform = $config->Get(sysvar => 'buildPlatform');
|
||||
my $rcTag = $productTag . '_RC' . $rc;
|
||||
|
||||
my $buildLog = catfile($logDir, 'repack_' . $rcTag . '-build-l10n.log');
|
||||
my $lastBuilt = catfile($buildDir, $buildPlatform, 'last-built');
|
||||
my $lastBuilt = catfile($l10n_buildDir, $buildPlatform, 'last-built');
|
||||
unlink($lastBuilt)
|
||||
or $this->Log(msg => "Cannot unlink last-built file $lastBuilt: $!");
|
||||
$this->Log(msg => "Unlinked $lastBuilt");
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
test:
|
||||
for f in release t/test.pl `find . -name "*.pm"`; do perl -c $$f; done
|
||||
if [ -f t/test.log ]; then rm t/test.log; fi
|
||||
if [ ! -f bootstrap.cfg ]; then cp bootstrap.cfg.example bootstrap.cfg; fi
|
||||
./t/test.pl
|
||||
|
||||
stage:
|
||||
|
|
|
@ -1,8 +1,20 @@
|
|||
#!/usr/bin/perl -w
|
||||
use strict;
|
||||
use Bootstrap::Step;
|
||||
use Bootstrap::Config;
|
||||
use t::Bootstrap::Step::Dummy;
|
||||
#use t::Bootstrap::Step::Tag;
|
||||
|
||||
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";
|
||||
}
|
||||
my $sysname = $config->SystemInfo(var => 'sysname');
|
||||
unless ($sysname) {
|
||||
print "FAIL: sysname should exist\n";
|
||||
}
|
||||
|
||||
my $step = t::Bootstrap::Step::Dummy->new();
|
||||
|
||||
|
@ -11,6 +23,3 @@ $step->Verify();
|
|||
$step->Push();
|
||||
$step->Announce();
|
||||
|
||||
#$step = t::Bootstrap::Step::Tag->new();
|
||||
|
||||
#$step->Execute();
|
||||
|
|
Загрузка…
Ссылка в новой задаче