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.

234 lines
6.3 KiB

  1. @REM -----------------------------------------------------------------
  2. @REM
  3. @REM SetBuildStatus.cmd - miker
  4. @REM Call SetBuildStatus.vbs with the proper data to record the
  5. @REM build status in the status database. Only runs for official
  6. @REM builds.
  7. @REM
  8. @REM Copyright (c) Microsoft Corporation. All rights reserved.
  9. @REM
  10. @REM -----------------------------------------------------------------
  11. @if defined _CPCMAGIC goto CPCBegin
  12. @perl -x "%~f0" %*
  13. @goto :EOF
  14. #!perl
  15. use strict;
  16. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts"; # NOTE: Remove if BuildName.pm ever moves out to \tools
  17. use lib $ENV{RAZZLETOOLPATH};
  18. use ParseArgs;
  19. use Logmsg;
  20. use cklang;
  21. sub Usage { print<<USAGE; exit(0) }
  22. SetBuildStatus.cmd -s:stage [-n:buildnumber] [-l:lang]
  23. Call SetBuildStatus.vbs with the proper data to record the
  24. build status in the status database. Only runs for official
  25. builds.
  26. -s:buildstage Build Stage. Must be one of the ones below. Note
  27. that "done" and "scrub" are mutually exclusive
  28. for a given build of a lang and archtype.
  29. build
  30. postbuild
  31. boot
  32. bvt
  33. release
  34. done
  35. scrub
  36. -n:buildnum Build number. Must be a full build number in the
  37. form "number.archtype.branch.date". If one is not
  38. provided, we will attempt to use the value from
  39. the first one of these that we can find it from:
  40. %SDXROOT%\\BuildName.txt
  41. %_NTPOSTBUILD%\\build_logs\BuildName.txt
  42. %_NTTREE%\\build_logs\BuildName.txt
  43. -l:language Any valid language from codes.txt. Default is USA.
  44. Note that this tool is designed to be run during automated build
  45. processes and any problems it encounters are not output as
  46. errors - not reporting build status is not a build blocking
  47. issue. This script should never output something that says
  48. "ERROR: xxxx", but instead simply output the relevant information
  49. about what happened so it will be logged for later use.
  50. USAGE
  51. sub build_name {
  52. my $build_name;
  53. if ($_[0]) { return lc($_[0]) }
  54. my $BuildNameTxt;
  55. if(-e ("$ENV{SDXROOT}\\BuildName.txt" )){
  56. $BuildNameTxt = "$ENV{SDXROOT}\\BuildName.txt";
  57. }
  58. elsif(-e ("$ENV{_NTPOSTBLD}\\build_logs\\BuildName.txt" )){
  59. $BuildNameTxt = "$ENV{_NTPOSTBLD}\\build_logs\\BuildName.txt";
  60. }
  61. elsif(-e ("$ENV{_NTTREE}\\build_logs\\BuildName.txt" )){
  62. $BuildNameTxt = "$ENV{_NTTREE}\\build_logs\\BuildName.txt";
  63. }
  64. # else{
  65. # Myerrmsg( "Couldn't open file $BuildNameTxt: $!");
  66. # }
  67. if (-e $BuildNameTxt) {
  68. my $fh = new IO::File $BuildNameTxt, "r";
  69. if (defined $fh) {
  70. $build_name = $fh->getline;
  71. chomp($build_name);
  72. undef $fh;
  73. } else {
  74. Myerrmsg( "Couldn't open file $BuildNameTxt!");
  75. }
  76. } else {
  77. # Myerrmsg( "File '$BuildNameTxt' does not exist.");
  78. }
  79. return lc($build_name);
  80. }
  81. my ($BuildStage, $BuildNumber, $BuildBranch, $Lang);
  82. parseargs('?' => \&Usage,
  83. 's:' => \$BuildStage,
  84. 'n:' => \$BuildNumber,
  85. 'l:' => \$Lang);
  86. # Save off the language - but only if we got one
  87. if ( $Lang )
  88. {
  89. # Save what they gave us.
  90. $ENV{LANG} = $Lang;
  91. }
  92. # If nothing is set, default to 'usa'
  93. $ENV{LANG} ||= 'usa';
  94. # validate language, bad languages are fatal
  95. if (!&cklang::CkLang($ENV{LANG}))
  96. {
  97. Myerrmsg( "Language $ENV{LANG} is not listed in codes.txt." );
  98. exit(0);
  99. }
  100. # Validate the build stage...
  101. $BuildStage =~ tr/A-Z/a-z/;
  102. if ( $BuildStage ne "build" &&
  103. $BuildStage ne "postbuild" &&
  104. $BuildStage ne "boot" &&
  105. $BuildStage ne "bvt" &&
  106. $BuildStage ne "release" &&
  107. $BuildStage ne "done" &&
  108. $BuildStage ne "scrub" )
  109. {
  110. Myerrmsg( "Build stage is not valid." );
  111. exit(0);# Note: Exits when done
  112. }
  113. # Make sure we have a build number...
  114. if ( !$BuildNumber )
  115. {
  116. # Nothing given on the command line. Get the current build number and save it...
  117. # Reset %_NTPostBld% first...
  118. my $Saved_NTPostBld = $ENV{_NTPOSTBLD};
  119. if (lc($ENV{LANG}) ne 'usa' && !$ENV{dont_modify_ntpostbld} )
  120. {
  121. $ENV{_NTPOSTBLD} .= "\\$ENV{LANG}";
  122. }
  123. # Get the info we need...
  124. $BuildNumber = build_name();
  125. # Set %_NTPostBld% back to whatever it was...
  126. $ENV{_NTPOSTBLD} = $Saved_NTPostBld;
  127. # Did we get anything?
  128. if ( ! $BuildNumber )
  129. {
  130. Myerrmsg( "Unable to determine the current build number and one was not provided on the command line." );
  131. exit(0);
  132. }
  133. }
  134. # Extract the branch from the build number.
  135. if ( $BuildNumber =~ /([0-9]+)\.(x86|ia64)(fre|chk)\.([0-9A-Za-z_]+)\.([0-9\-]+)/ )
  136. {
  137. $BuildBranch = $4;
  138. }
  139. else
  140. {
  141. Myerrmsg( "Build number '$BuildNumber' is not in usable format" );
  142. exit(0); # Note: Exits when done
  143. }
  144. # Log what we know for reference purposes...
  145. logmsg( "[Lang = $ENV{LANG}]" );
  146. logmsg( "[Build = $BuildNumber]" );
  147. logmsg( "[Branch = $BuildBranch]" );
  148. logmsg( "[Stage = $BuildStage]" );
  149. if ( !$ENV{OFFICIAL_BUILD_MACHINE} )
  150. {
  151. logmsg( "This is not an official build machine. No build status will be written to the database." );
  152. }
  153. else
  154. {
  155. logmsg( "Writing build status to database..." );
  156. my $CommandToCall = "cscript /NOLOGO $ENV{RAZZLETOOLPATH}\\SetBuildStatus.vbs $BuildNumber $ENV{LANG} $BuildBranch $BuildStage";
  157. print ( "$CommandToCall\n" );
  158. # Run the command and log it's raw output...
  159. foreach $_ (`$CommandToCall`)
  160. {
  161. s/$(.*)\n/\1/;
  162. logmsg( "$_" );
  163. }
  164. # Check the return code and if needed log an error...
  165. my $ReturnCode;
  166. $ReturnCode = $? / 256;
  167. if ( $? || $ReturnCode != 0 )
  168. {
  169. # The command returned an unexpected return code!
  170. Myerrmsg( "cscript call failed with code $ReturnCode when code 0 was expected. System Error Code is $?." );
  171. }
  172. logmsg( "Done writing build status to database." );
  173. }
  174. sub Myerrmsg
  175. {
  176. my $msg = shift;
  177. if ( exists $ENV{BUILDMSG} )
  178. {
  179. print "Build_Status error\n$0 : error : $msg (ignorable)";
  180. }
  181. print ( "$msg\n" );
  182. }
  183. # Done!