Advertisement
ScratchMonkey

MakeSvnVersion.pl

Jul 4th, 2022
977
0
86 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.74 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use File::Basename;
  4. my $dirname = dirname(__FILE__);
  5. my $outputfile = "$dirname/svnversion.h";
  6. my $svnversion = `svnversion $dirname/../.. 2>&1`;
  7. chomp $svnversion;
  8. my $originalcontent;
  9. if (-e $outputfile) {
  10.         local($/, *FH);
  11.         open(FH, $outputfile) or die("unable to open $outputfile to read");
  12.         $originalcontent = <FH>;
  13. } else {
  14.         print STDERR "Creating $outputfile\n";
  15.         $originalcontent = "";
  16. }
  17. my $newcontent = "";
  18. # this variant can potentially have mixed version info so not usable as
  19. # a number (useful for private build strings)
  20. $newcontent .= "#define SVNVERSION_FULL \"$svnversion\"\n";
  21. # for exported directory, use 0 for revision
  22. if ("Unversioned directory" eq $svnversion) { $svnversion = "0"; }
  23. # use the last number found, unadorned, as the actual number
  24. unless ($svnversion =~ m/((\d+):)?(\d+)([A-Z]*)/) {
  25.         print STDERR "Attempted command: svnversion $dirname/../..\n";
  26.         my $where = `where svnversion`;
  27.         print STDERR "where svnversion: $where\n";
  28.         die("'$svnversion' fails to match m/((\d+):)?(\d+)([A-Z]*)/)");
  29. }
  30. my ($first_with_colon, $first, $last, $suffix) = $svnversion =~ m/((\d+):)?(\d+)([A-Z]*)/;
  31. # print STDERR "svnversion = $svnversion | first = $first | last = $last | suffix = $suffix\n";
  32. if ("" eq $svnversion) {
  33.         $last = 0; # to create valid value for macro, but die at end of script to fail this project build
  34. }
  35. $newcontent .= "#define SVNVERSION $last\n";
  36. $newcontent .= "#define FULL_VERSION_STRING \"1.0.$last\"\n";
  37. if (($first_with_colon ne "") || ($suffix ne "")) {
  38.         # set the flag to tell inspectors that special build string is
  39.         # present
  40.         $newcontent .= "#define MY_FF_SPECIAL VS_FF_SPECIALBUILD\n";
  41.         $newcontent .= "#define MY_SPECIAL_BUILD SVNVERSION_FULL\n";
  42.         # issue mixed revision warning both when creating the header
  43.         # and when the header is included in other files, to make sure
  44.         # the warning gets seen
  45.         my $warning = "WARNING: MIXED REVISION $svnversion. Commit changes and update tree before release.";
  46.         $newcontent .= "#pragma message (\"$warning\")\n";
  47.         print "$warning\n";
  48. } elsif (0 == $last) {
  49.         $newcontent .= "#define MY_FF_SPECIAL VS_FF_SPECIALBUILD\n";
  50.         $newcontent .= "#define MY_SPECIAL_BUILD \"exported\"\n";
  51. } else {
  52.         $newcontent .= "#define MY_FF_SPECIAL 0\n";
  53.         $newcontent .= "#define MY_SPECIAL_BUILD \"\"\n";
  54. }
  55. # print $newcontent;
  56. if ($newcontent ne $originalcontent) {
  57.         print "Writing new $outputfile\n";
  58.         print STDERR $newcontent;
  59.         open(FILE, ">$outputfile");
  60.         print FILE $newcontent;
  61.         close(FILE);
  62. } else {
  63.         print "No version change\n";
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement