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.

174 lines
4.1 KiB

  1. # -----------------------------------------------------------------------------
  2. # Purpose: recreate %_NTTREE% by re-executing all of the binplace commands
  3. # listed in the log created during the last build.
  4. #
  5. # Usage: ReplayBinplace.pl [<file>]
  6. # If <file> is given, replay commands from that file. If no <file> is
  7. # given, use the file pointed to by %BINPLACE_MESSAGE_LOG% (or fail)
  8. # -----------------------------------------------------------------------------
  9. #
  10. # dependent modules
  11. #
  12. use strict;
  13. use Win32::Process;
  14. use File::Spec;
  15. use File::Temp qw(tempfile);
  16. #
  17. # Real log and temp log variables
  18. #
  19. my $LogToReplay;
  20. my $TempReplayLog;
  21. #
  22. # see if usage() is wanted
  23. #
  24. if ($ARGV[0] =~ /^[-\/][hH?]/) {
  25. Usage();
  26. exit();
  27. }
  28. #
  29. # Verify we have a message log to work with
  30. #
  31. if ( !defined($ARGV[0]) ) {
  32. if ((!defined $ENV{BINPLACE_MESSAGE_LOG}) ||
  33. (! -e $ENV{BINPLACE_MESSAGE_LOG})) {
  34. Usage();
  35. exit();
  36. } else {
  37. $LogToReplay = $ENV{BINPLACE_MESSAGE_LOG};
  38. }
  39. } else {
  40. $LogToReplay = shift;
  41. }
  42. #
  43. # Copy the message log to a temporary file to work with
  44. #
  45. (undef, $TempReplayLog) = tempfile("RBLXXXXXX", SUFFIX=>".rbl", OPEN => 0, DIR => "$ENV{TEMP}");
  46. system("copy $LogToReplay $TempReplayLog > NUL");
  47. printf("Created: $TempReplayLog\n");
  48. open(hFILE, "$TempReplayLog")||die("ERROR: $0 : Can't open $TempReplayLog\n");
  49. #
  50. # point to the binplace executable
  51. #
  52. my $ExeName = "$ENV{RazzleToolPath}\\$ENV{HOST_PROCESSOR_ARCHITECTURE}\\binplace.exe";
  53. #
  54. # Limit the total number of processes to start
  55. #
  56. my $MaxProcs= $ENV{NUMBER_OF_PROCESSORS} * 4;
  57. #
  58. # Record keeping info
  59. #
  60. my $start = time();
  61. #
  62. # Working variables
  63. #
  64. my $cur_proc; # current process info array [$ProcessObj, $ResponseFile]
  65. my $i; # loop var
  66. my $ProcessObj; # a single process object
  67. my @all_procs; # array of all process
  68. my @params; # array of cmdline params
  69. #
  70. # Loop through the file
  71. #
  72. while (<hFILE> ) {
  73. chomp;
  74. @params = split(/\s+/,$_);
  75. chdir($params[0]);
  76. shift @params;
  77. # create a response file
  78. my($fh, $filename) = tempfile("respXXXXXX", SUFFIX=>".rbl", DIR => "$ENV{TEMP}");
  79. printf($fh "@params");
  80. close($fh);
  81. # call binplace
  82. Win32::Process::Create($ProcessObj,
  83. "$ExeName",
  84. "$ExeName \@${filename}",
  85. 0,
  86. NORMAL_PRIORITY_CLASS,
  87. ".")|| die ErrorReport();
  88. # save info about the new process
  89. push(@all_procs, [$ProcessObj, $filename]);
  90. # don't let the machine get over burdened
  91. while ( $#all_procs > ($MaxProcs - 1) ) {
  92. $cur_proc = shift(@all_procs);
  93. $$cur_proc[0]->Wait(INFINITE);
  94. unlink($$cur_proc[1]);
  95. }
  96. }
  97. #
  98. # wait for the still running processes to finish
  99. #
  100. foreach $cur_proc (@all_procs) {
  101. $$cur_proc[0]->Wait(INFINITE);
  102. unlink($$cur_proc[1]);
  103. }
  104. #
  105. # clenaup
  106. #
  107. close(hFILE);
  108. unlink($TempReplayLog);
  109. printf("$0 : %d seconds\n",time() - $start);
  110. exit(0);
  111. # -----------------------------------------------------------------------------
  112. # Subroutines
  113. # -----------------------------------------------------------------------------
  114. #
  115. # Script usage
  116. #
  117. sub Usage {
  118. print<<END_USAGE
  119. Usage: perl $0 [<file>]
  120. Purpose: recreate %_NTTREE% by re-executing all of the binplace commands
  121. listed in the log created during the last build.
  122. Usage: ReplayBinplace.pl [<file>]
  123. If <file> is given, replay commands from that file. If no <file> is
  124. given, use the file pointed to by %BINPLACE_MESSAGE_LOG% (or fail)
  125. END_USAGE
  126. }
  127. #
  128. # pretty print errors
  129. #
  130. sub ErrorReport{
  131. print Win32::FormatMessage( Win32::GetLastError() );
  132. }
  133. #
  134. # File::Spec theoretically cleans the path up, but it fails to
  135. # handle "[<path>\..\<path>]"
  136. #
  137. sub clean_path {
  138. my $path = shift;#File::Spec->rel2abs($_[0]);
  139. # Remove ..\'s with path
  140. while ( $path =~ s/^(.*?)(\\[^\\]+\\\.\.)\\/$1\\/g ) {
  141. ;
  142. }
  143. # Remove excessive ..\'s
  144. $path =~ s/\\\.\.//g;
  145. return($path);
  146. }