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.

501 lines
14 KiB

  1. #----------------------------------------------------------------//
  2. # Script: copylang.pl
  3. #
  4. # (c) 2000 Microsoft Corporation. All rights reserved.
  5. #
  6. # Purpose: This script copy the files between Source Tree and
  7. # Loc Tree listed in $ENV{RazzleToolPath}\intlsrc.txt.
  8. #
  9. # Version: <1.00> 06/30/2000 : Suemiao Rossognol
  10. #----------------------------------------------------------------//
  11. ###-----Set current script Name/Version.----------------//
  12. package copylang;
  13. $VERSION = '1.00';
  14. $ENV{script_name} = 'copylang.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 GetParams;
  24. use Logmsg;
  25. use cklang;
  26. use cktarg;
  27. use HashText;
  28. use comlib;
  29. %hashCodes=();
  30. &HashText::Read_Text_Hash( 0, $ENV{RazzleToolPath}."\\Codes.txt", \%hashCodes );
  31. # Delete everything that's not international
  32. delete $hashCodes{RO};
  33. delete $hashCodes{CA};
  34. delete $hashCodes{CHP};
  35. delete $hashCodes{PSU};
  36. delete $hashCodes{MIR};
  37. delete $hashCodes{TST};
  38. my ( $infsSrcTree, $unfsLocTree, $isNtsetup );
  39. #------------------------------------------------------------------//
  40. #Function: main
  41. #Parameter: (1) Language
  42. # (2) Root of the Source Tree
  43. # (3) Root of the Localized Tree
  44. # (4) Incremental Flag
  45. # (5) Powerless Flag
  46. #------------------------------------------------------------------//
  47. sub main
  48. {
  49. my ( $pLang, $pSrcRoot, $pLocRoot, $pIsIncr, $pIsPowerless ) = @_;
  50. if( $pLang eq "USA" )
  51. {
  52. $theFromTree = "SourceTree";
  53. $theFromRoot = $pSrcRoot;
  54. $theFromFile = "SourceFilename";
  55. $theToTree = "LocTree";
  56. $theToRoot = $pLocRoot;
  57. $theToFile = "LocTreeFilename";
  58. }else
  59. {
  60. $theFromTree = "LocTree";
  61. $theFromRoot = $pLocRoot;
  62. $theFromFile = "LocTreeFilename";
  63. $theToTree = "SourceTree";
  64. $theToRoot = $pSrcRoot;
  65. $theToFile = "SourceFilename";
  66. }
  67. ###---Set xcopy flag.--------------------------------//
  68. my $copyOpt = "/V /F /R /Y";
  69. if( $pIsPowerless )
  70. {
  71. $copyOpt .= " /L /D";
  72. }
  73. else
  74. {
  75. if( $pIsIncr ){ $copyOpt .= " /D"; }
  76. }
  77. ###---Get Hash value from intlsrc.txt file.----------//
  78. my @srcHash=();
  79. &HashText::Read_Text_Hash( 1, "$ENV{\"RazzleToolPath\"}\\intlsrc.txt", \@srcHash );
  80. @theHashKey = ("Target", "SourceFilename", "SourceTree", "LocTree","LocTreeFilename","Comments");
  81. %tmp=();
  82. for $line( @srcHash)
  83. {
  84. for $curKey ( @theHashKey )
  85. {
  86. if( $line->{ $curKey } =~ /^(.*)(\$\(LANG\))(.*)$/ )
  87. {
  88. $line->{ $curKey } = $1 . lc($pLang) .$3;
  89. }
  90. if( $line->{ $curKey } =~ /^(.*)([c|h])(\$\(PRIMARY_LANG_ID\))(.*)$/ )
  91. {
  92. if( $pLang eq "CHT" || $pLang eq "CHS" )
  93. {
  94. $LCID = substr( $hashCodes{uc($pLang)}->{LCID}, 2, length($hashCodes{uc($pLang)}->{LCID})-2);
  95. $line->{ $curKey } = "prf" . $2 . $LCID .$4;
  96. }
  97. else
  98. {
  99. $priLangID = "0". substr( $hashCodes{uc($pLang)}->{PriLangID}, 2, length($hashCodes{uc($pLang)}->{PriLangID})-2);
  100. $line->{ $curKey } = $1 . $2. $priLangID .$4;
  101. }
  102. }
  103. }
  104. $to = $theToRoot."\\". $line->{ $theToTree };
  105. if( !exists $tmp{$to} ){ $tmp{$to}=(); }
  106. }
  107. if( $pLang eq "USA" )
  108. {
  109. for( keys %tmp )
  110. {
  111. &CkCleanDir( $_, $pIsIncr, $pIsPowerless );
  112. }
  113. }
  114. ###---Perform Copy now.------------------------------//
  115. for $line ( @srcHash )
  116. {
  117. if( $pLang ne "USA" )
  118. {
  119. next if( !&cktarg::CkTarg( $line->{'Target'}, uc($pLang) ) );
  120. }
  121. next if(&IsTargInfsNtsetup( $line, $pLang,$pSrcRoot, $pLocRoot, $pIsIncr, $pIsPowerless, $copyOpt));
  122. $from = $theFromRoot ."\\". $line->{ $theFromTree }."\\".$line->{ $theFromFile};
  123. if( $pLang ne "USA" )
  124. {
  125. if( $line->{ $theFromFile } eq ".")
  126. {
  127. $from = $theFromRoot ."\\". $line->{ $theFromTree }."\\".$line->{ $theToFile };
  128. }
  129. }
  130. $to = $theToRoot."\\". $line->{ $theToTree }. "\\".$line->{ $theToFile };
  131. &PerformCopy( $line->{Target}, $from, $to, $copyOpt);
  132. }
  133. exit( !&comlib::CheckError( $ENV{ERRFILE}, "Copy Successfully" ) );
  134. }
  135. #------------------------------------------------------------------//
  136. #Function: IsTargInfsNtsetup
  137. #Parameter: (1) Line from intlsrc.txt
  138. # (2) Language
  139. # (3) Root of the Source Tree
  140. # (4) Root of the Localized Tree
  141. # (5) Incremental Flag
  142. # (6) Powerless Flag
  143. # (7) xcopy optional flags
  144. #------------------------------------------------------------------//
  145. sub IsTargInfsNtsetup
  146. {
  147. my( $pLine, $pLang, $pSrcRoot, $pLocRoot, $pIsIncr, $pIsPowerless,$pCopyOpt )= @_;
  148. my( $from, $to );
  149. return 0 if( $pLine->{Target} ne "INFS_NTSETUP" && $pLine->{Target} ne "INFS_COMPDATA");
  150. if( $pLine->{Target} eq "INFS_NTSETUP" )
  151. {
  152. $infsSrcTree = "$pSrcRoot\\MergedComponents\\SetupInfs";
  153. $infsLocTree = "$pLocRoot\\infs\\setup";
  154. $isNtsetup=1;
  155. }
  156. else
  157. {
  158. $infsSrcTree = "$pSrcRoot\\MergedComponents\\SetupInfs\\compdata";
  159. $infsLocTree = "$pLocRoot\\infs\\setup\\compdata";
  160. $isNtsetup=0;
  161. }
  162. if( $pLang eq "USA")
  163. {
  164. ###(1)Copy $infsSrcTree\\*.inx => infs\setup
  165. $from = "$infsSrcTree\\*\.inx";
  166. $to = "$infsLocTree\\.";
  167. &CkCleanDir( $to, $pIsIncr, $pIsPowerless );
  168. &PerformCopy( $line->{Target}, $from, $to, $pCopyOpt);
  169. ###(2)Copy $infsSrcTree\\usa\* => $infsLocTree\usa_all
  170. $from = "$infsSrcTree\\usa\\*";
  171. $to = "$infsLocTree\\usa_all";
  172. &CkCleanDir( $to, $pIsIncr, $pIsPowerless );
  173. &PerformCopy( $line->{Target}, $from, "$to\\.", $pCopyOpt);
  174. }
  175. ###(3)If copylang.pl -l:usa, precompile MergedComponents\SetupInfs\usa => to infs\setup\$lang
  176. ### for all $lang's in codes.txt.
  177. ### This step is necessary to make LocStudio load the unlocalized text files,
  178. ### as LS does not understand if statements.
  179. ###
  180. ###(1)Otherwise, copy loc\res\$lang\windows\sources\infs\setup => MergedComponents\SetupInfs\$lang
  181. ### for the localizable txt files, and
  182. ### copy MergedComponents\SetupInfs\usa => MergedComponents\SetupInfs\$lang
  183. ### for the unlocalizable txt files.
  184. ### In the end, MergedComponents\SetupInfs\$lang will have the same list of files as
  185. ### MergedComponents\SetupInfs\usa.
  186. &ClSrc( $pLang, $pSrcRoot, $pLocRoot, $pIsIncr,$pIsPowerless, $pCopyOpt );
  187. return 1;
  188. }
  189. #------------------------------------------------------------------//
  190. #Function: ClSrc
  191. #Parameter: (1) Language
  192. # (2) Root of the Source Tree
  193. # (3) Root of the Localized Tree
  194. # (4) Incremental Flag
  195. # (5) Powerless Flag
  196. # (6) xcopy optional flags
  197. #------------------------------------------------------------------//
  198. sub ClSrc
  199. {
  200. my( $pLang, $pSrcRoot, $pLocRoot,$pIsIncr, $pIsPowerless, $pCopyOpt )=@_;
  201. ###---Get LCID from codes.txt.---------------------------------//
  202. my $srcDir = "$infsSrcTree\\usa";
  203. my @srcFiles = `dir /on /b $srcDir`;
  204. chomp @srcFiles;
  205. if( $pLang eq "USA")
  206. {
  207. my @myLang = sort keys %hashCodes;
  208. for( my $i=0; $i < @myLang; $i++)
  209. {
  210. $destDir = "$infsLocTree\\$myLang[$i]";
  211. &CkCleanDir( $destDir, $pIsIncr, $pIsPowerless );
  212. &PerformCompile( $myLang[$i], \@srcFiles, $srcDir, $destDir, $pIsPowerless, $pCopyOpt);
  213. }
  214. return 1;
  215. }
  216. ###(1)Copy $infsLocTree\* $infsSrcTree\<LANG>
  217. $destDir = "$infsSrcTree\\$pLang";
  218. &CkCleanDir( $destDir, $pIsIncr, $pIsPowerless );
  219. $locDir = $infsLocTree;
  220. @locFiles = `dir /on /b $locDir`;
  221. chomp @locFiles;
  222. for( my $i=0; $i < @locFiles; $i++)
  223. {
  224. &PerformCopy( "INFS_NTSETUP", "$locDir\\$locFiles[$i]", "$destDir\\.", $pCopyOpt);
  225. }
  226. ###Sepcial case for chh
  227. if( lc($pLang) eq "cht" && $isNtsetup )
  228. {
  229. $destDir =~ /(.*)cht$/ || $destDir =~ /(.*)CHT$/;
  230. {
  231. $tmpDestDir = "$1chh";
  232. }
  233. &PerformCopy( "INFS_NTSETUP", "$locDir\\chh\\hivesft\.txt", "$tmpDestDir\\.", $pCopyOpt) ;
  234. }
  235. ###(2)Precompile the files in srcDir but not in locDir=>destDir
  236. %tmp=();
  237. for ( @locFiles ){ $tmp{lc($_)}=1;}
  238. @srcFiles = map( { exists $tmp{lc($_)}?():lc($_)} @srcFiles);
  239. &PerformCompile( $pLang, \@srcFiles, $srcDir, $destDir, $pIsPowerless, $pCopyOpt);
  240. return 1;
  241. }
  242. #------------------------------------------------------------------//
  243. #Function: PerformCompile
  244. #Parameter: (1) Language
  245. # (2) Source File name
  246. # (3) Source File Path
  247. # (4) Target File Path
  248. # (5) Powerless Flag
  249. # (6) xcopy optional flags
  250. #------------------------------------------------------------------//
  251. sub PerformCompile
  252. {
  253. my( $pLang, $pSrcFiles, $pSrcDir, $pDestDir, $pIsPowerless, $pCopyOpt)=@_;
  254. my $PREFLAGS ="";
  255. for ( my $i=0; $i < @$pSrcFiles; $i++)
  256. {
  257. if( lc($pSrcFiles->[$i]) eq "intl\.txt" )
  258. {
  259. &PerformCopy( "INFS_NTSETUP", "$pSrcDir\\$pSrcFiles->[$i]", "$pDestDir\\.", $pCopyOpt);
  260. next;
  261. }
  262. ###Special CHH case for hivesft.txt
  263. if( lc($pSrcFiles->[$i]) eq "hivesft\.txt" && lc($pLang) eq "chh" )
  264. {
  265. $PREFLAGS = "/DLANGUAGE_ID=0xc04 /EP";
  266. }
  267. else
  268. {
  269. $PREFLAGS = "/DLANGUAGE_ID=$hashCodes{uc($pLang)}->{LCID} /EP";
  270. }
  271. $cmdLine="cl /nologo $PREFLAGS $pSrcDir\\$pSrcFiles->[$i] 1\>$pDestDir\\$pSrcFiles->[$i]";
  272. if ( !$pIsPowerless )
  273. {
  274. &comlib::ExecuteSystem( $cmdLine );
  275. }
  276. else
  277. {
  278. print "$cmdLine\n";
  279. }
  280. }
  281. }
  282. #------------------------------------------------------------------//
  283. #Function: CkCleanDir
  284. #Parameter: (1) Directory to be checked and cleaned
  285. # (2) Incremental flag
  286. # (3) Powerless flag
  287. #------------------------------------------------------------------//
  288. sub CkCleanDir
  289. {
  290. my ( $pDir, $pIsIncr, $pIsPowerless )=@_;
  291. if( !$pIsIncr && !$pIsPowerless )
  292. {
  293. if( -e $pDir ){
  294. &comlib::ExecuteSystem( "rd /S /Q $pDir" );
  295. }
  296. }
  297. if( !(-e $pDir) ){
  298. &comlib::ExecuteSystem( "md $pDir");
  299. }
  300. }
  301. #------------------------------------------------------------------//
  302. #Function: PerformCopy
  303. #Parameter: (1) Any String - information purpose, it could be NULL.
  304. # (2) Source of the xcopy
  305. # (3) Target of the xcopy
  306. # (4) xcopy optional flags
  307. #------------------------------------------------------------------//
  308. sub PerformCopy
  309. {
  310. my( $pTarg, $pFrom, $pTo, $pCopyOpt )=@_;
  311. &comlib::ExecuteSystem( "echo F|xcopy $pCopyOpt $pFrom $pTo", "$pTarg:");
  312. }
  313. #------------------------------------------------------------------//
  314. #Function: Usage
  315. #-----------------------------------------------------------------//
  316. sub Usage
  317. {
  318. print <<USAGE;
  319. Perform files copy between the source and localization trees as
  320. described in tools\\intlsrc.txt.
  321. Usage:
  322. $0 -l:<lang> [-x:<SourcePath>] [-y:<LocPath>] [-i] [-p]
  323. -l Language.
  324. -x Root path of the SourceTree.
  325. Defaults to $ENV{_NTBINDIR}.
  326. -y Root path of the LocTree.
  327. Defaults to $ENV{_NTBINDIR}\\usasrc when language is usa.
  328. Defaults to $ENV{_NTBINDIR}\\loc\\res\\<lang>\\windows\\sources otherwise.
  329. -i Incremental. This flag is used for incremental copy.
  330. -p Powerless. Only lists the files that would get copied,
  331. in case the script is run without the powerless flag.
  332. /? Displays usage.
  333. Examples:
  334. $0 -l:usa -x:\\\\ntbld03\\sources -y:\\\\intlnt\\2500.x86.src
  335. Copies sources from the usa build machines for localization.
  336. $0 -l:usa -y:\\\\intlnt\\2500.x86.src
  337. Copies sources from local machines for localization.
  338. $0 -l:jpn -i -p
  339. Queries which localized sources would get copied from the
  340. localization tree to the source tree for jpn.
  341. USAGE
  342. exit(1);
  343. }
  344. #--------------------------------------------------------//
  345. #Cmd entry point for script.
  346. #--------------------------------------------------------//
  347. if (eval("\$0 =~ /" . __PACKAGE__ . "\\.pl\$/i"))
  348. {
  349. # <run perl.exe GetParams.pm /? to get the complete usage for GetParams.pm>
  350. &GetParams ('-n', 'l:','-o', 'x:y:ip', '-p', 'lang srcroot locroot isincr ispowerless', @ARGV);
  351. #Validate or Set default
  352. $lang = uc($lang);
  353. if( !&ValidateParams( $lang, \$srcroot, \$locroot ) ) {exit(1); }
  354. exit( !&copylang::main( $lang, $srcroot,$locroot, $isincr, $ispowerless ) );
  355. }
  356. #--------------------------------------------------------//
  357. #Function: ValidateParams
  358. #--------------------------------------------------------//
  359. sub ValidateParams
  360. {
  361. my ( $pLang, $pSrcRoot, $pLocRoot ) = @_;
  362. if ( !&cklang::CkLang( uc($pLang) ) ) {
  363. $ENV{LOGFILE} = "copylang.log";
  364. $ENV{ERRFILE} = "copylang.err";
  365. errmsg("Invalid language $pLang.");
  366. return 0;
  367. }
  368. #Create log/err file
  369. if( !( -e "$ENV{_NTTREE}\\$lang\\build_logs") )
  370. {
  371. &comlib::ExecuteSystem( "md \"$ENV{_NTTREE}\\$lang\\build_logs\"");
  372. }
  373. $ENV{LOGFILE} = "$ENV{_NTTREE}\\$lang\\build_logs\\copylang.log";
  374. $ENV{ERRFILE} = "$ENV{_NTTREE}\\$lang\\build_logs\\copylang.err";
  375. &comlib::ExecuteSystem( "del $ENV{LOGFILE}" ) if( -e $ENV{LOGFILE} );
  376. &comlib::ExecuteSystem( "del $ENV{ERRFILE}" ) if( -e $ENV{ERRFILE} );
  377. if( !${$pSrcRoot} )
  378. {
  379. $$pSrcRoot = "$ENV{_NTBINDIR}";
  380. }
  381. if( !${$pLocRoot} )
  382. {
  383. if( $pLang eq "USA" )
  384. {
  385. $$pLocRoot = "$ENV{_NTBINDIR}\\usasrc";
  386. }
  387. else
  388. {
  389. $$pLocRoot = "$ENV{_NTBINDIR}\\loc\\res\\$pLang\\windows\\sources";
  390. }
  391. }
  392. return 1;
  393. }
  394. #----------------------------------------------------------------//
  395. #Function: GetParams
  396. #----------------------------------------------------------------//
  397. sub GetParams
  398. {
  399. use GetParams;
  400. #Call pm getparams with specified arguments
  401. &GetParams::getparams(@_);
  402. #Call the usage if specified by /?
  403. if ($HELP){ &Usage();}
  404. }
  405. ###------------------------------------------------------//
  406. =head1 NAME
  407. B<Copylang> - Perform Files copy
  408. =head1 SYNOPSIS
  409. =head1 DESCRIPTION
  410. =head1 INSTANCES
  411. =head2 <myinstances>
  412. <Description of myinstances>
  413. =head1 METHODS
  414. =head2 <mymathods>
  415. <Description of mymathods>
  416. =head1 SEE ALSO
  417. =head1 AUTHOR
  418. <Suemiao Rossignol <[email protected]>>
  419. =cut
  420. 1;