From b9da5d8a23ee34bf8330d26cc5541489a90a38a7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 3 Mar 2007 07:54:32 +0000 Subject: [PATCH] added the holy version changer script! --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40573 --- tools/versionchanger.pl | 166 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 tools/versionchanger.pl diff --git a/tools/versionchanger.pl b/tools/versionchanger.pl new file mode 100644 index 00000000..63004d38 --- /dev/null +++ b/tools/versionchanger.pl @@ -0,0 +1,166 @@ +#!/usr/bin/perl + +our %arguments = +( + 'config' => 'modules.versions', + 'major' => '1', + 'minor' => '0', + 'revision' => '0', + 'build' => undef, + 'svnrev' => 'global', + 'path' => '', +); + +my $arg; +foreach $arg (@ARGV) +{ + $arg =~ s/--//; + @arg = split(/=/, $arg); + $arguments{$arg[0]} = $arg[1]; +} + +#Set up path info +if ($arguments{'path'} ne "") +{ + if (!(-d $arguments{'path'})) + { + die "Unable to find path: " . $arguments{'path'} ."\n"; + } + chdir($arguments{'path'}); +} + +if (!open(CONFIG, $arguments{'config'})) +{ + die "Unable to open config file for reading: " . $arguments{'config'} . "\n"; +} + +our %modules; +my $cur_module = undef; +my $line; +while () +{ + chomp; + $line = $_; + if ($line =~ /^\[([^\]]+)\]$/) + { + $cur_module = $1; + next; + } + if (!$cur_module) + { + next; + } + if ($line =~ /^([^=]+) = (.+)$/) + { + $modules{$cur_module}{$1} = $2; + } +} + +close(CONFIG); + +#Copy global configuration options... +if (exists($modules{'PRODUCT'})) +{ + if (exists($modules{'PRODUCT'}{'major'})) + { + $arguments{'major'} = $modules{'PRODUCT'}{'major'}; + } + if (exists($modules{'PRODUCT'}{'minor'})) + { + $arguments{'minor'} = $modules{'PRODUCT'}{'minor'}; + } + if (exists($modules{'PRODUCT'}{'revision'})) + { + $arguments{'revision'} = $modules{'PRODUCT'}{'revision'}; + } + if (exists($modules{'PRODUCT'}{'svnrev'})) + { + $arguments{'svnrev'} = $modules{'PRODUCT'}{'svnrev'}; + } +} + +#Get the global SVN revision if we have none +my $rev; +if ($arguments{'build'} == undef) +{ + $rev = GetRevision(undef); +} else { + $rev = int($arguments{'build'}); +} + +my $major = $arguments{'major'}; +my $minor = $arguments{'minor'}; +my $revision = $arguments{'revision'}; +my $svnrev = $arguments{'svnrev'}; + +#Go through everything now +my $mod_i; +while ( ($cur_module, $mod_i) = each(%modules) ) +{ + #Skip the magic one + if ($cur_module eq "PRODUCT") + { + next; + } + #Prepare path + my %mod = %{$mod_i}; + my $infile = $mod{'in'}; + my $outfile = $mod{'out'}; + if ($mod{'folder'}) + { + if (!(-d $mod{'folder'})) + { + die "Folder " . $mod{'folder'} . " not found.\n"; + } + $infile = $mod{'folder'} . '/' . $infile; + $outfile = $mod{'folder'} . '/' . $outfile; + } + if (!(-f $infile)) + { + die "File $infile is not a file.\n"; + } + my $global_rev = $rev; + my $local_rev = GetRevision($mod{'folder'}); + if ($arguments{'svnrev'} eq 'local') + { + $global_rev = $local_rev; + } + #Start rewriting + 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"; + while () + { + s/\$PMAJOR\$/$major/g; + s/\$PMINOR\$/$minor/g; + s/\$PREVISION\$/$revision/g; + s/\$GLOBAL_BUILD\$/$rev/g; + s/\$LOCAL_BUILD\$/$local_rev/g; + print OUTFILE $_; + } + close(OUTFILE); + close(INFILE); +} + +sub GetRevision +{ + my ($path)=(@_); + my $rev; + if (!$path) + { + $rev = `svnversion --committed`; + } else { + $rev = `svnversion --committed $path`; + } + print "$path $rev\n"; + 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; +}