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.

161 lines
4.4 KiB

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