Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
4.5 KiB

  1. #@REM -----------------------------------------------------------------
  2. #@REM
  3. #@REM makebuildname.pl - TSanders ripping off jeremyd code
  4. #@REM generate buildname.txt
  5. #@REM
  6. #@REM Copyright (c) Microsoft Corporation. All rights reserved.
  7. #@REM
  8. #@REM -----------------------------------------------------------------
  9. use strict;
  10. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  11. use lib $ENV{RAZZLETOOLPATH};
  12. use PbuildEnv;
  13. use ParseArgs;
  14. use Logmsg;
  15. sub Usage { print<<USAGE; exit(1) }
  16. makebuildname [-d <alt destination>]
  17. Create the file %_NTPostBLD%\\build_logs\\buildname.txt
  18. USAGE
  19. my($Dest);
  20. parseargs('d:' => \$Dest, '?' => \&Usage);
  21. WriteBuildName($Dest);
  22. sub WriteBuildName($) {
  23. my ($BuildNamePath) = @_;
  24. $BuildNamePath = $ENV{SDXROOT} if(!defined $BuildNamePath);
  25. my $BuildNameFile = $BuildNamePath . "\\BuildName.txt";
  26. if (!-d $BuildNamePath) {
  27. Myerrmsg("can't find build logs directory $BuildNamePath");
  28. return;
  29. }
  30. # make a new buildname each time, idx builds will update
  31. # the __blddate__ file each day during newver.cmd
  32. my $BuildName = &MakeBuildName;
  33. if ($BuildName) {
  34. my $fh = new IO::File $BuildNameFile, "w";
  35. if (defined $fh) {
  36. $fh->print("$BuildName\n");
  37. undef $fh;
  38. } else {
  39. Myerrmsg("can't open $BuildNameFile: $!");
  40. }
  41. } else {
  42. Myerrmsg("can't make build name");
  43. }
  44. # verify that we have a valid build name file
  45. my $ReadBuildName;
  46. my $fh = new IO::File $BuildNameFile, "r";
  47. if (defined $fh) {
  48. $ReadBuildName = $fh->getline;
  49. undef $fh;
  50. chomp $ReadBuildName;
  51. logmsg("Build name is $ReadBuildName");
  52. } else {
  53. Myerrmsg("can't read $BuildNameFile: $!");
  54. }
  55. if ($ReadBuildName ne $BuildName) {
  56. wrnmsg("build name file $BuildNameFile value " .
  57. "$ReadBuildName does not match $BuildName");
  58. }
  59. return $ReadBuildName;
  60. }
  61. sub MakeBuildName {
  62. my $BuildNumber = &MakeBuildNumber or return;
  63. my $BuildArch = &MakeBuildArch or return;
  64. my $BuildType = &MakeBuildType or return;
  65. my $BuildBranch = &MakeBuildBranch or return;
  66. my $BuildDate = &MakeBuildDate or return;
  67. return sprintf("%s.%s%s.%s.%s", $BuildNumber, $BuildArch,
  68. $BuildType, $BuildBranch, $BuildDate);
  69. }
  70. sub MakeBuildNumber {
  71. my ($BuildNumber, $BuildRevision);
  72. my $BldnumFile = $ENV{"SDXROOT"} . "\\__bldnum__";
  73. dbgmsg("will use $BldnumFile as build number file");
  74. my $fh = new IO::File $BldnumFile, "r";
  75. if (defined $fh) {
  76. ($BuildNumber) = $fh->getline =~ /BUILDNUMBER=(\d+)/;
  77. undef $fh;
  78. dbgmsg("build number is $BuildNumber");
  79. } else {
  80. Myerrmsg("can't read $BldnumFile: $!");
  81. }
  82. ##########
  83. my $BldrevFile = $ENV{"SDXROOT"} . "\\BuildRev.txt";
  84. dbgmsg("will use $BldrevFile as build revision file");
  85. if (-e $BldrevFile) {
  86. my $fh = new IO::File $BldrevFile, "r";
  87. if (defined $fh) {
  88. $BuildRevision = $fh->getline;
  89. undef $fh;
  90. chomp $BuildRevision;
  91. dbgmsg("build revision is $BuildRevision");
  92. } else {
  93. Myerrmsg("can't read $BldrevFile: $!");
  94. }
  95. }
  96. return ($BuildRevision ? "$BuildNumber-$BuildRevision" : $BuildNumber);
  97. }
  98. sub MakeBuildArch {
  99. unless ($ENV{_BuildArch}) {
  100. Myerrmsg("environment variable _BuildArch is not defined");
  101. }
  102. return $ENV{_BuildArch};
  103. }
  104. sub MakeBuildType {
  105. unless ($ENV{_BuildType}) {
  106. Myerrmsg("environment variable _BuildType is not defined");
  107. }
  108. return $ENV{_BuildType};
  109. }
  110. sub MakeBuildBranch {
  111. unless ($ENV{_BuildBranch}) {
  112. Myerrmsg("environment variable _BuildBranch is not defined");
  113. }
  114. return $ENV{_BuildBranch};
  115. }
  116. sub MakeBuildDate {
  117. my $BuildDate;
  118. my $BlddateFile = $ENV{"SDXROOT"} . "\\__blddate__";
  119. dbgmsg("will use $BlddateFile as build date file");
  120. my $fh = new IO::File $BlddateFile, "r";
  121. if (defined $fh) {
  122. ($BuildDate) = $fh->getline =~ /BUILDDATE=(\d{6}-\d{4})/;
  123. undef $fh;
  124. dbgmsg("build date is $BuildDate");
  125. } else {
  126. Myerrmsg("can't read $BlddateFile: $!");
  127. }
  128. return $BuildDate;
  129. }
  130. sub Myerrmsg($)
  131. {
  132. my $msg = shift;
  133. if ( exists $ENV{BUILDMSG} )
  134. {
  135. print "Build_Status ERROR!\n$0 : error : $msg";
  136. }
  137. errmsg( $msg );
  138. }