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.

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