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.

318 lines
9.3 KiB

  1. @rem ='
  2. @echo off
  3. REM ------------------------------------------------------------------
  4. REM
  5. REM <<template_script.cmd>>
  6. REM <<purpose of this script>>
  7. REM
  8. REM Copyright (c) Microsoft Corporation. All rights reserved.
  9. REM
  10. REM ------------------------------------------------------------------
  11. perl -x "%~f0" %*
  12. goto :EOF
  13. rem ';
  14. #!perl
  15. use strict;
  16. use File::Basename;
  17. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  18. use lib $ENV{RAZZLETOOLPATH} . "\\sp";
  19. use lib $ENV{RAZZLETOOLPATH};
  20. use PbuildEnv;
  21. use ParseArgs;
  22. use Logmsg;
  23. use ParseTable;
  24. use GetIniSetting;
  25. use File::Copy;
  26. my ($Lang, $Plat, $Build_Num, $Uniq_Name, $Uniq_Name_Prefix, $Proj_Name, $Counter, $BuildRemark, $BuildProj_Name, $Symbol_Info);
  27. my ($Release_Root, $UNC_Path, $Bld_Path, $Sym_Update, $Symbol_Tools);
  28. sub Usage { print<<USAGE; exit(1) }
  29. indexsym.cmd -l:Lang -n:Build_Num -x:Plat [-i:Symbol_Info]
  30. -l:Lang language
  31. -n:Build_Num build number
  32. -x:Plat build arch and build type
  33. -i:Symbol_Info the symbol information; default is tools\\sp\\symbolinfo.txt
  34. Eg.,
  35. indexsym.cmd -l usa -n 1045 -x x86fre
  36. USAGE
  37. parseargs('?' => \&Usage,
  38. 'n:' => \$Build_Num,
  39. 'l:' => \$Lang,
  40. 'x:' => \$Plat,
  41. 'i:' => \$Symbol_Info
  42. );
  43. &main;
  44. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  45. #
  46. # main()
  47. # Main process
  48. #
  49. # IN - none
  50. # OUT - return
  51. #
  52. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  53. sub main
  54. {
  55. &Initial() or return;
  56. &GenerateFileList() or return;
  57. &SubmitUniqRequest();
  58. }
  59. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  60. #
  61. # Initial()
  62. # Check variable defined and set default values
  63. #
  64. # IN - none
  65. # OUT - 0: failed, 1 : success
  66. #
  67. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  68. sub Initial()
  69. {
  70. my ($symbol_info_handle);
  71. $Lang = $ENV{'Lang'} if (!defined $Lang);
  72. # If necessary parameter not defined, exit
  73. if (("$Build_Num" eq '') || ("$Lang" eq '') || ("$Plat" eq '') ) {
  74. logmsg "Error: -l:Lang -n:Build_Num -x:Plat are required variable";
  75. }
  76. #
  77. # Symbol_Info - the setting file
  78. #
  79. $Symbol_Info = dirname($0) . "\\symbolinfo.txt" if (!defined $Symbol_Info);
  80. if (!-e $Symbol_Info) {
  81. logmsg "Error: cannot find the symbol information ($Symbol_Info)\.";
  82. return 0;
  83. }
  84. #
  85. # Proj_Name - the project name
  86. #
  87. if (!defined $Proj_Name) {
  88. $symbol_info_handle = new IO::File $Symbol_Info, 'r';
  89. if (!defined $symbol_info_handle) {
  90. logmsg "Error: cannot open the symbol information ($Symbol_Info)\.";
  91. return 0;
  92. }
  93. while (<$symbol_info_handle>)
  94. {
  95. chomp;
  96. if (/^Project\s*\=\s*(.+)\s*$/) {
  97. $Proj_Name = $1;
  98. last;
  99. }
  100. }
  101. undef $symbol_info_handle;
  102. if (!defined $Proj_Name) {
  103. logmsg "Error: project name is undefined. Cannot find it in the symbol information\.";
  104. return 0;
  105. }
  106. }
  107. # others assign default value if not defined
  108. # BuildProj_Name - the build's project. Default is xpsp1.
  109. $BuildProj_Name = $ENV{_BuildBranch} if (!defined $BuildProj_Name);
  110. # Uniq_Name_Prefix - the prefix of BuildID. Default is $Build_Num\.$BuildProj_Name\.$Plat\.$Lang.
  111. $Uniq_Name_Prefix = "$Build_Num\.$BuildProj_Name\.$Plat\.$Lang" if (!defined $Uniq_Name_Prefix);
  112. # Build Remark - the remark of the build name. Default is 'daily'.
  113. $BuildRemark = 'daily' if (!defined $BuildRemark);
  114. # Release Root - the release root; mainlab is \\ntdev\release
  115. my @iniRequest = ( "DFSRootName" );
  116. $Release_Root = &GetIniSetting::GetSetting( @iniRequest );
  117. # UNC_Path - the release share
  118. $UNC_Path = "$Release_Root\\$BuildProj_Name\\$Build_Num\\$Lang\\$Plat\\bin";
  119. # Bld_Path - the current build path
  120. $Bld_Path = "\\release\\$Build_Num\\$Lang\\$Plat\\bin";
  121. if (!-e $Bld_Path) {
  122. logmsg "Error: cannot find the build in $Bld_Path\.";
  123. return 0;
  124. }
  125. # Sym_Update - the symupd.txt
  126. $Sym_Update = "$Bld_Path\\symbolcd\\symupd.txt";
  127. if (!-e $Sym_Update) {
  128. logmsg "Error: cannot find the symupd.txt ($Sym_Update)\.";
  129. return 0;
  130. }
  131. # Uniq_Name - the unique name
  132. $Counter = &GenerateUniqueName();
  133. $Uniq_Name = $Uniq_Name_Prefix . $Counter;
  134. # Symbols tools
  135. $Symbol_Tools = "\\\\symbols\\tools";
  136. return 1;
  137. }
  138. #
  139. # SubmitUniqRequest()
  140. # - submit the unique request and remove previouse request
  141. # if the new one successfully finished
  142. # - copy the ssi file to symbolcd folder
  143. #
  144. # In : none
  145. # Out: none
  146. #
  147. sub SubmitUniqRequest()
  148. {
  149. my ($r, @requests, $errfile_handle, $crcmd);
  150. if (!-e "$Symbol_Tools\\createrequest.cmd") {
  151. logmsg "Error: Cannot access to createrequest.cmd";
  152. }
  153. #
  154. # A trick to increase the message speed in createrequest.cmd
  155. #
  156. $ENV{'__BatchJob__'} = 2;
  157. #
  158. # Create the new request
  159. #
  160. $crcmd = "$Symbol_Tools\\createrequest.cmd " .
  161. "-i \"$Symbol_Info\" " .
  162. "-d \"$ENV{TEMP}\" -c -s " .
  163. "-b $Uniq_Name -e $BuildRemark " .
  164. "-f \"$ENV{'TEMP'}\\$Uniq_Name\_$BuildRemark\.lst\" " .
  165. "-p \"$Bld_Path\" " .
  166. "-u \"$UNC_Path\" ";
  167. logmsg $crcmd;
  168. $r = system($crcmd);
  169. undef $ENV{'__BatchJob__'};
  170. #
  171. # If success, remove the previous requests in the server
  172. #
  173. if (CreateRequestSuccess("$ENV{'TEMP'}\\$Proj_Name\_$Uniq_Name\_$BuildRemark\.ssi\.log", $r)) {
  174. @requests = Exists("\\\\symbols\\projects\\$Proj_Name\\add_finished\\$Proj_Name\_$Uniq_Name_Prefix*\_$BuildRemark.ssi");
  175. for (@requests) {
  176. next if (/$Uniq_Name\_$BuildRemark/i);
  177. copy($_, "\\\\symbols\\projects\\$Proj_Name\\del_requests\\");
  178. logmsg("Remove old request $_");
  179. }
  180. unlink "$ENV{'TEMP'}\\$Uniq_Name\_$BuildRemark\.lst";
  181. logmsg("CreateRequest finished successfully");
  182. } else {
  183. $errfile_handle = new IO::File "$ENV{'TEMP'}\\$Proj_Name\_$Uniq_Name\_$BuildRemark\.ssi\.err", 'r';
  184. while(<$errfile_handle>) {
  185. chomp;
  186. logmsg($_);
  187. }
  188. undef $errfile_handle;
  189. }
  190. # For safety, we keep the ssi file to symbolcd folder
  191. move("$ENV{'TEMP'}\\$Proj_Name\_$Uniq_Name\_$BuildRemark\.ssi", "$Bld_Path\\symbolcd\\$Proj_Name\_$Uniq_Name\_$BuildRemark\.ssi");
  192. }
  193. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  194. #
  195. # CreateRequestSuccess($logfile, $result)
  196. # if $result > 0 return FAIL
  197. # Look for the Msg(11702) or Msg(11703) in the log file to
  198. # exam the result of the createrequest
  199. #
  200. # IN - CreateRequest's log
  201. # OUT - 1 for success
  202. #
  203. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  204. sub CreateRequestSuccess($, $)
  205. {
  206. my ($logfile, $result) = @_;
  207. my ($logfile_handle, @result);
  208. return 0 if ($result > 0);
  209. $logfile_handle = new IO::File $logfile, 'r';
  210. @result = <$logfile_handle>;
  211. undef $logfile_handle;
  212. # Looking for msg(11702) (SUBMIT TO SYMBOLS SUCCESS) or msg(11703) (SUBMIT TO ARCHIVE SUCCESS)
  213. for (@result) {
  214. return 1 if (/^Msg\((11702|11703)\)/i);
  215. }
  216. return 0;
  217. }
  218. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  219. #
  220. # GenerateFileList()
  221. # Generate a file list from for createrequest to use
  222. #
  223. # IN - none (ref. symupd.txt)
  224. # OUT - none ($ENV{'TEMP'}\\$Uniq_Name\_$BuildRemark\.lst)
  225. #
  226. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  227. sub GenerateFileList()
  228. {
  229. my ($symupd_handle, $symindex_handle, @list, $bin, $pri, $pub);
  230. $symupd_handle = new IO::File $Sym_Update, 'r';
  231. chomp(@list = <$symupd_handle>);
  232. $symupd_handle->close();
  233. $symindex_handle = new IO::File "$ENV{'TEMP'}\\$Uniq_Name\_$BuildRemark\.lst", 'w';
  234. if (!defined $symindex_handle) {
  235. logmsg("Error: Cannot open $ENV{'TEMP'}\\$Uniq_Name\_$BuildRemark\.lst");
  236. return 0;
  237. }
  238. for (@list) {
  239. next if (!/\S/);
  240. ($bin, $pri, $pub) = split(/\s*\,\s*/, $_);
  241. print $symindex_handle "$Bld_Path\\$bin\n" if (-f "$Bld_Path\\$bin");
  242. print $symindex_handle "$Bld_Path\\$pri\n" if (-f "$Bld_Path\\$pri");
  243. print $symindex_handle "$Bld_Path\\$pub\n" if ((!-f "$Bld_Path\\$pri") && (-f "$Bld_Path\\$pub"));
  244. }
  245. $symindex_handle->close();
  246. if (-z "$ENV{'TEMP'}\\$Uniq_Name\_$BuildRemark\.lst") {
  247. logmsg("Error: $ENV{'TEMP'}\\$Uniq_Name\_$BuildRemark\.lst is a zero-byte file");
  248. return 0;
  249. }
  250. return 1;
  251. }
  252. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  253. #
  254. # Exists($filespecprefix)
  255. # Use glob to check file exist or not similar as
  256. # exist in cmd
  257. #
  258. # IN - a filespec prefix, suc as foo\bar*
  259. # OUT - if want array, it return the list of files exist
  260. # in current system with the same filespec prefix;
  261. # if want a value, it return the amout of files that
  262. # have the filespec prefix
  263. #
  264. # * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  265. sub Exists
  266. {
  267. my @list = glob(shift);
  268. return (wantarray)?@list:$#list + 1;
  269. }
  270. #
  271. # GenerateUniqueName()
  272. # Generate unique name by the prefix + YYMMDD-hhmm + extension
  273. # IN: none
  274. # OUT: current time YYMMDD-hhmm
  275. #
  276. sub GenerateUniqueName()
  277. {
  278. my ($YY, $MM, $DD, $hh, $mm) = (localtime())[5,4,3,2,1];
  279. return sprintf("%02d%02d%02d-%02d%02d", $YY % 100, $MM + 1, $DD, $hh, $mm);
  280. }
  281. 1;
  282. __END__