1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/support/versionchanger.pl Tue Nov 18 02:28:38 2008 -0600
1.3 @@ -0,0 +1,140 @@
1.4 +#!/usr/bin/perl
1.5 +
1.6 +our %arguments =
1.7 +(
1.8 + 'config' => 'modules.versions',
1.9 + 'major' => '1',
1.10 + 'minor' => '0',
1.11 + 'revision' => '0',
1.12 + 'build' => undef,
1.13 + 'path' => '',
1.14 + 'buildstring' => '',
1.15 +);
1.16 +
1.17 +my $arg;
1.18 +foreach $arg (@ARGV)
1.19 +{
1.20 + $arg =~ s/--//;
1.21 + @arg = split(/=/, $arg);
1.22 + $arguments{$arg[0]} = $arg[1];
1.23 +}
1.24 +
1.25 +#Set up path info
1.26 +if ($arguments{'path'} ne "")
1.27 +{
1.28 + if (!(-d $arguments{'path'}))
1.29 + {
1.30 + die "Unable to find path: " . $arguments{'path'} ."\n";
1.31 + }
1.32 + chdir($arguments{'path'});
1.33 +}
1.34 +
1.35 +if (!open(CONFIG, $arguments{'config'}))
1.36 +{
1.37 + die "Unable to open config file for reading: " . $arguments{'config'} . "\n";
1.38 +}
1.39 +
1.40 +our %modules;
1.41 +my $cur_module = undef;
1.42 +my $line;
1.43 +while (<CONFIG>)
1.44 +{
1.45 + chomp;
1.46 + $line = $_;
1.47 + if ($line =~ /^\[([^\]]+)\]$/)
1.48 + {
1.49 + $cur_module = $1;
1.50 + next;
1.51 + }
1.52 + if (!$cur_module)
1.53 + {
1.54 + next;
1.55 + }
1.56 + if ($line =~ /^([^=]+) = (.+)$/)
1.57 + {
1.58 + $modules{$cur_module}{$1} = $2;
1.59 + }
1.60 +}
1.61 +
1.62 +close(CONFIG);
1.63 +
1.64 +#Copy global configuration options...
1.65 +if (exists($modules{'PRODUCT'}))
1.66 +{
1.67 + if (exists($modules{'PRODUCT'}{'major'}))
1.68 + {
1.69 + $arguments{'major'} = $modules{'PRODUCT'}{'major'};
1.70 + }
1.71 + if (exists($modules{'PRODUCT'}{'minor'}))
1.72 + {
1.73 + $arguments{'minor'} = $modules{'PRODUCT'}{'minor'};
1.74 + }
1.75 + if (exists($modules{'PRODUCT'}{'revision'}))
1.76 + {
1.77 + $arguments{'revision'} = $modules{'PRODUCT'}{'revision'};
1.78 + }
1.79 +}
1.80 +
1.81 +#Get the global SVN revision if we have none
1.82 +my $rev;
1.83 +if ($arguments{'build'} == undef)
1.84 +{
1.85 + my ($text);
1.86 + $text = `hg identif -n -i`;
1.87 + chomp $text;
1.88 + $text =~ s/\+//g;
1.89 + my ($id,$num) = split(/ /, $text);
1.90 + $rev = "$num:$id";
1.91 +}
1.92 +else
1.93 +{
1.94 + $rev = int($arguments{'build'});
1.95 +}
1.96 +
1.97 +my $major = $arguments{'major'};
1.98 +my $minor = $arguments{'minor'};
1.99 +my $revision = $arguments{'revision'};
1.100 +my $buildstr = $arguments{'buildstring'};
1.101 +
1.102 +#Go through everything now
1.103 +my $mod_i;
1.104 +while ( ($cur_module, $mod_i) = each(%modules) )
1.105 +{
1.106 + #Skip the magic one
1.107 + if ($cur_module eq "PRODUCT")
1.108 + {
1.109 + next;
1.110 + }
1.111 + #Prepare path
1.112 + my %mod = %{$mod_i};
1.113 + my $infile = $mod{'in'};
1.114 + my $outfile = $mod{'out'};
1.115 + if ($mod{'folder'})
1.116 + {
1.117 + if (!(-d $mod{'folder'}))
1.118 + {
1.119 + die "Folder " . $mod{'folder'} . " not found.\n";
1.120 + }
1.121 + $infile = $mod{'folder'} . '/' . $infile;
1.122 + $outfile = $mod{'folder'} . '/' . $outfile;
1.123 + }
1.124 + if (!(-f $infile))
1.125 + {
1.126 + die "File $infile is not a file.\n";
1.127 + }
1.128 + #Start rewriting
1.129 + open(INFILE, $infile) or die "Could not open file for reading: $infile\n";
1.130 + open(OUTFILE, '>'.$outfile) or die "Could not open file for writing: $outfile\n";
1.131 + while (<INFILE>)
1.132 + {
1.133 + s/\$PMAJOR\$/$major/g;
1.134 + s/\$PMINOR\$/$minor/g;
1.135 + s/\$PREVISION\$/$revision/g;
1.136 + s/\$BUILD_ID\$/$rev/g;
1.137 + s/\$BUILD_STRING\$/$buildstr/g;
1.138 + print OUTFILE $_;
1.139 + }
1.140 + close(OUTFILE);
1.141 + close(INFILE);
1.142 +}
1.143 +