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.

341 lines
9.6 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. # Set Package
  12. # <Set your package name of your perl module>
  13. package locag;
  14. # Set the script name
  15. # <Set your script name>
  16. $ENV{script_name} = 'locag.pl';
  17. # Set version
  18. # <Set the version of your script>
  19. $VERSION = '1.00';
  20. # Set required perl version
  21. # <Set the version of perl that your script requires>
  22. require 5.003;
  23. # Use section
  24. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  25. use lib $ENV{RAZZLETOOLPATH};
  26. use GetParams;
  27. use LocalEnvEx;
  28. use Logmsg;
  29. use Cwd;
  30. use strict;
  31. no strict 'vars';
  32. # <Add any perl modules that you will be using for this script>
  33. # Require section
  34. require Exporter;
  35. # <Add any perl pl files that you will be using>
  36. # Global variable section
  37. # <Add any global variables here using my to preserve namespace>
  38. my @SYSGENLOGERR=("sysgen.log", "sysgen.err");
  39. my @BACKUPLOGERR;
  40. sub Main {
  41. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  42. # Begin Main code section
  43. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  44. # Return when you want to exit on error
  45. # <Implement your code here>
  46. my $r;
  47. $r = &SysGen;
  48. $r = &NMake if ($r eq 0);
  49. $r = &CPLocationWorkAround if ($r eq 0);
  50. logmsg("Please reference sysgen.log in $ENV{_NTPOSTBLD}\\build_logs");
  51. return $r;
  52. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  53. # End Main code section
  54. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  55. }
  56. # <Implement your subs here>
  57. sub redir_execute {
  58. my($cmd)=@_;
  59. my $r;
  60. ($ENV{LOGFILE}, $ENV{ERRFILE}) = @SYSGENLOGERR;
  61. $r = system($cmd) >> 8;
  62. ($ENV{LOGFILE}, $ENV{ERRFILE}) = @BACKUPLOGERR;
  63. return $r;
  64. }
  65. # for Bidi's comdlg32.dll, we need work-around to add 0x040? and 0x080?
  66. # into EN binary (we copied from binaries tree in sysgen).
  67. sub BidiWorkAround {
  68. my(%codes, $LCID1, $LCID2);
  69. ParseTable::parse_table_file($ENV{ "RazzleToolPath" }."\\codes.txt", \%codes);
  70. $LCID1 = $codes{uc$lang}->{LCID};
  71. $LCID1 =~ s/0x0*//;
  72. $LCID2 = $LCID1;
  73. $LCID2 =~ s/^4/8/;
  74. map({logmsg($_)} `rsrc $ENV{_NTPOSTBLD}\\comdlg32.dll -a $ENV{_NTROOT}\\loc\\res\\$lang\\windows\\tokens\\multi\\comdlg32.dll.${LCID1}.rsrc -l 0x0${LCID1}`);
  75. map({logmsg($_)} `rsrc $ENV{_NTPOSTBLD}\\comdlg32.dll -a $ENV{_NTROOT}\\loc\\res\\$lang\\windows\\tokens\\multi\\comdlg32.dll.${LCID2}.rsrc -l 0x0${LCID2}`);
  76. }
  77. sub CPLocationWorkAround{
  78. logmsg ("del $ENV{_NTPostBld}\\build_logs\\cplocation.txt");
  79. system "del $ENV{_NTPostBld}\\build_logs\\cplocation.txt";
  80. return 0;
  81. }
  82. sub NMake {
  83. my $filesize = (-e $SYSGENLOGERR[1])?(-s $SYSGENLOGERR[1]):0;
  84. my $r = redir_execute(
  85. (defined $clean)?
  86. sprintf("$ENV{RazzleToolPath}\\PostbuildScripts\\mtnmake SYSGEN %d",2 * $ENV{NUMBER_OF_PROCESSORS}) :
  87. "nmake"
  88. );
  89. &CollectErrAndLog;
  90. if ($r ne 0) {
  91. errmsg("Nmake had fatal error.");
  92. } # handle no error case more elaborately.
  93. elsif ((-e $SYSGENLOGERR[1]) && ($filesize ne (-s $SYSGENLOGERR[1]))){
  94. my $checksize = -s $SYSGENLOGERR[1];
  95. errmsg("Failed bingen / rsrc or copy during nmake.");
  96. errmsg("\$filesize = $filesize\n-s \$SYSGENLOGERR\[\1\]=-s $SYSGENLOGERR[1]\n") if $DEBUG;
  97. $r = 1;
  98. }
  99. return $r;
  100. }
  101. sub SysGen {
  102. my $sysgencmd = "set _NTPOSTBLD=$ENV{_NTPostBld_Bak} \&\& " .
  103. "perl $ENV{RazzleToolPath}\\PostbuildScripts\\sysgen.pl $clean $sysgenfiles";
  104. my $r = redir_execute($sysgencmd);
  105. &CollectErrAndLog if ($r ne 0);
  106. return $r;
  107. }
  108. sub CollectErrAndLog {
  109. if (-e "sysgen.err") {
  110. open(F, "sysgen.err") or do {errmsg("Cannot open sysgen.err file."); return};
  111. map({errmsg($_);()} <F>);
  112. close(F);
  113. if (0 ne system("copy sysgen.err $ENV{_NTPostBld}\\build_logs\\sysgen.err")) {
  114. errmsg("Copy Sysgen.err to build_logs folder failed.");
  115. }
  116. }
  117. if (0 ne system("copy sysgen.log $ENV{_NTPostBld}\\build_logs\\sysgen.log")) {
  118. errmsg("Copy Sysgen.log to build_logs folder failed.");
  119. }
  120. if (0 ne system("copy makefile $ENV{_NTPostBld}\\build_logs\\sysgen.mak")) {
  121. errmsg("Copy Makefile to build_logs folder failed.");
  122. }
  123. return;
  124. }
  125. sub ValidateParams {
  126. #<Add your code for validating the parameters here>
  127. my $failed = 1;
  128. my ($mycwd, $RazzleToolPath);
  129. @BACKUPLOGERR = ($ENV{LOGFILE}, $ENV{ERRFILE});
  130. $RazzleToolPath=$ENV{RazzleToolPath};
  131. $RazzleToolPath=~s!\\!\/!g;
  132. # Valdate folder exist for the sysgen's sysfile
  133. if (defined $bbt) {
  134. if (-e "$ENV{RazzleToolPath}\\PostbuildScripts\\sysgen\\bbt\\$lang") {
  135. chdir("$RazzleToolPath/PostbuildScripts/sysgen/bbt/$lang") or
  136. errmsg("Chdir to $ENV{RazzleToolPath}\\PostbuildScripts\\sysgen\\bbt\\$lang failed");
  137. $mycwd=cwd;
  138. $failed = 0 if (lc$mycwd eq lc("${RazzleToolPath}\/PostbuildScripts\/sysgen\/bbt\/$lang"));
  139. } else {
  140. errmsg("BBT sysfile folder $ENV{RazzleToolPath}\\PostbuildScripts\\sysgen\\bbt\\$lang" .
  141. " is not exist");
  142. }
  143. } else {
  144. if (-e "$ENV{RazzleToolPath}\\PostbuildScripts\\sysgen\\relbins\\$lang") {
  145. chdir("$RazzleToolPath/PostbuildScripts/sysgen/relbins/$lang") or
  146. errmsg("Chdir to $ENV{RazzleToolPath}\\PostbuildScripts\\sysgen\\relbins\\$lang failed");
  147. $mycwd=cwd;
  148. $failed = 0 if (lc$mycwd eq lc "${RazzleToolPath}/PostbuildScripts/sysgen/relbins/$lang");
  149. } else {
  150. errmsg("RelBins sysfile folder $ENV{RazzleToolPath}\\PostbuildScripts\\sysgen\\bbt\\$lang" .
  151. " is not exist");
  152. }
  153. }
  154. if (defined $sysgenfiles) {
  155. $sysgenfiles =~s/\,/ /g; # replace the comma (,) with space for sysgen.pl command line
  156. undef $clean
  157. }
  158. if (defined $clean) {
  159. $clean = "-c";
  160. }
  161. exit 1 if $failed;
  162. }
  163. # <Add your usage here>
  164. sub Usage {
  165. print <<USAGE;
  166. Purpose of program
  167. Usage: $0 <-l lang> [-c] [-b] [-f sysgenfiles]
  168. -l Language
  169. -c for clean build
  170. -b refer to bbt's sysfile
  171. -f sysgenfiles; seperate by comma
  172. -? Displays usage
  173. Example:
  174. 1. Clean build
  175. perl $0.pl
  176. Example:
  177. $0 -l jpn
  178. USAGE
  179. }
  180. sub GetParams {
  181. # Step 1: Call pm getparams with specified arguments
  182. &GetParams::getparams(@_);
  183. # Step 2: Set the language into the enviroment
  184. $ENV{lang}=$lang;
  185. # Step 3: Call the usage if specified by /?
  186. if ($HELP) {
  187. &Usage();
  188. exit 1;
  189. }
  190. }
  191. # Cmd entry point for script.
  192. if (eval("\$0 =~ /" . __PACKAGE__ . "\\.pl\$/i")) {
  193. # Step 1: Parse the command line
  194. # <run perl.exe GetParams.pm /? to get the complete usage for GetParams.pm>
  195. &GetParams ('-n', 'l:', '-o', 'f:cb', '-p', 'lang sysgenfiles clean bbt', @ARGV);
  196. # Include local environment extensions
  197. &LocalEnvEx::localenvex('initialize');
  198. # Set lang from the environment
  199. $lang=$ENV{lang};
  200. # Validate the option given as parameter.
  201. &ValidateParams;
  202. # Step 4: Call the main function
  203. &locag::Main();
  204. # End local environment extensions.
  205. &LocalEnvEx::localenvex('end');
  206. }
  207. # -------------------------------------------------------------------------------------------
  208. # Script: template_script.pl
  209. # Purpose: Template perl perl script for the NT postbuild environment
  210. # SD Location: %sdxroot%\tools\postbuildscripts
  211. #
  212. # (1) Code section description:
  213. # CmdMain - Developer code section. This is where your work gets done.
  214. # <Implement your subs here> - Developer subs code section. This is where you write subs.
  215. #
  216. # (2) Reserved Variables -
  217. # $ENV{HELP} - Flag that specifies usage.
  218. # $ENV{lang} - The specified language. Defaults to USA.
  219. # $ENV{logfile} - The path and filename of the logs file.
  220. # $ENV{logfile_bak} - The path and filename of the logfile.
  221. # $ENV{errfile} - The path and filename of the error file.
  222. # $ENV{tmpfile} - The path and filename of the temp file.
  223. # $ENV{errors} - The scripts errorlevel.
  224. # $ENV{script_name} - The script name.
  225. # $ENV{_NTPostBld} - Abstracts the language from the files path that
  226. # postbuild operates on.
  227. # $ENV{_NTPostBld_Bak} - Reserved support var.
  228. # $ENV{_temp_bak} - Reserved support var.
  229. # $ENV{_logs_bak} - Reserved support var.
  230. #
  231. # (3) Reserved Subs -
  232. # Usage - Use this sub to discribe the scripts usage.
  233. # ValidateParams - Use this sub to verify the parameters passed to the script.
  234. #
  235. # (4) Call other executables or command scripts by using:
  236. # system "foo.exe";
  237. # Note that the executable/script you're calling with system must return a
  238. # non-zero value on errors to make the error checking mechanism work.
  239. #
  240. # Example
  241. # if (system("perl.exe foo.pl -l $lang")){
  242. # errmsg("perl.exe foo.pl -l $lang failed.");
  243. # # If you need to terminate function's execution on this error
  244. # goto End;
  245. # }
  246. #
  247. # (5) Log non-error information by using:
  248. # logmsg "<log message>";
  249. # and log error information by using:
  250. # errmsg "<error message>";
  251. #
  252. # (6) Have your changes reviewed by a member of the US build team (ntbusa) and
  253. # by a member of the international build team (ntbintl).
  254. #
  255. # -------------------------------------------------------------------------------------------
  256. =head1 NAME
  257. B<mypackage> - What this package for
  258. =head1 SYNOPSIS
  259. <An code example how to use>
  260. =head1 DESCRIPTION
  261. <Use above example to describe this package>
  262. =head1 INSTANCES
  263. =head2 <myinstances>
  264. <Description of myinstances>
  265. =head1 METHODS
  266. =head2 <mymathods>
  267. <Description of mymathods>
  268. =head1 SEE ALSO
  269. <Some related package or None>
  270. =head1 AUTHOR
  271. <Your Name <your e-mail address>>
  272. =cut
  273. 1;