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.

292 lines
7.8 KiB

  1. @rem = '
  2. @echo off
  3. GOTO End_PERL
  4. rem ';
  5. ## ======================= Perl program start
  6. use lib $ENV{ "RAZZLETOOLPATH" } . "\\POSTBUILDSCRIPTS"; # for cmdevt.pl
  7. use Win32;
  8. use Win32::Process;
  9. use PbuildEnv;
  10. use ParseArgs;
  11. use Cwd;
  12. require 5.003;
  13. $SYSGEN = shift @ARGV if ($ARGV[0]=~/sysgen/i);
  14. # this is obsolete but still there /investigate/
  15. &parseargs('?' =>\&Usage,
  16. 't:' =>\$SYSGEN,
  17. 'n:' =>\$sessions,
  18. 'd' =>\$nomakedirs,
  19. 'w:' =>\$makefile);
  20. my $self = $0;
  21. my ($chars, $total, $target, $group, $Target, $LogFileCount) = ();
  22. my $LOGFILE = "SYSGEN.LOG";
  23. my $ERRFILE = "SYSGEN.ERR";
  24. my $SESSIONS = 16;
  25. my $COMPDIR = undef;
  26. my $DEBUG = undef;
  27. $sessions = $ENV{"NUM"} if defined $ENV{"NUM"};
  28. $sessions = $SESSIONS if(!defined $sessions);
  29. die "The parameter \$sessions = $sessions is invalid" if $sessions =~ /\D/;
  30. $makefile = $ENV{"MAKEFILE"} unless !defined ($ENV{"MAKEFILE"});
  31. $makefile = (uc($SYSGEN) eq "SYSGEN") ? "sysgen.mak" : "makefile" unless $makefile;
  32. die "cannot read $makefile" unless -e $makefile;
  33. map {$_ =~ s/\%(\w+)\%/$ENV{$1}/ieg} ($makefile);
  34. my $workdir = $makefile;
  35. $workdir =~ s/\\[^\\]+$//;
  36. # get the workdir for nmake from the makefile
  37. my $Title = $workdir;
  38. $Title =~ s/^.*\\//;
  39. # set the language (or whatever last subdir we are) from the workdir
  40. my $fountargets = 0;
  41. my @targets = ();
  42. # no targets
  43. open(F, $makefile);
  44. while (<F>){
  45. chomp;
  46. $foundtargets = 1 if /^all\s*:/i;
  47. $line = $_;
  48. $line =~ s/^.*:\s*//g;
  49. $line =~ s/^\W+//g;
  50. $line =~ s/\\$//g;
  51. last if $foundtargets and /^\s*$/; # blank line
  52. $makedirs = 1 if $foundtargets and /_DIRS/i;
  53. push @targets, split(/\s+/,$line) if $foundtargets and $line =~ /\S/;
  54. }
  55. close(F);
  56. $DIRS=shift @targets if $targets[0] =~ /\b_DIRS\b/i;
  57. $COMPDIR=shift @targets if $targets[0] =~ /\b_COMPDIR\b/i;
  58. foreach $target (@targets){
  59. if ($target =~ /^process(\d\d)(\d\d)/i and $2 eq $1){
  60. $total = $1; # number of chips.
  61. }
  62. }
  63. $chars = scalar(split '', $total);
  64. my @groups = ();
  65. $#groups = $sessions - 1;
  66. foreach $group (@groups){
  67. $group = [];
  68. }
  69. while (scalar(@targets)){
  70. foreach $group (@groups){
  71. push @$group, pop @targets;
  72. }
  73. }
  74. # @targets must be empty now; we re-group the targets
  75. foreach $group (@groups){
  76. push @targets, join(" ", @$group);
  77. }
  78. # change current dir for proper error log file placement
  79. system("cd /d $workdir") if $workdir =~ /\W/;
  80. print STDERR "CWD is now: ",$workdir,"\n";
  81. print STDERR "move sysgen.log sysgen.log.tmp";
  82. qx("move $workdir\\sysgen.log $workdir\\sysgen.log.tmp");
  83. qx("move $workdir\\sysgen.err $workdir\\sysgen.err.tmp");
  84. map {$_=$workdir."\\$_.TMP"} ($LOGFILE, $ERRFILE);
  85. # may not need it anymore
  86. if (!$nomakedirs && $makedirs) {
  87. print STDERR "make $DIRS $COMPDIR\n";
  88. &makeLogErrEnv("LOGFILE", $LOGFILE);
  89. &makeLogErrEnv("ERRFILE", $ERRFILE);
  90. &makeLogErrEnv("LOGFILE_BAK", $LOGFILE);
  91. &makeLogErrEnv("ERRFILE_BAK", $ERRFILE);
  92. system("nmake /NOLOGO /R /S /C /F $makefile $DIRS $COMPDIR");
  93. print STDERR "nmake /NOLOGO /R /S /C /F $makefile $DIRS $COMPDIR\n";
  94. }
  95. my @ProcessList= ();
  96. $DEBUG and $ENV{"DEBUG"} = $DEBUG;
  97. print "\nArrange ".scalar(@targets)." SYSGEN targets in $sessions groups\n";
  98. foreach $target (0..$#targets) {
  99. my $Target = $targets[$target];
  100. &makeLogErrEnv("LOGFILE", $LOGFILE);
  101. &makeLogErrEnv("ERRFILE", $ERRFILE);
  102. &makeLogErrEnv("LOGFILE_BAK", $LOGFILE);
  103. &makeLogErrEnv("ERRFILE_BAK", $ERRFILE);
  104. my $Event = join("_", ("PB", $Title, $target));
  105. my $enforce = defined ($COMPDIR) ? "/A":"";
  106. my $cmd = "start \"$Event\" /MIN cmd /k $self -w $Event nmake /NOLOGO /f $makefile $enforce $Target";
  107. system($cmd);
  108. push @ProcessList, $Event and print STDERR "create $Event for $Target\n";
  109. }
  110. my $ProcessList = join(" ", @ProcessList);
  111. print STDERR "wait for: $ProcessList\n";
  112. system("\%PERLEXE\% \%RAZZLETOOLPATH\%\\POSTBUILDSCRIPTS\\cmdevt.pl -w $ProcessList");
  113. delete $ENV{"DEBUG"};
  114. delete $ENV{"WORKDIR"};
  115. sub makeLogErrEnv{
  116. my ($filename, $filemask) = @_;
  117. my $chars = 2;
  118. $ENV{uc($filename)} = lc(sprintf ("$filemask.TEMP.\%0${chars}d", $LogFileCount));
  119. $LogFileCount ++;
  120. 1;
  121. }
  122. 1;
  123. __END__
  124. :End_PERL
  125. SETLOCAL ENABLEDELAYEDEXPANSION
  126. IF NOT "%_echo%" == "" echo on
  127. IF NOT "%verbose%" == "" echo on
  128. SET SELF=%~nx0
  129. FOR %%a IN (./ .- .) DO IF ".%1." == "%%a?." GOTO Usage
  130. FOR %%i IN (perl.exe) DO IF NOT defined PERLEXE set PERLEXE=%%~$PATH:i
  131. IF /I "%3"=="nmake" GOTO :NMAKE
  132. REM SET SCRIPT= %~f0
  133. REM ECHO %*
  134. %PERLEXE% %~DP0\%SELF% %*
  135. SETLOCAL ENABLEDELAYEDEXPANSION ENABLEDELAYEDEXPANSION
  136. FOR %%l in (%LOGFILE% %ERRFILE%) DO CALL :CONCAT %%~nxl %%~dpl
  137. GOTO:EOF
  138. SET RET_VALUE=0
  139. FOR /f %%i IN ('findstr /c:"**** ERROR :" *') DO SET /A RET_VALUE+=1
  140. ENDLOCAL && seterror %RET_VALUE%
  141. GOTO :EOF
  142. :Usage
  143. echo %SELF% - Multi-Taskly NMake makefile with process^<total^>^<id^>
  144. echo.
  145. echo Syntax:
  146. echo %SELF% [SYSGEN] -n ^<sessions^> [-d] [-w ^<makefile^>] [-v]
  147. echo.
  148. echo Argument :
  149. echo SYSGEN : by default it will define sysgen.err and sysgen.log for
  150. echo it's standard input / output file
  151. echo.
  152. echo sessions : number of session you want to run at the same time.
  153. echo -d : do not make target directory tree (SYSGEN specific)
  154. echo -v : run verbosely, echo executed commands
  155. echo makefile : specify full path to makefile in order to run %SELF%
  156. echo in arbitrary directory (probably ^%%^TEMP^%%^)
  157. echo default is to look in current directory
  158. echo Example:
  159. echo 1. run nmake at 4 sessions
  160. echo =^> %SELF% -n 4
  161. echo 2. run nmake for sysgen with 8 sessions,
  162. echo. makefile sitting in ^%%^TEMP^%%^\^%%^LANG^%%^:
  163. echo =^> %SELF% SYSGEN -n 8 -d -w ^%%^TEMP^%%^\^%%^LANG^%%^\SYSGEN.MAK
  164. echo.
  165. GOTO :EOF
  166. :NMAKE
  167. SET MYSWITCH=%1
  168. SET MYTYTLE=%2
  169. TITLE %MYTYTLE%
  170. SHIFT
  171. SHIFT
  172. %PERLEXE% %RAZZLETOOLPATH%\POSTBUILDSCRIPTS\cmdevt.pl -h %MYTYTLE%
  173. IF NOT DEFINED DEBUG DEL %logfile% 2>NUL 1> NUL
  174. IF NOT DEFINED DEBUG DEL %errfile% 2>NUL 1> NUL
  175. SET CMD=
  176. :NEXTARG
  177. SET CMD=!CMD! %1
  178. SHIFT
  179. IF NOT "%1"=="" GOTO :NEXTARG
  180. ECHO %cmd%
  181. %CMD%
  182. IF ERRORLEVEL 1 ECHO **** ERROR : %MYTYTLE% - ErrorLevel %errorlevel%>>%ERRFILE%
  183. %PERLEXE% %RAZZLETOOLPATH%\POSTBUILDSCRIPTS\cmdevt.pl -s %MYTYTLE%
  184. ENDLOCAL
  185. IF NOT DEFINED DEBUG EXIT
  186. GOTO :EOF
  187. :CONCAT
  188. SET ROOT=%~2
  189. PUSHD %ROOT%
  190. SET FILES=
  191. SET MASK=%~1
  192. IF EXIST %MASK% SET FILES= + %MASK%
  193. FOR /F %%f IN ('DIR /B/A-D %MASK%.TEMP.* 2^>NUL') DO (
  194. IF "%%~zf" neq "0" SET FILES=!FILES! + %%f
  195. )
  196. IF DEFINED FILES (
  197. IF "%FILES%" NEQ " + %MASK%" (
  198. SET FILES=%FILES:~3%
  199. IF DEFINED DEBUG ECHO %SELF%: copy /A /Y %FILES:~3% %MASK%
  200. COPY /A /Y %FILES:~3% %MASK% 1>NUL 2>NUL
  201. IF ERRORLEVEL 1 ECHO %SELF%: FAILED TO COLLECT %MASK%
  202. )
  203. )
  204. IF NOT DEFINED DEBUG (
  205. ECHO %SELF%: remove %MASK%.TEMP.*
  206. DEL %MASK%.TEMP.* 1>NUL 2>NUL
  207. )
  208. POPD
  209. GOTO:EOF
  210. :ENABLEEXTENSIONS
  211. SETLOCAL ENABLEDELAYEDEXPANSION
  212. GOTO :EOF