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.

558 lines
18 KiB

  1. # ---------------------------------------------------------------------------
  2. # Script: symindex.pm
  3. #
  4. # (c) 2000 Microsoft Corporation. All rights reserved.
  5. #
  6. # Purpose: symbols server package
  7. #
  8. # Version: 1.00 (06/14/2000) - dmiura Make international complient
  9. #---------------------------------------------------------------------
  10. # Set Package
  11. package symindex;
  12. # Set the script name
  13. $ENV{script_name} = 'symindex.pm';
  14. # Set version
  15. $VERSION = '1.00';
  16. # Set required perl version
  17. require 5.003;
  18. # Use section
  19. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  20. use lib $ENV{RAZZLETOOLPATH};
  21. use GetParams;
  22. use LocalEnvEx;
  23. use Logmsg;
  24. use GetIniSetting;
  25. use strict;
  26. no strict 'vars';
  27. # Require section
  28. require Exporter;
  29. # Global variable section
  30. ( $MainSymSrvShare, $OfficialIDXBranch1, $OfficialIDXBranch2 );
  31. $MainSymSrvShare = undef;
  32. # if running on idx branch then some paths below will change
  33. $OfficialIDXBranch1 = "idx01";
  34. $OfficialIDXBranch2 = "idx02";
  35. sub Main {
  36. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  37. # Begin Main code section
  38. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  39. # Return when you want to exit on error
  40. # <Implement your code here>
  41. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  42. # End Main code section
  43. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  44. }
  45. # <Implement your subs here>
  46. sub IndexSymbols
  47. {
  48. # get passed arg
  49. my( $Language, $BuildName, $LogFileName ) = @_;
  50. my( $SymLocation, $LocalSymSrvDir, $ArchType, $RazPath, $Return);
  51. if ( ! ( defined ( $ENV{ "OFFICIAL_BUILD_MACHINE" } ) ) ) {
  52. # we don't index symbols on non-official machines
  53. logmsg( "Non-official build machine, not indexing symbols ...");
  54. return;
  55. }
  56. # # comment out this code to enable VBLs to index
  57. # if ( ! ( defined ( $ENV{ "MAIN_BUILD_LAB_MACHINE" } ) ) ) {
  58. # # we don't index symbols yet outside the main build lab
  59. # logmsg( "Not a main build lab machine, not indexing symbols yet...");
  60. # return;
  61. # }
  62. $SymLocation = &GetSymbolsLocation( $Language, $BuildName, $LogFileName );
  63. if ( ! ( defined( $SymLocation ) ) ) {
  64. errmsg( "Location of symbols to index can't be determined");
  65. return;
  66. }
  67. # comment out for now, timing problems may cause indexing to occur before sym copy
  68. # if ( ! ( -e $SymLocation ) ) {
  69. # errmsg( "Location of symbols $SymLocation doesn't exist");
  70. # return;
  71. # }
  72. if ( ! ( defined ( $ENV{_NTPostBld} ) ) ) {
  73. # if the binaries tree is not there we are toast!
  74. errmsg( "unexpected error - binaries tree not present ...");
  75. return;
  76. }
  77. my( @IniRequest ) = ( "SymIndexServer" );
  78. my( $IniReturn ) = &GetIniSetting::GetSettingEx( $ENV{_BuildBranch},
  79. $Language,
  80. @IniRequest );
  81. if ( $IniReturn ) {
  82. $MainSymSrvShare = $IniReturn;
  83. } else {
  84. logmsg( "No symindex server. Exit.");
  85. return;
  86. }
  87. $LocalSymSrvDir = "$ENV{_NTPostBld}\\symsrv\\$Language";
  88. if ( ! ( defined( $LocalSymSrvDir ) ) ) {
  89. errmsg( "Location of local symsrv directory can't be determined");
  90. return;
  91. }
  92. logmsg( "Location of symsrv subdirectory is $LocalSymSrvDir");
  93. if ( ! ( -e $LocalSymSrvDir ) ) {
  94. errmsg( "Location of symsrv $LocalSymSrvDir doesn't exist");
  95. return;
  96. }
  97. &AddSymbols( $SymLocation, $LocalSymSrvDir, $BuildName, $LogFileName );
  98. }
  99. sub AddSymbols
  100. {
  101. #create loc files
  102. #push newreq (loc, bin, pri, pub) to MainSymServer-AddReq queue
  103. #move newreq (bin, pri, pub)to AddWorking
  104. #if oldreq in AddFinish move oldreq to MainSymServer-DeleteReq
  105. #remove oldreq from AddFinish
  106. #Wait for newreq to move to MainSymServer-AddFinish
  107. #move newreq to AddFinsh
  108. # get passed args
  109. my( $SymbolsLoc, $LocalSymSrvDir, $BuildName, $LogFileName ) = @_;
  110. my( $FileType, %FileName, $StillWorkingList );
  111. my( $Counter, $FinalLocation, $ThisFile, $Return );
  112. logmsg( "Indexing symbols ..." );
  113. # create the loc files
  114. foreach $FileType ( 'bin', 'pri', 'pub' ) {
  115. $Return = system( "dir /b $LocalSymSrvDir\\add_requests\\$BuildName.*.$FileType >nul 2>nul" );
  116. if ( $Return != 0 ) {
  117. logmsg( "$BuildName\.\*\.$FileType file not found at $LocalSymSrvDir\\add_requests");
  118. } else {
  119. $FileName{ $FileType } = `dir /b $LocalSymSrvDir\\add_requests\\$BuildName.*.$FileType`;
  120. if ( defined( $FileName{ $FileType } ) ) {
  121. chomp( $FileName{ $FileType } );
  122. $FinalLocation = $SymbolsLoc;
  123. if ( $FileType =~ /pri/i ) { $FinalLocation .= "\\symbols.pri"; }
  124. if ( $FileType =~ /pub/i ) { $FinalLocation .= "\\symbols"; }
  125. $Return = system( "echo $FinalLocation > $LocalSymSrvDir\\add_requests\\" . $FileName{ $FileType } . "\.loc" );
  126. # add error checking to make sure the write of the loc file worked!!!?
  127. } else {
  128. errmsg( "Undefined dir return! '$FileType' has no value in FileName hash!");
  129. }
  130. }
  131. }
  132. # copy the files over to the main symbols server add request
  133. if ( -e $MainSymSrvShare ) {
  134. # make these into loops over $FileName{ $FileType }
  135. foreach $FileType ( 'bin', 'pri', 'pub' ) {
  136. # now, copy the loc file over to the symbols server (this must be done before the non-loc file per BarbKess)
  137. if ( defined ( $FileName{ $FileType } )) {
  138. $Return = system( "copy $LocalSymSrvDir\\add_requests\\" . $FileName{ $FileType } . "\.loc $MainSymSrvShare\\add_requests >nul 2>nul" );
  139. if ( $Return != 0 ) { errmsg( "Failed to copy $FileName{ $FileType }\.loc file to $MainSymSrvShare\\add_requests ..."); }
  140. }
  141. # next copy the non-loc file to the sym server (must be done second per BarbKess)
  142. if ( defined ( $FileName{ $FileType } )) {
  143. $Return = system( "copy $LocalSymSrvDir\\add_requests\\" . $FileName{ $FileType } . " $MainSymSrvShare\\add_requests" );
  144. if ( $Return != 0 ) { errmsg( "Failed to copy $FileName{ $FileType } to $MainSymSrvShare\\add_requests ..."); }
  145. }
  146. }
  147. #if any files in add finished then move to main symbol server delete request (but only if add requests is not empty)
  148. $Return = system( "dir /b $LocalSymSrvDir\\add_requests\\$BuildName.* >nul 2>nul" );
  149. if ( $Return == 0 ) {
  150. # get branch name
  151. $BranchName = &GetBuildBranch( $BuildName );
  152. if ( ! ( defined( $BranchName ) ) ) {
  153. errmsg( "Failed to find branch name...");
  154. return;
  155. }
  156. #only move to main symbol server delete request if we are not in a fork branch
  157. # if ( !($BranchName =~ /$OfficialIDXBranch1/i || $BranchName =~ /$OfficialIDXBranch2/i) ) {
  158. # $Return = system( "copy $LocalSymSrvDir\\add_finished\\\*\.\* $MainSymSrvShare\\del_requests >nul 2>nul" );
  159. # if ( $Return != 0 ) { errmsg( "Failed to copy $LocalSymSrvDir\\add_finished\\\*\.\*to $MainSymSrvShare\\del_requests\\..."); }
  160. # $Return = system( "del \/q $LocalSymSrvDir\\add_finished\\\*\.\*" );
  161. # if ( $Return != 0 ) { logmsg( "Failed to delete $LocalSymSrvDir\\add_finished\\\*\.\*..."); }
  162. # }
  163. # move files from add requests to add finished
  164. foreach $FileType ( 'bin', 'pri', 'pub' ) {
  165. if ( defined ( $FileName{ $FileType } )) {
  166. if ( !($BranchName =~ /$OfficialIDXBranch1/i || $BranchName =~ /$OfficialIDXBranch2/i) ) {
  167. $Return = system( "copy $LocalSymSrvDir\\add_finished\\\*\.$FileType $MainSymSrvShare\\del_requests >nul 2>nul" );
  168. $Return = system( "del \/q $LocalSymSrvDir\\add_finished\\\*\.$FileType" );
  169. }
  170. $Return = system( "move $LocalSymSrvDir\\add_requests\\" . $FileName{ $FileType } . " $LocalSymSrvDir\\add_finished\\" );
  171. if ( $Return != 0 ) { errmsg( "Failed to move $FileName{ $FileType } to $LocalSymSrvDir\\add_finished\\..."); }
  172. $Return = system( "move $LocalSymSrvDir\\add_requests\\" . $FileName{ $FileType } . "\.loc $LocalSymSrvDir\\add_finished" );
  173. if ( $Return != 0 ) { errmsg( "Failed to move $FileName{ $FileType }\.loc to $LocalSymSrvDir\\add_finished\\..."); }
  174. }
  175. }
  176. }
  177. } else { # matches if ( -e $MainSymSrvShare ) {
  178. errmsg( "Couldn't see the symbols server $MainSymSrvShare ...");
  179. }
  180. }
  181. sub GetRelSvrFromRelRules
  182. {
  183. # get passed args
  184. my( $Language, $BranchName, $ArchType, $LogFileName ) = @_;
  185. my( $RazPath, $RelRulesFile, @RelRulesLines, $FoundTag, $Line, $Junk, $ThisLang, $FirstMachine );
  186. $RazPath = $ENV{ "RazzleToolPath" };
  187. $RelRulesFile = "$RazPath\\PostBuildScripts\\RelRules.$BranchName";
  188. if ( ! ( -e $RelRulesFile ) ) {
  189. logmsg( "No relrules file found, assuming not archiving on release server ...");
  190. return( undef );
  191. }
  192. # parse the relrules file
  193. unless ( open( INFILE, $RelRulesFile ) ) {
  194. errmsg( "Failed to open $RelRulesFile for reading.");
  195. return( undef );
  196. }
  197. @RelRulesLines = <INFILE>;
  198. close( INFILE );
  199. $FoundTag = "FALSE";
  200. foreach $Line ( @RelRulesLines ) {
  201. chomp( $Line );
  202. if ( $Line =~ /^\#/ ) { next; } # skip comments
  203. if ( length( $Line ) == 0 ) { next; } # skip blank lines
  204. if ( $Line =~ /^(.+?)\:$/ ) { # parse tag lines
  205. $FoundTag = "FALSE";
  206. if ( $1 =~ /$ArchType/ ) { $FoundTag = "TRUE"; } # look for "$ArchType": tag, where $ArchType is x86fre...
  207. } elsif ( $FoundTag eq "TRUE" ) { # parse non-tag lines
  208. ( $Junk, $Junk, $ThisLang, $FirstMachine ) = split( /\, /, $Line );
  209. if ( $ThisLang !~ /$Language/i ) { next; } # skip other language specs
  210. return( $FirstMachine ); # return the first release server listed
  211. }
  212. }
  213. # if we're here, we didn't find ourselves in RelRules.
  214. logmsg( "No $ArchType release server found, assuming not archiving on release server ...");
  215. return( undef );
  216. }
  217. sub GetSymbolsLocation
  218. {
  219. # get passed args
  220. my( $Language, $BuildName, $LogFileName ) = @_;
  221. my( $BranchName, $BuildReleaseShare, $SymFarmShare, $Location, $ArchType, $RelSrv, $Return );
  222. # get branch name
  223. $BranchName = &GetBuildBranch( $BuildName );
  224. if ( ! ( defined( $BranchName ) ) ) {
  225. errmsg( "Failed to find branch name.");
  226. return;
  227. }
  228. undef( $Location );
  229. # find the symbols farm name for this branch if it exists
  230. my( @IniRequest ) = ( "SymFarm" );
  231. my( $IniReturn ) = &GetIniSetting::GetSettingEx( $ENV{_BuildBranch},
  232. $Language,
  233. @IniRequest );
  234. if ( $IniReturn ) {
  235. $SymFarmShare = $IniReturn;
  236. }
  237. if ( defined( $SymFarmShare ) ) {
  238. $Location = "$SymFarmShare\\$Language\\$BuildName";
  239. logmsg( "Symbols Location for build machine with sym farm is $Location");
  240. return( $Location );
  241. # symbols are on the symbols farm
  242. }
  243. # parse args from the build name
  244. $ArchType = &GetArchType( $BuildName, $LogFileName );
  245. if ( ! ( defined( $ArchType ) ) ) {
  246. errmsg( "Failed to get valid ArchType from Build Name $BuildName.");
  247. return;
  248. }
  249. # find the release server name for this branch if it exists
  250. $RelSrv = GetRelSvrFromRelRules($Language, $BranchName, $ArchType, $LogFileName );
  251. if ( defined( $RelSrv ) ) {
  252. $Location = "\\\\$RelSrv\\release\\$Language\\$BuildName";
  253. logmsg( "Symbols Location for build machine with release server is $Location");
  254. return( $Location );
  255. # symbols are on a release server
  256. }
  257. # symbols location being determined for build machine with no sym farm or release servers");
  258. # set up build release share name
  259. ( @IniRequest ) = ( "AlternateReleaseDir" );
  260. ( $IniReturn ) = &GetIniSetting::GetSettingEx( $BranchName,
  261. $Language,
  262. @IniRequest );
  263. if ( $IniReturn ) {
  264. $BuildReleaseShare = $IniReturn;
  265. } else {
  266. $BuildReleaseShare = "release";
  267. }
  268. if ($Language =~ /usa/i ) {
  269. $Location = "\\\\" . $ENV{ 'COMPUTERNAME' } . "\\$BuildReleaseShare\\$BuildName";
  270. } else {
  271. $Location = "\\\\" . $ENV{ 'COMPUTERNAME' } . "\\$BuildReleaseShare\\$Language\\$BuildName";
  272. }
  273. logmsg( "Symbols Location for build machine only is $Location");
  274. return( $Location );
  275. # symbols are on a build machine
  276. }
  277. sub GetArchType
  278. {
  279. # GetArchType
  280. #
  281. # GetArchType will return the archtype found in the given BuildName,
  282. # or undef if an invalid archtype is given.
  283. # get passed args
  284. my( $BuildName, $LogFileName ) = @_;
  285. my( $Junk, $ArchType );
  286. ( $Junk, $ArchType, $Junk ) = split( /\./, $BuildName );
  287. # validate we have a real arch type
  288. if ( ( $ArchType =~ /ia64fre/i ) ||
  289. ( $ArchType =~ /ia64chk/i ) ||
  290. ( $ArchType =~ /amd64fre/i ) ||
  291. ( $ArchType =~ /amd64chk/i ) ||
  292. ( $ArchType =~ /x86fre/i ) ||
  293. ( $ArchType =~ /x86chk/i ) ) {
  294. return( $ArchType );
  295. } else {
  296. errmsg( "Failed to parse a valid arch type '$ArchType' from" .
  297. "the given build name '$BuildName' ...");
  298. return;
  299. }
  300. }
  301. sub GetBuildBranch
  302. {
  303. # GetBuildBranch
  304. #
  305. # GetBuildBranch will return the branch name contained in the passed BuildName
  306. # get passed args
  307. my( $BuildName ) = @_;
  308. my( $Junk, $BranchName );
  309. ( $Junk, $Junk, $BranchName, $Junk ) = split( /\./, $BuildName );
  310. return( $BranchName );
  311. }
  312. #
  313. # GetShareDir
  314. #
  315. #
  316. sub GetShareDir
  317. {
  318. my( $ShareName, $LogFile ) = @_;
  319. my( @NetShareReturn, $Return, $NetShareLine );
  320. my( $FieldName, $FieldValue );
  321. $Return = system( "net share $ShareName >nul 2>nul" );
  322. if ( $Return != 0 ) {
  323. errmsg( "No $ShareName share found.");
  324. return;
  325. }
  326. @NetShareReturn = `net share $ShareName`;
  327. # note that i'm using the second line of the net share return
  328. # to get this data. if this changes, it'll break.
  329. $NetShareLine = $NetShareReturn[1];
  330. # logmsg( "NetShareLine is $NetShareLine");
  331. chomp( $NetShareLine );
  332. ( $FieldName, $FieldValue ) = split( /\s+/, $NetShareLine );
  333. if ( $FieldName ne "Path" ) {
  334. errmsg( "Second line of net share does not start with " .
  335. "\'Path\' -- possibly another language?");
  336. }
  337. # logmsg( "FieldValue for $ShareName share path is $FieldValue");
  338. return( $FieldValue );
  339. }
  340. sub ValidateParams {
  341. #<Add your code for validating the parameters here>
  342. }
  343. # <Add your usage here>
  344. sub Usage {
  345. print <<USAGE;
  346. Purpose of program
  347. Usage: $0 [-l lang]
  348. -l Language
  349. -? Displays usage
  350. Example:
  351. $0 -l jpn
  352. USAGE
  353. }
  354. sub GetParams {
  355. # Step 1: Call pm getparams with specified arguments
  356. &GetParams::getparams(@_);
  357. # Step 2: Set the language into the enviroment
  358. $ENV{lang}=$lang;
  359. # Step 3: Call the usage if specified by /?
  360. if ($HELP) {
  361. &Usage();
  362. exit 1;
  363. }
  364. }
  365. # Cmd entry point for script.
  366. if (eval("\$0 =~ /" . __PACKAGE__ . "\\.pm\$/i")) {
  367. # Step 1: Parse the command line
  368. # <run perl.exe GetParams.pm /? to get the complete usage for GetParams.pm>
  369. &GetParams ('-o', 'l:', '-p', 'lang', @ARGV);
  370. # Include local environment extensions
  371. &LocalEnvEx::localenvex('initialize');
  372. # Set lang from the environment
  373. $lang=$ENV{lang};
  374. # Validate the option given as parameter.
  375. &ValidateParams;
  376. # Step 4: Call the main function
  377. &symindex::Main();
  378. # End local environment extensions.
  379. &LocalEnvEx::localenvex('end');
  380. }
  381. # -------------------------------------------------------------------------------------------
  382. # Script: template_script.pm
  383. # Purpose: Template perl perl script for the NT postbuild environment
  384. # SD Location: %sdxroot%\tools\postbuildscripts
  385. #
  386. # (1) Code section description:
  387. # CmdMain - Developer code section. This is where your work gets done.
  388. # <Implement your subs here> - Developer subs code section. This is where you write subs.
  389. #
  390. # (2) Reserved Variables -
  391. # $ENV{HELP} - Flag that specifies usage.
  392. # $ENV{lang} - The specified language. Defaults to USA.
  393. # $ENV{logfile} - The path and filename of the logs file.
  394. # $ENV{logfile_bak} - The path and filename of the logfile.
  395. # $ENV{errfile} - The path and filename of the error file.
  396. # $ENV{tmpfile} - The path and filename of the temp file.
  397. # $ENV{errors} - The scripts errorlevel.
  398. # $ENV{script_name} - The script name.
  399. # $ENV{_NTPostBld} - Abstracts the language from the files path that
  400. # postbuild operates on.
  401. #
  402. # (3) Reserved Subs -
  403. # Usage - Use this sub to discribe the scripts usage.
  404. # ValidateParams - Use this sub to verify the parameters passed to the script.
  405. #
  406. # (4) Call other executables or command scripts by using:
  407. # system "foo.exe";
  408. # Note that the executable/script you're calling with system must return a
  409. # non-zero value on errors to make the error checking mechanism work.
  410. #
  411. # Example
  412. # if (system("perl.exe foo.pl -l $lang")){
  413. # errmsg("perl.exe foo.pl -l $lang failed.");
  414. # # If you need to terminate function's execution on this error
  415. # goto End;
  416. # }
  417. #
  418. # (5) Log non-error information by using:
  419. # logmsg "<log message>";
  420. # and log error information by using:
  421. # errmsg "<error message>";
  422. #
  423. # (6) Have your changes reviewed by a member of the US build team (ntbusa) and
  424. # by a member of the international build team (ntbintl).
  425. #
  426. # -------------------------------------------------------------------------------------------
  427. =head1 NAME
  428. B<mypackage> - What this package for
  429. =head1 SYNOPSIS
  430. <An code example how to use>
  431. =head1 DESCRIPTION
  432. <Use above example to describe this package>
  433. =head1 INSTANCES
  434. =head2 <myinstances>
  435. <Description of myinstances>
  436. =head1 METHODS
  437. =head2 <mymathods>
  438. <Description of mymathods>
  439. =head1 SEE ALSO
  440. <Some related package or None>
  441. =head1 AUTHOR
  442. <Your Name <your e-mail address>>
  443. =cut
  444. 1;