Source code of Windows XP (NT5)
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.

162 lines
4.2 KiB

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