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.

478 lines
13 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM <<intlsdop.cmd>>
  4. REM Perform sd operations for international builds.
  5. REM Copyright (c) Microsoft Corporation. All rights reserved.
  6. REM Version: < 1.0 > 02/02/2001 Suemiao Rossignol
  7. REM ------------------------------------------------------------------
  8. perl -x "%~f0" %*
  9. goto :EOF
  10. #!perl
  11. use strict;
  12. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  13. use lib $ENV{RAZZLETOOLPATH};
  14. use PbuildEnv;
  15. use Logmsg;
  16. use ParseArgs;
  17. use File::Basename;
  18. use BuildName;
  19. use GetIniSetting;
  20. use comlib;
  21. my $scriptname = basename( $0 );
  22. sub Usage {
  23. print<<USAGE;
  24. Perform Integrate, reverse integrate or sync for internatioanl builds steps.
  25. Usage:
  26. $0 [-l:<lang> | -d:<location>] -o:<op> [-t:<timestamp>][-pfi]
  27. -l Language. Default is "usa".
  28. If "usa", sync the source projects under SDXROOT.
  29. If <lang>, RI or sync the localization projects for the given <lang>.
  30. -d: Location.
  31. This could be %sdxroot% or %RazzleToolPath%
  32. Perform sd <operation> on <location>.
  33. -o: SD operation.
  34. if "i", perform integrate.
  35. if "r", perform revers integrate.
  36. if "s", perform sync.
  37. if "v", perform verification.
  38. -t Timestamp. Used for Integrate/RI/syncing the SD files.
  39. Default is the latest time.
  40. -f: Force operation
  41. -i: Interactive mode (prompts for user input)
  42. -p Powerless.
  43. Do not perform sd operation.
  44. /? Displays usage.
  45. Examples:
  46. $0 -d:%sdxroot% -t:2000/10/01:18:00 -o:s
  47. Sync the source tree at the given timestamp.
  48. $0 -d:%RazzleToolPath% -t:2000/10/01:18:00 -o:i
  49. Integrate the intlred tools from main at the given timestamp.
  50. $0 -l:ger -t:2000/09/09:12:34 -o:r
  51. Reverse integrate German localization projects at the given timestamp.
  52. $0 -l:ger -o:s
  53. Sync the German localization projects at the latest time.
  54. USAGE
  55. exit(1);
  56. }
  57. my( $lang, $destDir, $syncTime, $operation, $powerLess, $force, $intact);
  58. my( $isFake, $sdxroot, $toolDir, $pbsDir );
  59. if( !&GetParams ) { exit(1);}
  60. exit(&main);
  61. #-----------------------------------------------------------------------------
  62. # GetParams - parse & validate command line
  63. #-----------------------------------------------------------------------------
  64. sub GetParams
  65. {
  66. parseargs('?' => \&Usage, 'd:' => \$destDir,'t:' =>\$syncTime, 'o:' =>\$operation,
  67. 'p' =>\$powerLess, 'f' => \$force, 'i' => \$intact );
  68. $lang = $ENV{lang};
  69. return 1 if( lc($lang) eq "usa" && !$destDir );
  70. #####The lang not usa, but template default it got to be, so verify with destDir
  71. if( lc($lang) eq "usa" && $destDir )
  72. {
  73. if( $destDir eq $ENV{sdxroot} )
  74. {
  75. if( $operation ne "s" )
  76. {
  77. errmsg("Invalid operation $operation for $destDir" );
  78. return 0;
  79. }
  80. }
  81. elsif( $destDir eq $ENV{RazzleToolPath} )
  82. {
  83. if( !( $operation eq "i" ||$operation eq "r" || $operation eq "s" ) )
  84. {
  85. errmsg("Invalid operation $operation for $destDir" );
  86. return 0;
  87. }
  88. }
  89. else
  90. {
  91. errmsg( "Invalid location $destDir" );
  92. return 0;
  93. }
  94. }
  95. else
  96. {
  97. if( !( $operation eq "r" || $operation eq "s" || $operation eq "v") )
  98. {
  99. errmsg("Invalid operation $operation for $lang" );
  100. return 0;
  101. }
  102. }
  103. return 1;
  104. }
  105. #-----------------------------------------------------------------------------
  106. sub main
  107. {
  108. if( $syncTime && ( $syncTime !~ /^([@#].+)$/ )){ $syncTime = "\@".$syncTime; }
  109. if( $powerLess ) { $isFake = "-n"; } else { $isFake="";}
  110. if( $force ) { $force = "-f"; } else { $force="";}
  111. $sdxroot = $ENV{SDXROOT};
  112. $toolDir = $ENV{RazzleToolPath};
  113. $pbsDir = "$toolDir\\PostBuildScripts";
  114. if( uc($lang) eq "USA" && !$destDir ) #sync source tree#
  115. {
  116. &comlib::ExecuteSystem( "cd /d $ENV{SDXROOT} & sdx sync $force $isFake ...$syncTime -q -h" ); #added $force switch
  117. #if timestamp specified, sync tools & pbs to latest
  118. if($syncTime){ &SyncTools;}
  119. return 0;
  120. }
  121. if ( $destDir )
  122. {
  123. if( $destDir eq $sdxroot )
  124. {
  125. &SyncSourceTree;
  126. }
  127. else
  128. {
  129. &IorRIorSyncTools;
  130. }
  131. }
  132. elsif( $lang )
  133. {
  134. if(!&CheckOpened("$sdxroot\\loc\\res\\$lang") || !&CheckOpened("$sdxroot\\loc\\bin\\$lang")) #just made a wrapper function for this
  135. {
  136. return 0 if( !$intact );
  137. }
  138. if( $intact && &PromptAction("sd client") == 1 ) #only do sd client in interactive mode
  139. { #we'll assume its right in automated case#
  140. &comlib::ExecuteSystem( "cd $sdxroot\\loc\\res\\$lang& sd client -o");
  141. &comlib::ExecuteSystem( "cd $sdxroot\\loc\\bin\\$lang& sd client -o");
  142. }
  143. if( $operation eq "v" )
  144. {
  145. &CompMainLocpart;
  146. }
  147. else
  148. {
  149. &RIorSyncLocTree;
  150. if( $operation eq "r"){ if(!$intact){&CompMainLocpart;} }
  151. }
  152. }
  153. return 1;
  154. }
  155. #----------------------------------------------------------------------------
  156. # SyncTools() - Syncs tools & PBS to latest - all others to timestamp
  157. #----------------------------------------------------------------------------
  158. sub SyncTools()
  159. {
  160. my ($d, @dirs);
  161. @dirs = `cd $sdxroot\\tools &dir /ad /b`;
  162. for $d (@dirs)
  163. {
  164. if( $d !~ /postbuildscripts/i)
  165. {
  166. chomp $d;
  167. &comlib::ExecuteSystem("cd $sdxroot\\tools\\$d &sd sync $force $isFake ...$syncTime");
  168. }
  169. }
  170. &comlib::ExecuteSystem("cd $sdxroot\\tools &sd sync $force $isFake *");
  171. &comlib::ExecuteSystem("cd $sdxroot\\tools\\postbuildscripts &sd sync $force $isFake ...");
  172. return 0 if (!CheckOpened("$sdxroot\\tools"));
  173. return 1;
  174. }
  175. #----------------------------------------------------------------------------
  176. # SDSubmit($) - Automates Submittals w/ arg:comment
  177. #----------------------------------------------------------------------------
  178. sub SDSubmit($$)
  179. {
  180. my(@chglist, $fout);
  181. my($comment, $dir) = @_;
  182. open fout, ">$ENV{TMP}\\_sdchglst.$lang.tmp" || return 0;
  183. @chglist = `cd $dir &sd change -o`;
  184. foreach my $l (@chglist) {
  185. $l =~ s/\<enter description here\>/$comment/;
  186. print fout $l;
  187. }
  188. close fout;
  189. print `cd $dir &type $ENV{TMP}\\_sdchglst.$lang.tmp | sd submit -i`;
  190. `del /f $ENV{TMP}\\_sdchglst.$lang.tmp`;
  191. return 1;
  192. }
  193. #----------------------------------------------------------------------------
  194. # CheckOpened($) - validate no opened files in $arg:tree
  195. #----------------------------------------------------------------------------
  196. sub CheckOpened(@)
  197. {
  198. my @path = @_;
  199. my $res;
  200. logmsg("cd @path &sd opened ...");
  201. $res = `cd @path &sd opened ...`;
  202. if($res ne '')
  203. {
  204. print $res;
  205. return 0;
  206. }
  207. return 1;
  208. }
  209. #----------------------------------------------------------------------------
  210. # RIorSyncLocTree - RI's or syncs loc tree
  211. #----------------------------------------------------------------------------
  212. sub RIorSyncLocTree
  213. {
  214. my( $cmdLine, $action, $res );
  215. my %myCmds = ( "1"=>"sd sync $force $isFake ...", #added $force switch
  216. "2"=>"sd integrate -b locpart -d -r -i $force $isFake ...$syncTime",
  217. "3"=>"sd resolve $isFake -at ...",
  218. "4"=>"sd resolve -n ...",
  219. "5"=>"sd submit ..." );
  220. if( $operation eq "s" ) { $myCmds{"1"} = "sd sync $force $isFake ...$syncTime";}
  221. my %myDirs = ( "1"=>"$sdxroot\\loc\\res\\$lang",
  222. "2"=>"$sdxroot\\loc\\bin\\$lang" );
  223. for my $dirKey ( sort keys %myDirs )
  224. {
  225. for my $theKey ( sort keys %myCmds )
  226. {
  227. last if( $theKey eq "5" && !$intact );
  228. $action = 1;
  229. $cmdLine="cd $myDirs{$dirKey}& $myCmds{$theKey}";
  230. if($intact){ $action = &PromptAction( $cmdLine );}
  231. $res = &comlib::ExecuteSystem( $cmdLine ) if( $action == 1);
  232. if(!$intact && $res == 0 )
  233. {
  234. errmsg("Errors encountered... exiting\n");
  235. return 0;
  236. }
  237. #####Stop here, if sync or automation
  238. #last if( $operation eq "s" || !$intact );
  239. last if( $operation eq "s");
  240. }
  241. #perform submit here - since 2nd case isnt a system call, can't add to myCmds hash
  242. if($operation eq "r" && !$isFake && !$intact)
  243. {
  244. if(!SDSubmit("RI: [ntdev\\ntbuild] Automated RI $lang locpart->main", $myDirs{$dirKey}))
  245. {
  246. errmsg("Errors encountered submitting changes... exiting\n");
  247. return 0;
  248. }
  249. }
  250. }
  251. }
  252. #----------------------------------------------------------------------------
  253. # CompmainLocpart - compares RI & LP branches
  254. #----------------------------------------------------------------------------
  255. sub CompMainLocpart
  256. {
  257. my( $cmdLine, $action, $res );
  258. my %myCmds = ( "1"=>"sd sync $force $isFake ...$syncTime",
  259. "2"=>"sd sync $force $isFake ...$syncTime");
  260. my %myDirs = ( "1"=>"\\lp\\loc\\res\\$lang",
  261. "2"=>"\\lp\\loc\\bin\\$lang");
  262. for my $theKey ( sort keys %myCmds )
  263. {
  264. $cmdLine="cd $myDirs{$theKey}& $myCmds{$theKey}";
  265. if($intact)
  266. {
  267. $action = &PromptAction( $cmdLine );
  268. next if( $action == 2 );
  269. }
  270. $res = &comlib::ExecuteSystem( $cmdLine );
  271. if(!$intact && $res == 0 )
  272. {
  273. errmsg("Differences found during: $cmdLine\n");
  274. }
  275. }
  276. #do comparison
  277. if($intact) #if interactive use windiff / else compdir
  278. {
  279. for $cmdLine ("start windiff $sdxroot\\loc\\res\\$lang \\lp\\loc\\res\\$lang",
  280. "start windiff $sdxroot\\loc\\bin\\$lang \\lp\\loc\\bin\\$lang")
  281. {
  282. $action = &PromptAction( $cmdLine );
  283. &comlib::ExecuteSystem( $cmdLine );
  284. }
  285. }
  286. else
  287. {
  288. for $cmdLine (" compdir $sdxroot\\loc\\res\\$lang \\lp\\loc\\res\\$lang",
  289. " compdir $sdxroot\\loc\\bin\\$lang \\lp\\loc\\bin\\$lang")
  290. {
  291. logmsg("$cmdLine");
  292. my @res = `$cmdLine`;
  293. if( $? )
  294. {
  295. errmsg( "Errors found during comparison:\n@res" );
  296. }
  297. }
  298. }
  299. }
  300. #----------------------------------------------------------------------------//
  301. sub IorRIorSyncTools
  302. {
  303. my( $cmdLine, $action, $IorRI, $res );
  304. $IorRI = "";
  305. $IorRI = "-r -i" if( $operation eq "r" );
  306. if($operation eq "s")
  307. {
  308. &SyncTools();
  309. }
  310. else
  311. {
  312. my %myCmds = ( "1" => "sd opened ...",
  313. "2"=>"sd sync $force $isFake *",
  314. "3"=>"sd sync $force $isFake ...",
  315. "4"=>"sd integrate -b intlred $IorRI $force $isFake *$syncTime",
  316. "5"=>"sd integrate -b intlred $IorRI $force $isFake ...$syncTime",
  317. "6"=>"sd resolve $isFake -am ...",
  318. "7"=>"sd resolve ...",
  319. "8"=>"sd resolve -n ...",
  320. "9"=>"sd submit ..." );
  321. my %myDirs = ( "1"=>"$toolDir", "2"=>"$toolDir","3"=>"$pbsDir", "4"=>"$toolDir", "5"=>"$pbsDir",
  322. "6"=>"$toolDir","7"=>"$toolDir", "8"=>"$toolDir", "9"=>"$toolDir" );
  323. for my $theKey ( sort keys %myCmds )
  324. {
  325. $action = 1;
  326. $cmdLine="cd $myDirs{$theKey}& $myCmds{$theKey}";
  327. if($intact){$action = &PromptAction( $cmdLine ); }
  328. $res = &comlib::ExecuteSystem( $cmdLine )if( $action == 1 );
  329. if(!$intact && $res == 0 )
  330. {
  331. errmsg("**** Errors encountered executing $cmdLine... exiting ****\n");
  332. return 0;
  333. }
  334. }
  335. }
  336. }
  337. #----------------------------------------------------------------------------
  338. # SyncSourceTree - syncs sdx projects
  339. #----------------------------------------------------------------------------
  340. sub SyncSourceTree
  341. {
  342. my( @sdMap, @sdProject, $cmdLine, $action, $res, $sdCmd, @opened );
  343. if( !open( SDMAP, "$sdxroot\\sd.map") )
  344. {
  345. errmsg( "Fail to read $sdxroot\\s.map, exit.");
  346. return 0;
  347. }
  348. @sdMap = <SDMAP>;
  349. close( SDMAP );
  350. my $validLine = 0;
  351. @sdProject=();
  352. for my $curLine ( @sdMap )
  353. {
  354. chomp $curLine;
  355. my @tmpLine = split( /\s+/, $curLine );
  356. if( $tmpLine[1] !~ "---" )
  357. {
  358. next if ( !$validLine );
  359. last if( $tmpLine[0] =~ "#" );
  360. }
  361. else
  362. {
  363. $validLine = 1;
  364. next;
  365. }
  366. next if( !$tmpLine[1] || $tmpLine[1] =~ "(.*)_(.*)" );
  367. next if( $tmpLine[1] eq "root" );
  368. push ( @sdProject, $tmpLine[3] );
  369. }
  370. push ( @sdProject,"developer" );
  371. push ( @sdProject,"Mergedcomponents" );
  372. push ( @sdProject,"public" );
  373. push ( @sdProject,"published" );
  374. $sdCmd = "sd sync $force $isFake ...$syncTime";
  375. $cmdLine = "cd $sdxroot\\@sdProject& $sdCmd";
  376. if($intact) {return 1 if( &PromptAction( $cmdLine ) !=1 );}
  377. for my $theDir( @sdProject )
  378. {
  379. $res = CheckOpened("$sdxroot\\$theDir" );
  380. if(!$intact && $res == 0 ){ push (@opened, $theDir); }
  381. $res = &comlib::ExecuteSystem( "cd $sdxroot\\$theDir& sd sync $force $isFake ...$syncTime" );
  382. if(!$intact && $res == 0 ){
  383. errmsg("**** Errors encountered during sync. Exiting... ****\n");
  384. return 0;
  385. }
  386. }
  387. if(!&SyncTools) #added SynclatestTools here since we'll always want latest tools
  388. {
  389. push (@opened, "tools");
  390. }
  391. for my $i(@opened) #report opened files
  392. {
  393. errmsg(" - Files opened in $i ");
  394. }
  395. return 1;
  396. }
  397. #----------------------------------------------------------------------------//
  398. sub PromptAction
  399. {
  400. my ( $pCmdLine ) = @_;
  401. my ( $choice ) = -1;
  402. my ($theDot) = '.' x ( length( $pCmdLine ) + 10);
  403. print ( "\nAbout to [$pCmdLine]\n$theDot\n") if( $pCmdLine );
  404. while ( $choice > 3 || $choice < 1 )
  405. {
  406. print( "\nPlease choose (1) Continue? (2) Skip (3) Quit? ");
  407. chop( $choice=<STDIN> );
  408. }
  409. print "\n\n";
  410. exit(0) if( $choice == 3 );
  411. return $choice;
  412. }
  413. 1;