Updated versionchanger.pl for Mercurial, FINALLY fixed its whitespace.

This commit is contained in:
David Anderson 2008-09-14 16:26:38 -05:00
parent 326e8ee205
commit 8fcecf3dec

View File

@ -1,169 +1,140 @@
#!/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', 'path' => '',
'path' => '', 'buildstring' => '',
'buildstring' => '', );
);
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]; }
}
#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'}))
{ #Get the global SVN revision if we have none
$arguments{'svnrev'} = $modules{'PRODUCT'}{'svnrev'}; my $rev;
} if ($arguments{'build'} == undef)
} {
my ($text);
#Get the global SVN revision if we have none $text = `hg identif -n -i`;
my $rev; chomp $text;
if ($arguments{'build'} == undef) $text =~ s/\+//g;
{ my ($id,$num) = split(/ /, $text);
$rev = GetRevision(undef); $rev = "$num:$id";
} else { }
$rev = int($arguments{'build'}); else
} {
$rev = int($arguments{'build'});
my $major = $arguments{'major'}; }
my $minor = $arguments{'minor'};
my $revision = $arguments{'revision'}; my $major = $arguments{'major'};
my $svnrev = $arguments{'svnrev'}; my $minor = $arguments{'minor'};
my $buildstr = $arguments{'buildstring'}; my $revision = $arguments{'revision'};
my $buildstr = $arguments{'buildstring'};
#Go through everything now
my $mod_i; #Go through everything now
while ( ($cur_module, $mod_i) = each(%modules) ) my $mod_i;
{ while ( ($cur_module, $mod_i) = each(%modules) )
#Skip the magic one {
if ($cur_module eq "PRODUCT") #Skip the magic one
{ if ($cur_module eq "PRODUCT")
next; {
} next;
#Prepare path }
my %mod = %{$mod_i}; #Prepare path
my $infile = $mod{'in'}; my %mod = %{$mod_i};
my $outfile = $mod{'out'}; my $infile = $mod{'in'};
if ($mod{'folder'}) my $outfile = $mod{'out'};
{ 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; }
$outfile = $mod{'folder'} . '/' . $outfile; $infile = $mod{'folder'} . '/' . $infile;
} $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 $local_rev = GetRevision($mod{'folder'}); #Start rewriting
if ($arguments{'svnrev'} eq 'local') open(INFILE, $infile) or die "Could not open file for reading: $infile\n";
{ open(OUTFILE, '>'.$outfile) or die "Could not open file for writing: $outfile\n";
$global_rev = $local_rev; while (<INFILE>)
} {
#Start rewriting s/\$PMAJOR\$/$major/g;
open(INFILE, $infile) or die "Could not open file for reading: $infile\n"; s/\$PMINOR\$/$minor/g;
open(OUTFILE, '>'.$outfile) or die "Could not open file for writing: $outfile\n"; s/\$PREVISION\$/$revision/g;
while (<INFILE>) s/\$BUILD_ID\$/$rev/g;
{ s/\$BUILD_STRING\$/$buildstr/g;
s/\$PMAJOR\$/$major/g; print OUTFILE $_;
s/\$PMINOR\$/$minor/g; }
s/\$PREVISION\$/$revision/g; close(OUTFILE);
s/\$GLOBAL_BUILD\$/$rev/g; close(INFILE);
s/\$LOCAL_BUILD\$/$local_rev/g; }
s/\$BUILD_ID\$/$rev/g;
s/\$BUILD_STRING\$/$buildstr/g;
print OUTFILE $_;
}
close(OUTFILE);
close(INFILE);
}
sub GetRevision
{
my ($path)=(@_);
my $rev;
if (!$path)
{
$rev = `svnversion --committed`;
} else {
$rev = `svnversion --committed $path`;
}
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;
}