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.

479 lines
9.5 KiB

  1. # USE section
  2. use lib $ENV{ "RazzleToolPath" };
  3. use GetParams;
  4. use CkLang;
  5. use strict;
  6. no strict 'vars';
  7. # GLOBALS
  8. $ScriptName=$0;
  9. $SDXROOT=$ENV{SDXROOT};
  10. $INTLVIEW_FNAME="$SDXROOT\\tools\\intlview.map";
  11. %SDMAP=();
  12. %INTLVIEW=();
  13. $Lang="";
  14. $Project="";
  15. $Quiet="";
  16. $CODEBASE="NT";
  17. $BRANCH=$ENV{_BuildBranch};
  18. $LOGGING=0;
  19. $ERROR=1;
  20. $WARNING=2;
  21. %MSG=($LOGGING => "", $ERROR => "error: ", $WARNING => "warning: ");
  22. # MAIN {
  23. # Parse the command line parameters.
  24. &ParseCmdLine( @ARGV );
  25. # Verify the command line parameters and the environment.
  26. &VerifyParams();
  27. # Mark sd.map as read only.
  28. &MarkReadWrite();
  29. # Load data from the "SD.MAP" file.
  30. &LoadSDMap();
  31. &LoadIntlview();
  32. if ( $Lang ) {
  33. &EnlistLangProj($Lang);
  34. } else {
  35. &EnlistCodeProj($Project);
  36. }
  37. # Mark sd.map as read only.
  38. &MarkReadOnly();
  39. # } # MAIN
  40. sub EnlistLangProj {
  41. my ( $lang ) = @_;
  42. &EnlistProject("$lang\_res");
  43. &EnlistProject("$lang\_bin");
  44. &MapProject("$lang\_res");
  45. &MapProject("$lang\_bin");
  46. } # EnlistLangProj
  47. sub EnlistCodeProj {
  48. my ( $projname ) = @_;
  49. foreach (sort keys %INTLVIEW) {
  50. if ( $projname && lc($projname) ne lc($_) ) {
  51. next;
  52. }
  53. &EnlistProject($_);
  54. &MapProject($_);
  55. }
  56. } # EnlistCodeProj
  57. sub EnlistProject {
  58. my ( $projname ) = @_;
  59. if ( !$Quiet ) {
  60. &AskForOK( $projname );
  61. }
  62. printf "\n";
  63. &DisplayMsg( $LOGMSG, "Enlisting project \"$projname\" in branch \"$BRANCH\"...");
  64. if ( exists $SDMAP{lc($projname)} ) {
  65. &DisplayMsg( $LOGMSG, "Already enlisted in project \"$projname\".");
  66. return;
  67. }
  68. &ExecuteCmd( "sdx enlist $projname /q");
  69. # As sdx does not set the error level in case of errors, reload the SD.MAP
  70. # mapping file to verify that the project got actually enlisted.
  71. &LoadSDMap();
  72. if ( ! exists $SDMAP{lc($projname)} ){
  73. &FatalError( "Enlist project \"$projname\" command failed." );
  74. } else {
  75. &DisplayMsg( $LOGMSG, "Project \"$projname\" enlisted successfully." );
  76. }
  77. return;
  78. } # EnlistProject
  79. sub MapProject {
  80. my ( $projname ) = @_;
  81. my $workdir = "$SDXROOT\\$SDMAP{lc($projname)}";
  82. &DisplayMsg( $LOGMSG, "cd /d $workdir");
  83. chdir ( $workdir ) ||
  84. &FatalError( "Unable to change directory to \"$workdir\" to update project's \"$projname\" client view.");
  85. &ExecuteCmd( "sd client -o \> sd.client" );
  86. if ( &UpdateClient( $projname ) ) {
  87. &ExecuteCmd( "sd client -i \< sd.client" );
  88. &DisplayMsg( $LOGMSG, "Project \"$projname\" mapped successfully." );
  89. }
  90. &ExecuteCmd( "del sd.client" );
  91. } # MapProject
  92. sub UpdateClient {
  93. my ( $projname ) = @_;
  94. my $workdir = "$SDXROOT\\$SDMAP{lc($projname)}";
  95. my @sdclient = ();
  96. my $i = 0;
  97. my $j = 0;
  98. open( FILE, "sd.client" ) ||
  99. &FatalError("Unable to open file \"$workdir\\sd.client\" for reading.");
  100. @sdclient = <FILE>;
  101. close( FILE );
  102. for ( $i=0; $i < @sdclient; $i++ ) {
  103. if ( $sdclient[$i] =~ /^View:/ ) {
  104. last;
  105. }
  106. }
  107. if ( $i == @sdclient ) {
  108. &FatalError( "");
  109. }
  110. if ($projname=~/$lang/i) {
  111. while( $i < @sdclient ) {
  112. if ( ($sdclient[$i] =~ /$projname/i) || ($sdclient[$i] =~ /^\s*$/) ) {
  113. # remove this language's item in client view
  114. splice(@sdclient, $i, 1);
  115. } else {
  116. $i++;
  117. }
  118. }
  119. }
  120. $#sdclient=$i;
  121. for ( $j=0; $j < @{$INTLVIEW{lc($projname)}}; $j++ ) {
  122. $sdclient[$i+$j+1] = sprintf( "\t%s\n", ${$INTLVIEW{lc($projname)}}[$j]);
  123. $sdclient[$i+$j+1] =~ s/\<client\>/$SDMAP{client}/;
  124. }
  125. &DisplayMsg( $LOGMSG, "Saving project's \"$projname\" updated client view...");
  126. open(FILE, ">sd.client") ||
  127. &FatalError( "Unable to open \"$workdir\\sd.client\" for writing." );
  128. for ($i=0; $i < @sdclient; $i++ ) {
  129. printf FILE "$sdclient[$i]";
  130. }
  131. close (FILE);
  132. return 1;
  133. } # UpdateClient
  134. sub LoadIntlview {
  135. my @mapfile = ();
  136. my $i=0;
  137. my $key;
  138. my $value;
  139. open( FILE, $INTLVIEW_FNAME ) ||
  140. &FatalError( "Unable to load input file $INTLVIEW_FNAME." );
  141. @mapfile = <FILE>;
  142. close( FILE );
  143. for ($i=0; $i < @mapfile; $i++) {
  144. foreach ($mapfile[$i]) {
  145. SWITCH: {
  146. # commented line
  147. if ( /\s*;/ ) { last SWITCH;}
  148. # valid entry
  149. if (/\s*(\S+)\s+(\S+.*)/ ) {
  150. ($key, $value) = ($1, $2);
  151. next if (( !$Lang ) && ( $key =~ /lang/ ));
  152. $key =~ s/\<lang\>/lc$Lang/eg;
  153. $value =~ s/\<lang\>/lc$Lang/eg;
  154. $value =~ s/\<branch\>/lc$BRANCH/eg;
  155. push @{$INTLVIEW{lc($key)}}, $value;
  156. last SWITCH;
  157. }
  158. # default
  159. last SWITCH;
  160. } # SWITCH
  161. } # foreach
  162. } # for
  163. # foreach (sort keys %INTLVIEW) {
  164. # for ($i=0; $i < @{$INTLVIEW{$_}}; $i++ ) {
  165. # printf "key=$_, value[$i]=${$INTLVIEW{$_}}[$i]\n";
  166. # }
  167. # }
  168. } # LoadIntlview
  169. sub LoadSDMap {
  170. my @mapfile=();
  171. my $i=0;
  172. my $sdmap="$SDXROOT\\sd.map";
  173. foreach (keys %SDMAP) {
  174. delete $SDMAP{$_};
  175. }
  176. ( -e $sdmap ) || &FatalError( "Unable to find file $sdmap" );
  177. open( FILE, $sdmap ) || &FatalError( "Unable to open file $sdmap." );
  178. @mapfile=<FILE>;
  179. close(FILE);
  180. for ($i=0; $i < @mapfile; $i++) {
  181. foreach ($mapfile[$i]) {
  182. SWITCH: {
  183. # commented lines
  184. if ( /\s*#/ ) { last SWITCH;}
  185. # valid entries
  186. if (/\s*(\S+)\s*=\s*(\S+)/ ) {
  187. $SDMAP{lc($1)}=$2;
  188. last SWITCH;
  189. }
  190. # default
  191. last SWITCH;
  192. } # SWITCH
  193. } # foreach
  194. } # for
  195. # verify codebase
  196. ( exists $SDMAP{codebase} ) ||
  197. &FatalError( "CODEBASE is not listed in the SD mapping file $sdmap." );
  198. ( lc($SDMAP{codebase}) eq lc($CODEBASE) ) ||
  199. &FatalError( "Codebase '$CODEBASE' does not match the SDXROOT '$SDMAP{codebase}' codebase." );
  200. # verify branch
  201. ( exists $SDMAP{branch} ) ||
  202. &FatalError( "BRANCH is not listed in the SD mapping file $sdmap." );
  203. ( lc($SDMAP{branch}) eq lc($BRANCH) ) ||
  204. &DisplayMsg( $WARNING, "Branch \"$BRANCH\" does not match the SDXROOT \"$SDMAP{branch}\" branch.");
  205. # verify client
  206. ( exists $SDMAP{client} ) ||
  207. &FatalError( "CLIENT is not listed in the SD mapping file $sdmap." );
  208. } # LoadSDMap
  209. sub MarkReadOnly {
  210. my $sdmap="$SDXROOT\\sd.map";
  211. &ExecuteCmd( "attrib +h +r $sdmap");
  212. } # MarkReadOnly
  213. sub MarkReadWrite {
  214. my $sdmap="$SDXROOT\\sd.map";
  215. &ExecuteCmd( "attrib +h -r $sdmap");
  216. } # MarkReadWrite
  217. sub AskForOK {
  218. my ( $projname ) = @_;
  219. printf( "\n About to enlist in project $projname.\n" );
  220. printf( " Press Ctrl+C in the next 30s if you wish to exit script.\n");
  221. printf( " ...");
  222. sleep 30;
  223. } # AskForOK
  224. sub ExecuteCmd {
  225. my ($command) = @_;
  226. DisplayMsg( $LOGMSG, $command );
  227. if ( system( "$command" ) ) {
  228. &FatalError( "Command \"$command\" failed." );
  229. }
  230. } # ExecuteCmd
  231. sub ParseCmdLine {
  232. my @arguments = @_;
  233. my @syntax = (
  234. -n => '',
  235. -o => 'b:l:p:q',
  236. -p => "BRANCH Lang Project Quiet"
  237. );
  238. &GetParameters( \@syntax, \@arguments );
  239. } # ParseCmdLine
  240. sub GetParameters {
  241. my ($syntax, $arguments)=@_;
  242. my $getparams=GetParams->new;
  243. &{$getparams->{-Process}}(@$syntax,@$arguments);
  244. if ( $HELP ) {
  245. &Usage();
  246. }
  247. } # GetParameters
  248. sub VerifyParams {
  249. # Must run this script from a razzle
  250. if ( !$ENV{RazzleToolPath} || !$ENV{SDXROOT} ) {
  251. &DisplayMsg( $ERROR, "Please run this script from a razzle." );
  252. &Usage();
  253. }
  254. if ( $Lang ) {
  255. if( uc($Lang) eq "INTL" ){
  256. $Lang = "";
  257. }
  258. else
  259. {
  260. # Only MAIN is accepted for language projects.
  261. if ( ! &cklang::CkLang($Lang) ) {
  262. &DisplayMsg( $ERROR, "Invalid language $Lang." );
  263. &Usage();
  264. }
  265. if ( lc($BRANCH) ne "main" ) {
  266. #$BRANCH = "main";
  267. #&DisplayMsg( $WARNING, "Branch has been reset to \"main\", as \"main\" is the only branch valid for language projects." );
  268. }
  269. }
  270. }
  271. if ( $Lang && $Project ) {
  272. &DisplayMsg( $ERROR, "You can specify language or project, but not both." );
  273. &Usage();
  274. }
  275. } # VerifyParams
  276. sub DisplayMsg {
  277. print "$ScriptName : $MSG{@_[0]}@_[1]\n";
  278. } # DisplayMsg
  279. sub FatalError {
  280. my ( $strerr ) = @_;
  281. &DisplayMsg( $ERRMSG, $strerr );
  282. exit 1;
  283. } # FatalError
  284. sub Usage {
  285. print <<USAGE;
  286. perl $0 - Enlist and map the projects pertinent to Whistler international.
  287. Usage:
  288. perl $0 [-b:<branch>] [-l:<language> | -p:<project>] [-q]
  289. <branch > Source depot branch.
  290. Enlist in the specified branch.
  291. Default is %_BuildBranch%, $BRANCH in this case.
  292. <language> Language.
  293. If not specified, enlist in the source projects.
  294. Acepted values are "intl" and any language
  295. listed in codes.txt.
  296. If "intl", enlist the source projects.
  297. Otherwise, enlist and map the language projects
  298. <language>_res and <language>_bin.
  299. <project> Project name.
  300. If specified, enlist and map the given source project.
  301. If no project or language is specified, enlist and map the source
  302. projects. Tools\\intlview.map lists the projects and the client
  303. view mappings pertinent to international builds.
  304. q Quiet mode.
  305. Examples:
  306. perl $0 /q
  307. Enlist and map the source projects, default branch.
  308. perl $0 -b:beta1 -l:intl /q
  309. Same as above, beta1 branch.
  310. perl $0 -p:Admin
  311. Enlist and map the admin project, default branch.
  312. perl $0 -l:ger /q
  313. Enlist and map ger_res and ger_bin, main branch.
  314. USAGE
  315. exit(1);
  316. } # Usage