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.

413 lines
12 KiB

  1. # ---------------------------------------------------------------------------
  2. # Script: locag.pl
  3. #
  4. # (c) 2000 Microsoft Corporation. All rights reserved.
  5. #
  6. # Purpose: This script is an example of a perl script in the NT postbuild
  7. # environment.
  8. #
  9. # Version: 1.00 (08/16/2000) (bensont) Provide a wrapper for sysgen & nmake
  10. #---------------------------------------------------------------------
  11. # Modified by sergueik
  12. # Set Package
  13. # <Set your package name of your perl module>
  14. #
  15. # nmake ->
  16. # redir_execute
  17. # collecterrandlog
  18. #
  19. package locag;
  20. # Set the script name
  21. # <Set your script name>
  22. $ENV{script_name} = 'locag.pl';
  23. # Set version
  24. # <Set the version of your script>
  25. $VERSION = '1.00';
  26. # Set required perl version
  27. # <Set the version of perl that your script requires>
  28. require 5.003;
  29. # Use section
  30. use lib $ENV{RAZZLETOOLPATH} . "\\POSTBUILDSCRIPTS";
  31. use lib $ENV{RAZZLETOOLPATH};
  32. # use PbuildEnv;
  33. # use ParseArgs;
  34. use GetParams;
  35. use LocalEnvEx;
  36. use Logmsg;
  37. use Cwd;
  38. use strict;
  39. no strict 'vars';
  40. no strict 'refs';
  41. # <Add any perl modules that you will be using for this script>
  42. # Require section
  43. require Exporter;
  44. # <Add any perl pl files that you will be using>
  45. # Global variable section
  46. # <Add any global variables here using my to preserve namespace>
  47. $SYSGEN_LOG = "\%TEMP\%\\sysgen.log.tmp";
  48. $SYSGEN_ERR = "\%TEMP\%\\sysgen.err.tmp";
  49. $SYSGEN = "\%RAZZLETOOLPATH\%\\POSTBUILDSCRIPTS\\sysgen.pl";
  50. $MTNMAKE = "\%RAZZLETOOLPATH\%\\POSTBUILDSCRIPTS\\mtnmake.cmd";
  51. $SYSFILE = "\%RAZZLETOOLPATH\%\\POSTBUILDSCRIPTS\\SYSGEN\\RELBINS\\\%LANG\%\\sysfile";
  52. $SYSGEN_MAK = "\%TEMP\%\\sysgen.mak";
  53. # new aggregation stuff. Always clean.
  54. my @BACKUPLOGERR;
  55. sub Main {
  56. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  57. # Begin Main code section
  58. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  59. # Return when you want to exit on error
  60. # <Implement your code here>
  61. &verify_tempdir;
  62. my $r = 0;
  63. $r = &SysGen;
  64. print "syntax check only - exiting\n" and exit 0 if ($syntax);
  65. $r = &NMake if ($r eq 0);
  66. $r = &CPLocationWorkAround if ($r eq 0);
  67. $r;
  68. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  69. # End Main code section
  70. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  71. }
  72. # <Implement your subs here>
  73. sub verify_tempdir{
  74. my $temp = $ENV{"TEMP"};
  75. my $tempdir = (defined($lang) && $ENV{"TEMP"} !~ /$lang$/) ?
  76. $ENV{"TEMP"}."\\". $lang :
  77. $ENV{"TEMP"} ;
  78. $ENV{"TEMP"} = $tempdir;
  79. }
  80. #
  81. #
  82. sub redir_execute {
  83. my $status;
  84. $ENV{"LOGFILE"} = $SYSGEN_LOG;
  85. $ENV{"ERRFILE"} = $SYSGEN_ERR;
  86. print "(", $ENV{"script_name"}, "): @_\n";
  87. $status = system(@_) >> 8;
  88. ($ENV{LOGFILE}, $ENV{ERRFILE}) = @BACKUPLOGERR;
  89. $status;
  90. }
  91. sub CPLocationWorkAround{
  92. logmsg ("del $ENV{_NTPostBld}\\build_logs\\cplocation.txt");
  93. system "del $ENV{_NTPostBld}\\build_logs\\cplocation.txt";
  94. return 0;
  95. }
  96. sub NMake {
  97. # my $NODIRS = "\-d" unless $clean;
  98. local $clean = "-c";
  99. my $cmd = (defined ($clean)) ?
  100. "$MTNMAKE SYSGEN \-n \%NUMBER_OF_PROCESSORS\% -w $SYSGEN_MAK $NODIRS -l $lang":
  101. "nmake -f $SYSGEN_MAK";
  102. $cmd =~ s/\%NUMBER_OF_PROCESSORS\%/2 * $ENV{"NUMBER_OF_PROCESSORS"}/eig;
  103. # the NUMBER_OF_PROCESSORS only variable is a little tricky
  104. map {$_ =~ s/\%(\w+)\%/$ENV{$1}/ieg} ($SYSGEN_LOG , $SYSGEN_ERR, $SYSFILE, $cmd);
  105. my $filesize = (-e $SYSGEN_ERR) ? (-s $SYSGEN_ERR) : 0;
  106. my $status = redir_execute($cmd);
  107. &CollectErrAndLog;
  108. if ($status ne 0) {
  109. errmsg("Nmake had fatal error.");
  110. }
  111. elsif ( (-e $SYSGEN_ERR) &&
  112. ($filesize ne (-s $SYSGEN_ERR))) {
  113. errmsg("unrecognized bingen / rsrc / copy error during nmake.");
  114. $status = 1;
  115. }
  116. $status;
  117. }
  118. sub SysGen {
  119. map {$_ =~ s/\%(\w+)\%/$ENV{"$1"}/ieg}
  120. ($SYSFILE , $SYSGEN_MAK, $SYSGEN);
  121. #
  122. # chop away the %LANG% from %_NTPOSTBLD%
  123. # not needed for sysgen version 4.xx
  124. my $_sysgen = qx("perl $SYSGEN -v 2>&1");
  125. my ($_version) = $_sysgen =~ m/\b(\d)\./;
  126. $_version = 0 + $_version;
  127. $_NTPOSTBLD = $ENV{"_NTPOSTBLD"};
  128. if ($_version < 4){
  129. $_NTPOSTBLD =~ s/\\$lang$//g;
  130. }
  131. local $clean = "-c";
  132. my $sysgencmd = "SET _NTPOSTBLD=$_NTPOSTBLD".
  133. "\&".
  134. "perl $SYSGEN $clean $accel $syntax -f:$SYSFILE -w:$ENV{TEMP} -l:$lang $targets";
  135. my $status = redir_execute($sysgencmd);
  136. $status and &CollectErrAndLog;
  137. $status;
  138. }
  139. sub CollectErrAndLog {
  140. my $LOGFOLDER = "\%_NTPOSTBLD\%\\BUILD_LOGS";
  141. map {$_ =~ s/\%(\w+)\%/$ENV{"$1"}/ieg}
  142. ($SYSGEN_ERR, $SYSGEN_LOG, $SYSGEN_MAK);
  143. if (-e $SYSGEN_ERR) {
  144. errmsg("Cannot open $SYSGEN_ERR") and return unless open(F, $SYSGEN_ERR);
  145. map({errmsg($_);()} <F>);
  146. close(F);
  147. }
  148. my $dest = {$SYSGEN_LOG => "sysgen.log",
  149. $SYSGEN_ERR => "sysgen.err",
  150. $SYSGEN_MAK => "sysgen.mak"};
  151. map {errmsg("copy $_ to $LOGFOLDER failed.")
  152. if (-e $_ and 0 ne system("copy $_ $LOGFOLDER\\". $dest->{$_}." 2>NUL1>NUL"))
  153. }
  154. ($SYSGEN_ERR, $SYSGEN_LOG, $SYSGEN_MAK);
  155. # temporary workaround. no way to know the location of COMPDIR FILES
  156. map {qx($_)} (
  157. "md $LOGFOLDER\\COMPDIR",
  158. "XCOPY /S/Q \%TEMP\%\\COMPDIR $LOGFOLDER\\COMPDIR"
  159. );
  160. 1;
  161. }
  162. sub ValidateParams {
  163. #<Add your code for validating the parameters here>
  164. my $failed = 1;
  165. my ($mycwd, $RazzleToolPath);
  166. @BACKUPLOGERR = ($ENV{LOGFILE}, $ENV{ERRFILE});
  167. $RazzleToolPath=$ENV{RazzleToolPath};
  168. $RazzleToolPath=~s!\\!\/!g;
  169. # Valdate folder exist for the sysgen's sysfile
  170. if (defined $bbt) {
  171. if (-e "$ENV{RazzleToolPath}\\POSTBUILDSCRIPTS\\SYSGEN\\bbt\\$lang") {
  172. chdir("$RazzleToolPath/PostbuildScripts/sysgen/bbt/$lang") or
  173. errmsg("Chdir to $ENV{RazzleToolPath}\\POSTBUILDSCRIPTS\\SYSGEN\\bbt\\$lang failed");
  174. $mycwd=cwd;
  175. $failed = 0 if (lc$mycwd eq lc("${RazzleToolPath}\/PostbuildScripts\/sysgen\/bbt\/$lang"));
  176. } else {
  177. errmsg("BBT sysfile folder $ENV{RazzleToolPath}\\POSTBUILDSCRIPTS\\SYSGEN\\bbt\\$lang" .
  178. " is not exist");
  179. }
  180. } else {
  181. if (-e "$ENV{RazzleToolPath}\\POSTBUILDSCRIPTS\\SYSGEN\\RELBINS\\$lang") {
  182. chdir("$RazzleToolPath/PostbuildScripts/sysgen/relbins/$lang")
  183. or
  184. errmsg("Chdir to $ENV{RazzleToolPath}\\POSTBUILDSCRIPTS\\SYSGEN\\RELBINS\\$lang failed");
  185. $mycwd=cwd;
  186. $failed = 0 if
  187. (lc$mycwd eq lc "${RazzleToolPath}/PostbuildScripts/sysgen/relbins/$lang");
  188. } else {
  189. errmsg("RelBins sysfile folder $ENV{RazzleToolPath}\\POSTBUILDSCRIPTS\\SYSGEN\\bbt\\$lang" .
  190. " is not exist");
  191. }
  192. }
  193. if (defined $targets) {
  194. $targets =~s/\,/ /g; # replace the comma (,) with space for sysgen.pl command line
  195. undef $clean
  196. }
  197. if (defined $clean) {
  198. # if was : $cle4an => -c, $accel => -a.
  199. # To retain the meaning of $clean,
  200. # it must become $clean always -c
  201. # $accel to be turned on by 'old' clean request.
  202. $clean = "-c";
  203. $accel= "-a";
  204. }
  205. if (defined $accel){
  206. $accel= "-a";
  207. }
  208. if (defined $syntax) {
  209. $syntax = "-s";
  210. }
  211. exit 1 if $failed;
  212. }
  213. # <Add your usage here>
  214. sub Usage {
  215. my $self = $0;
  216. $self =~s/.*\\//g;
  217. print <<USAGE;
  218. Purpose of program
  219. Usage: $seff <-l lang> [-c] [-b] [-s] [-f targets]
  220. -l Language (required)
  221. -c for clean build
  222. -s restrict sysgen to syntax checks:
  223. no makefiles required, none produced
  224. -b refer to bbt's sysfile
  225. -f targets; separate by comma
  226. -a accelerate sysgen
  227. -? Displays usage
  228. Example:
  229. 1. Clean build
  230. perl $self.pl -c
  231. Example:
  232. $0 -l jpn
  233. USAGE
  234. }
  235. sub GetParams {
  236. # Step 1: Call pm getparams with specified arguments
  237. &GetParams::getparams(@_);
  238. # Step 2: Set the language into the enviroment
  239. $ENV{lang}=uc($lang);
  240. # Step 3: Call the usage if specified by /?
  241. if ($HELP) {
  242. &Usage();
  243. exit 1;
  244. }
  245. }
  246. # Cmd entry point for script.
  247. if (eval("\$0 =~ /" . __PACKAGE__ . "\\.pl\$/i")) {
  248. # Step 1: Parse the command line
  249. # <run perl.exe GetParams.pm /? to get the complete usage for GetParams.pm>
  250. &GetParams ('-n', 'l:', '-o', 'f:cbsa', '-p', 'lang targets clean bbt syntax accel', @ARGV);
  251. # Include local environment extensions
  252. &LocalEnvEx::localenvex('initialize');
  253. # Set lang from the environment
  254. $lang=$ENV{lang};
  255. # Validate the option given as parameter.
  256. &ValidateParams;
  257. # Step 4: Call the main function
  258. &locag::Main();
  259. # End local environment extensions.
  260. &LocalEnvEx::localenvex('end');
  261. }
  262. # -------------------------------------------------------------------------------------------
  263. # Script: template_script.pl
  264. # Purpose: Template perl perl script for the NT postbuild environment
  265. # SD Location: %sdxroot%\tools\POSTBUILDSCRIPTS
  266. #
  267. # (1) Code section description:
  268. # CmdMain - Developer code section. This is where your work gets done.
  269. # <Implement your subs here> - Developer subs code section. This is where you write subs.
  270. #
  271. # (2) Reserved Variables -
  272. # $ENV{HELP} - Flag that specifies usage.
  273. # $ENV{lang} - The specified language. Defaults to USA.
  274. # $ENV{logfile} - The path and filename of the logs file.
  275. # $ENV{logfile_bak} - The path and filename of the logfile.
  276. # $ENV{errfile} - The path and filename of the error file.
  277. # $ENV{tmpfile} - The path and filename of the temp file.
  278. # $ENV{errors} - The scripts errorlevel.
  279. # $ENV{script_name} - The script name.
  280. # $ENV{_NTPostBld} - Abstracts the language from the files path that
  281. # postbuild operates on.
  282. # $ENV{_NTPostBld_Bak} - Reserved support var.
  283. # $ENV{_temp_bak} - Reserved support var.
  284. # $ENV{_logs_bak} - Reserved support var.
  285. #
  286. # (3) Reserved Subs -
  287. # Usage - Use this sub to discribe the scripts usage.
  288. # ValidateParams - Use this sub to verify the parameters passed to the script.
  289. #
  290. # (4) Call other executables or command scripts by using:
  291. # system "foo.exe";
  292. # Note that the executable/script you're calling with system must return a
  293. # non-zero value on errors to make the error checking mechanism work.
  294. #
  295. # Example
  296. # if (system("perl.exe foo.pl -l $lang")){
  297. # errmsg("perl.exe foo.pl -l $lang failed.");
  298. # # If you need to terminate function's execution on this error
  299. # goto End;
  300. # }
  301. #
  302. # (5) Log non-error information by using:
  303. # logmsg "<log message>";
  304. # and log error information by using:
  305. # errmsg "<error message>";
  306. #
  307. # (6) Have your changes reviewed by a member of the US build team (ntbusa) and
  308. # by a member of the international build team (ntbintl).
  309. #
  310. # -------------------------------------------------------------------------------------------
  311. =head1 NAME
  312. B<mypackage> - What this package for
  313. =head1 SYNOPSIS
  314. <An code example how to use>
  315. =head1 DESCRIPTION
  316. <Use above example to describe this package>
  317. =head1 INSTANCES
  318. =head2 <myinstances>
  319. <Description of myinstances>
  320. =head1 METHODS
  321. =head2 <mymathods>
  322. <Description of mymathods>
  323. =head1 SEE ALSO
  324. <Some related package or None>
  325. =head1 AUTHOR
  326. <sergueik>
  327. =cut
  328. 1;