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