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.

320 lines
9.2 KiB

  1. #----------------------------------------------------------------//
  2. # Script: synctree.pl
  3. #
  4. # (c) 2000 Microsoft Corporation. All rights reserved.
  5. #
  6. # Purpose: This script is a wrapper for intlbld.mak
  7. # It provides error checking, loging and usage.
  8. #
  9. # Version: <1.00> 09/13/2000 : Suemiao Rossognol
  10. #----------------------------------------------------------------//
  11. ###-----Set current script Name/Version.----------------//
  12. package synctree;
  13. $VERSION = '1.00';
  14. $ENV{script_name} = 'synctree.pl';
  15. ###-----Require section and extern modual.---------------//
  16. require 5.003;
  17. use strict;
  18. use lib $ENV{RazzleToolPath };
  19. use lib $ENV{RazzleToolPath } . "\\PostBuildScripts";
  20. no strict 'vars';
  21. no strict 'subs';
  22. no strict 'refs';
  23. use Logmsg;
  24. use cklang;
  25. use comlib;
  26. my( $isFake, $sdxroot, $toolDir, $pbsDir, $myScript );
  27. #------------------------------------------------------------------//
  28. #Function: Main
  29. #Parameter: (1) Language
  30. # (2) Build Number
  31. # (3) Sync Timestamp
  32. #------------------------------------------------------------------//
  33. sub main
  34. {
  35. my( $pLang, $pSyncTime, $pToolBranch, $pPowerless, $pIntegrateOnly, $pSyncOnly )=@_;
  36. if( $pSyncTime )
  37. {
  38. if( $pSyncTime !~ /^([@#].+)$/ )
  39. {
  40. $pSyncTime = "\@".$pSyncTime;
  41. }
  42. }
  43. if( $pPowerless ) { $isFake = "-n"; } else { $isFake="";}
  44. $sdxroot = $ENV{SDXROOT};
  45. $toolDir = $ENV{RazzleToolPath};
  46. $pbsDir = "$toolDir\\PostBuildScripts";
  47. $myScript = "$toolDir\\intlsdop.cmd";
  48. if( uc($pLang) eq "USA")
  49. {
  50. &comlib::ExecuteSystem( "cd /d $ENV{SDXROOT} & sdx sync ...$pSyncTime -q -h" );
  51. }
  52. elsif( uc($pLang) eq "INTL")
  53. {
  54. &comlib::ExecuteSystem( "$myScript -s:$sdxroot -o:\"sdx opened ...\" ");
  55. &IntegrateTools( $pSyncTime, $pToolBranch ) if( !$pSyncOnly );
  56. &SyncSourceTree( $pSyncTime ) if( !$pIntegrateOnly );
  57. }
  58. else
  59. {
  60. &comlib::ExecuteSystem( "$myScript -l:$pLang -o:\"sd opened ...\" ");
  61. exit(0) if( &PromptAction("sd client") == 3);
  62. &comlib::ExecuteSystem( "$myScript -l:$pLang -o:\"sd client -o\" ");
  63. &IntegrateLocTree( $pLang, $pSyncTime, 0) if( !$pSyncOnly );
  64. &IntegrateLocTree( $pLang, $pSyncTime, 1) if( !$pIntegrateOnly );
  65. }
  66. exit(0);
  67. }
  68. #------------------------------------------------------------------//
  69. sub IntegrateLocTree
  70. {
  71. my( $pLang, $pSyncTime, $pSyncOnly) =@_;
  72. my( $cmdLine, $action );
  73. %myCmds = ( "1"=>"sd sync $isFake ...$pSyncTime ",
  74. "2"=>"sd integrate -b locpart -r -i $isFake ...$pSyncTime",
  75. "3"=>"sd resolve $isFake -at",
  76. "4"=>"sd resolve -n",
  77. "5"=>"sd submit" );
  78. %myDirs = ( "1"=>"$sdxroot\\loc\\res\\$pLang",
  79. "2"=>"$sdxroot\\loc\\bin\\$pLang" );
  80. for my $dirKey ( sort keys %myDirs )
  81. {
  82. for my $theKey ( sort keys %myCmds )
  83. {
  84. $cmdLine="$myScript -s:$myDirs{$dirKey} -o:\"$myCmds{$theKey}\" ";
  85. $action = &PromptAction( "cd $myDirs{$dirKey} & $myCmds{$theKey}" );
  86. last if( $action == 2 );
  87. exit(0) if ( $action == 3);
  88. &comlib::ExecuteSystem( $cmdLine ) if( $action == 1);
  89. last if( $pSyncOnly );
  90. }
  91. }
  92. }
  93. #------------------------------------------------------------------//
  94. sub IntegrateTools
  95. {
  96. my( $pSyncTime, $pToolBranch ) =@_;
  97. my( $cmdLine, $action );
  98. %myCmds = ( "1"=>"sd sync $isFake *",
  99. "2"=>"sd integrate -b $pToolBranch $isFake *$pSyncTime",
  100. "3"=>"sd sync $isFake ...",
  101. "4"=>"sd integrate -b $pToolBranch $isFake ...$pSyncTime",
  102. "5"=>"sd resolve $isFake -am",
  103. "6"=>"sd resolve",
  104. "7"=>"sd resolve -n",
  105. "8"=>"sd submit" );
  106. %myDirs = ( "1"=>"$toolDir", "2"=>$toolDir, "3"=>"$pbsDir", "4"=>$pbsDir,
  107. "5"=>"$toolDir","6"=>"$toolDir", "7"=>"$toolDir", "8"=>"$toolDir" );
  108. for my $theKey ( sort keys %myCmds )
  109. {
  110. $cmdLine="$myScript -s:$myDirs{$theKey} -o:\"$myCmds{$theKey}\" ";
  111. $action = &PromptAction( "cd $myDirs{$theKey} & $myCmds{$theKey}" );
  112. if( $action == 1)
  113. {
  114. &comlib::ExecuteSystem( $cmdLine ) ;
  115. next;
  116. }
  117. last if( $action == 2 );
  118. exit(0) if ( $action == 3);
  119. }
  120. }
  121. #------------------------------------------------------------------//
  122. sub SyncSourceTree
  123. {
  124. my( $pSyncTime ) =@_;
  125. my( $cmdLine, $action );
  126. %myCmds = ( "1"=>"sdx sync $isFake ...$pSyncTime",
  127. "2"=>"sd sync $isFake *",
  128. "3"=>"sd sync $isFake ..." );
  129. %myDirs = ( "1"=>"$sdxroot",
  130. "2"=>"$toolDir",
  131. "3"=>"$pbsDir" );
  132. for my $theKey( sort keys %myCmds )
  133. {
  134. $cmdLine = "$myScript -s:$myDirs{$theKey} -o:\"$myCmds{$theKey}\" ";
  135. $action = &PromptAction( "cd $myDirs{$theKey} & $myCmds{$theKey}" );
  136. if( $action == 1)
  137. {
  138. &comlib::ExecuteSystem( $cmdLine ) ;
  139. next;
  140. }
  141. next if( $action == 2 );
  142. exit(0) if ( $action == 3);
  143. }
  144. }
  145. #------------------------------------------------------------------//
  146. sub PromptAction
  147. {
  148. my ( $pCmdLine ) = @_;
  149. my ( $choice ) = -1;
  150. my ($theDot) = '.' x ( length( $pCmdLine ) + 10);
  151. print ( "\nAbout to [$pCmdLine]\n$theDot\n") if( $pCmdLine );
  152. while ( $choice > 3 || $choice < 1 )
  153. {
  154. print( "\nPlease choose (1) Continue? (2) Skip (3) Quit? ");
  155. chop( $choice=<STDIN> );
  156. }
  157. print "\n\n";
  158. return $choice;
  159. }
  160. #------------------------------------------------------------------//
  161. #Function Usage
  162. #------------------------------------------------------------------//
  163. sub Usage
  164. {
  165. print <<USAGE;
  166. A wrapper for "sd operations" used to perform sd commands on source tree
  167. and loc tree.
  168. Usage:
  169. $0 [-l:<lang>] [-t:<timestamp>][-b:<toolbranch>][-i|-y][-p]
  170. -l Language. Default is "usa".
  171. If "usa", sync the source projects under SDXROOT.
  172. If "intl", sync the international build source projects.
  173. Otherwise, sync the localization projects of the given language.
  174. -t Timestamp used for sync'ing the SD files.
  175. -b Tool branch.
  176. Default is "intlred".
  177. -i Perform Integration or Reverse integration but No sync.
  178. -y Perform sync but no integration.
  179. Default execution on both sync and integration instructions.
  180. -p Powerless.
  181. /? Displays usage.
  182. Examples:
  183. $0 -l:intl -t:2000/10/01:18:00 -b:ntbintl -i
  184. Integrate the ntbintl tools from main at the given timestamp.
  185. $0 -l:intl -t:2000/10/01:18:00 -y
  186. Sync the source tree at the given timestamp.
  187. $0 -l:intl -t:2000/10/01:18:00
  188. Integrate the intlred tools from main.
  189. Sync the source tree at the given timestamp.
  190. $0 -l:ger -i
  191. Reverse integrate the German localization projects at the current time.
  192. $0 -l:ger -t:2000/09/09:12:34 -y
  193. Sync the localization projects at the given timestamp.
  194. $0 -l:ger
  195. Sync and reverse integrate the German localization projects at the current time.
  196. USAGE
  197. exit(1);
  198. }
  199. #------------------------------------------------------------------//
  200. #Cmd entry point for script.
  201. #------------------------------------------------------------------//
  202. if (eval("\$0 =~ /" . __PACKAGE__ . "\\.pl\$/i"))
  203. {
  204. # <run perl.exe GetParams.pm /? to get the complete usage for GetParams.pm>
  205. &GetParams ('-n', 'l:','-o', 'n:t:b:piy', '-p', 'lang bldno synctime toolbranch powerLess integrateOnly syncOnly', @ARGV);
  206. #Validate or Set default
  207. if ( !$lang ) {
  208. $lang = "usa";
  209. }
  210. exit(1) if( !&ValidateParams( uc($lang), \$toolbranch ) );
  211. exit( !&synctree::main( uc($lang), $synctime, $toolbranch, $powerLess, $integrateOnly, $syncOnly ) );
  212. }
  213. #----------------------------------------------------------------//
  214. #Function: GetParams
  215. #----------------------------------------------------------------//
  216. sub GetParams
  217. {
  218. use GetParams;
  219. #Call pm getparams with specified arguments
  220. &GetParams::getparams(@_);
  221. #Call the usage if specified by /?
  222. if ($HELP){ &Usage();}
  223. }
  224. #------------------------------------------------------------------//
  225. #Function ValidateParams
  226. #------------------------------------------------------------------//
  227. sub ValidateParams
  228. {
  229. my ( $pLang, $pToolBranch) = @_;
  230. # Define a default location for the log and err file
  231. my $defdir=$ENV{_NTTREE};
  232. if ( uc($pLang) ne "INTL" && uc($pLang) ne "USA") {
  233. $defdir .= "\\$pLang";
  234. }
  235. $defdir .= "\\build_logs";
  236. if( !( -e $defdir ) )
  237. {
  238. &comlib::ExecuteSystem( "md $defdir");
  239. }
  240. #Define LOGFILE and ERRFILE
  241. $ENV{LOGFILE} = "$defdir\\synctree.log";
  242. $ENV{ERRFILE} = "$defdir\\synctree.err";
  243. # Nuke the existing logging files.
  244. &comlib::ExecuteSystem( "del $ENV{LOGFILE}" ) if( -e $ENV{LOGFILE} );
  245. &comlib::ExecuteSystem( "del $ENV{ERRFILE}" ) if( -e $ENV{ERRFILE} );
  246. #Set tool branch to intlred if not defined
  247. $$pToolBranch = "intlred" if( !${$pToolBranch} );
  248. #Verify language if it is not usa or intl
  249. return 1 if( uc($pLang) eq "USA" || uc($pLang) eq "INTL");
  250. if ( !&cklang::CkLang( uc($pLang) ) )
  251. {
  252. errmsg("Invalid language $pLang.");
  253. return 0;
  254. }
  255. return 1;
  256. }
  257. #------------------------------------------------------------------//
  258. 1;