small change to the version changer for release builds

This commit is contained in:
David Anderson 2007-10-26 01:42:35 +00:00
parent 3750788893
commit efbba0a909

View File

@ -1,185 +1,195 @@
#!/usr/bin/perl #!/usr/bin/perl
our %arguments = our %arguments =
( (
'config' => 'modules.versions', 'config' => 'modules.versions',
'major' => '1', 'major' => '1',
'minor' => '0', 'minor' => '0',
'revision' => '0', 'revision' => '0',
'build' => undef, 'build' => undef,
'svnrev' => 'global', 'svnrev' => 'global',
'path' => '', 'path' => '',
'modules' => '', 'modules' => '',
); );
my $arg; my $arg;
foreach $arg (@ARGV) foreach $arg (@ARGV)
{ {
$arg =~ s/--//; $arg =~ s/--//;
@arg = split(/=/, $arg); @arg = split(/=/, $arg);
$arguments{$arg[0]} = $arg[1]; $arguments{$arg[0]} = $arg[1];
} }
our (%allowed); our (%allowed);
if ($arguments{'modules'} ne "") if ($arguments{'modules'} ne "")
{ {
my @l = split(/,/, $arguments{'modules'}); my @l = split(/,/, $arguments{'modules'});
my $i; my $i;
for ($i=0; $i<=$#l; $i++) for ($i=0; $i<=$#l; $i++)
{ {
$allowed{$l[$i]} = 1; $allowed{$l[$i]} = 1;
} }
} else { } else {
$allowed{'*'} = 1; $allowed{'*'} = 1;
} }
#Set up path info #Set up path info
if ($arguments{'path'} ne "") if ($arguments{'path'} ne "")
{ {
if (!(-d $arguments{'path'})) if (!(-d $arguments{'path'}))
{ {
die "Unable to find path: " . $arguments{'path'} ."\n"; die "Unable to find path: " . $arguments{'path'} ."\n";
} }
chdir($arguments{'path'}); chdir($arguments{'path'});
} }
if (!open(CONFIG, $arguments{'config'})) if (!open(CONFIG, $arguments{'config'}))
{ {
die "Unable to open config file for reading: " . $arguments{'config'} . "\n"; die "Unable to open config file for reading: " . $arguments{'config'} . "\n";
} }
our %modules; our %modules;
my $cur_module = undef; my $cur_module = undef;
my $line; my $line;
while (<CONFIG>) while (<CONFIG>)
{ {
chomp; chomp;
$line = $_; $line = $_;
if ($line =~ /^\[([^\]]+)\]$/) if ($line =~ /^\[([^\]]+)\]$/)
{ {
$cur_module = $1; $cur_module = $1;
next; next;
} }
if (!$cur_module) if (!$cur_module)
{ {
next; next;
} }
if ($line =~ /^([^=]+) = (.+)$/) if ($line =~ /^([^=]+) = (.+)$/)
{ {
$modules{$cur_module}{$1} = $2; $modules{$cur_module}{$1} = $2;
} }
} }
close(CONFIG); close(CONFIG);
#Copy global configuration options... #Copy global configuration options...
if (exists($modules{'PRODUCT'})) if (exists($modules{'PRODUCT'}))
{ {
if (exists($modules{'PRODUCT'}{'major'})) if (exists($modules{'PRODUCT'}{'major'}))
{ {
$arguments{'major'} = $modules{'PRODUCT'}{'major'}; $arguments{'major'} = $modules{'PRODUCT'}{'major'};
} }
if (exists($modules{'PRODUCT'}{'minor'})) if (exists($modules{'PRODUCT'}{'minor'}))
{ {
$arguments{'minor'} = $modules{'PRODUCT'}{'minor'}; $arguments{'minor'} = $modules{'PRODUCT'}{'minor'};
} }
if (exists($modules{'PRODUCT'}{'revision'})) if (exists($modules{'PRODUCT'}{'revision'}))
{ {
$arguments{'revision'} = $modules{'PRODUCT'}{'revision'}; $arguments{'revision'} = $modules{'PRODUCT'}{'revision'};
} }
if (exists($modules{'PRODUCT'}{'svnrev'})) if (exists($modules{'PRODUCT'}{'svnrev'}))
{ {
$arguments{'svnrev'} = $modules{'PRODUCT'}{'svnrev'}; $arguments{'svnrev'} = $modules{'PRODUCT'}{'svnrev'};
} }
} }
#Get the global SVN revision if we have none #Get the global SVN revision if we have none
my $rev; my $rev;
if ($arguments{'build'} == undef) if ($arguments{'build'} == undef)
{ {
$rev = GetRevision(undef); $rev = GetRevision(undef);
} else { } else {
$rev = int($arguments{'build'}); $rev = int($arguments{'build'});
} }
my $major = $arguments{'major'}; my $major = $arguments{'major'};
my $minor = $arguments{'minor'}; my $minor = $arguments{'minor'};
my $revision = $arguments{'revision'}; my $revision = $arguments{'revision'};
my $svnrev = $arguments{'svnrev'}; my $svnrev = $arguments{'svnrev'};
#Go through everything now #Go through everything now
my $mod_i; my $mod_i;
while ( ($cur_module, $mod_i) = each(%modules) ) while ( ($cur_module, $mod_i) = each(%modules) )
{ {
#Skip the magic one #Skip the magic one
if ($cur_module eq "PRODUCT") if ($cur_module eq "PRODUCT")
{ {
next; next;
} }
if (!$allowed{'*'} && !$allowed{$cur_module}) if (!$allowed{'*'} && !$allowed{$cur_module})
{ {
next; next;
} }
#Prepare path #Prepare path
my %mod = %{$mod_i}; my %mod = %{$mod_i};
my $infile = $mod{'in'}; my $infile = $mod{'in'};
my $outfile = $mod{'out'}; my $outfile = $mod{'out'};
if ($mod{'folder'}) if ($mod{'folder'})
{ {
if (!(-d $mod{'folder'})) if (!(-d $mod{'folder'}))
{ {
die "Folder " . $mod{'folder'} . " not found.\n"; die "Folder " . $mod{'folder'} . " not found.\n";
} }
$infile = $mod{'folder'} . '/' . $infile; $infile = $mod{'folder'} . '/' . $infile;
$outfile = $mod{'folder'} . '/' . $outfile; $outfile = $mod{'folder'} . '/' . $outfile;
} }
if (!(-f $infile)) if (!(-f $infile))
{ {
die "File $infile is not a file.\n"; die "File $infile is not a file.\n";
} }
my $global_rev = $rev; my $global_rev = $rev;
my $local_rev = GetRevision($mod{'folder'}); my $local_rev;
if ($arguments{'svnrev'} eq 'local')
{ if ($arguments{'build'} == undef)
$global_rev = $local_rev; {
} $local_rev = GetRevision($mod{'folder'});
#Start rewriting }
open(INFILE, $infile) or die "Could not open file for reading: $infile\n"; else
open(OUTFILE, '>'.$outfile) or die "Could not open file for writing: $outfile\n"; {
while (<INFILE>) $local_rev = $rev;
{ }
s/\$PMAJOR\$/$major/g;
s/\$PMINOR\$/$minor/g; if ($arguments{'svnrev'} eq 'local')
s/\$PREVISION\$/$revision/g; {
s/\$GLOBAL_BUILD\$/$rev/g; $global_rev = $local_rev;
s/\$LOCAL_BUILD\$/$local_rev/g; }
print OUTFILE $_; #Start rewriting
} open(INFILE, $infile) or die "Could not open file for reading: $infile\n";
close(OUTFILE); open(OUTFILE, '>'.$outfile) or die "Could not open file for writing: $outfile\n";
close(INFILE); while (<INFILE>)
} {
s/\$PMAJOR\$/$major/g;
sub GetRevision s/\$PMINOR\$/$minor/g;
{ s/\$PREVISION\$/$revision/g;
my ($path)=(@_); s/\$GLOBAL_BUILD\$/$rev/g;
my $rev; s/\$LOCAL_BUILD\$/$local_rev/g;
if (!$path) print OUTFILE $_;
{ }
$rev = `svnversion --committed`; close(OUTFILE);
} else { close(INFILE);
$rev = `svnversion --committed $path`; }
}
if ($rev =~ /exported/) sub GetRevision
{ {
die "Path specified is not a working copy\n"; my ($path)=(@_);
} elsif ($rev =~ /(\d+):(\d+)/) { my $rev;
$rev = int($2); if (!$path)
} elsif ($rev =~ /(\d+)/) { {
$rev = int($1); $rev = `svnversion --committed`;
} else { } else {
die "Unknown svnversion response: $rev\n"; $rev = `svnversion --committed $path`;
} }
return $rev; if ($rev =~ /exported/)
} {
die "Path specified is not a working copy\n";
} elsif ($rev =~ /(\d+):(\d+)/) {
$rev = int($2);
} elsif ($rev =~ /(\d+)/) {
$rev = int($1);
} else {
die "Unknown svnversion response: $rev\n";
}
return $rev;
}