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.

456 lines
10 KiB

  1. # USE section
  2. use GetParams;
  3. use strict;
  4. no strict 'vars';
  5. # GLOBAL Variables
  6. $ScriptName=$0;
  7. $Lang="";
  8. $SDXROOT=$ENV{SDXROOT};
  9. $CompName="";
  10. $CompType="";
  11. $ProjName="";
  12. $Enlist=0;
  13. $Map=0;
  14. $Sync=0;
  15. $Timestamp="";
  16. $Branch="locpart";
  17. $Codebase="NT";
  18. %SDMAP=();
  19. # GLOBAL Constants
  20. @COMPTYPES=("res", "bin", "tools");
  21. @BRANCHES=("main", "locpart");
  22. $LOGGING=0;
  23. $ERROR=1;
  24. %MSG=($LOGGING => "", $ERROR => "error: ");
  25. # MAIN {
  26. # Parse the command line parameters.
  27. &ParseCmdLine(@ARGV);
  28. # Verify the command line parameters and the environment.
  29. &VerifyParams();
  30. # Load data from the "SD.MAP" file.
  31. &LoadSDMap();
  32. # Set project name.
  33. $ProjName = sprintf ("%s_%s", $Lang, $CompType);
  34. # Enlist project.
  35. if ($Enlist) {
  36. &EnlistProject($ProjName);
  37. }
  38. # Set client view for component.
  39. if ( $Map || $Enlist ) {
  40. &MapClientView( $ProjName, $CompName );
  41. }
  42. # Sync project.
  43. if ($Sync) {
  44. &SyncProject( $ProjName, $CompName, $Timestamp );
  45. }
  46. # }
  47. sub EnlistProject {
  48. my ($projname) = @_;
  49. &DisplayMsg( $LOGMSG, "Enlisting project \"$projname\"...");
  50. if ( exists $SDMAP{lc($projname)} ) {
  51. &DisplayMsg( $LOGMSG, "Already enlisted in project \"$projname\".");
  52. return;
  53. }
  54. system( "sdx enlist $projname /q");
  55. # As sdx does not set the error level in case of errors, reload the SD.MAP
  56. # mapping file to verify that the project got actually enlisted.
  57. &LoadSDMap();
  58. if ( ! exists $SDMAP{lc($projname)} ){
  59. &FatalError( "Enlist project \"$projname\" command failed." );
  60. } else {
  61. &DisplayMsg( $LOGMSG, "Project \"$projname\" enlisted successfully." );
  62. }
  63. return;
  64. } # EnlistProject
  65. sub MapClientView {
  66. my ( $projname, $compname ) = @_;
  67. my $workdir="$SDXROOT\\$SDMAP{lc($projname)}";
  68. # Any ExecuteCmd failure is a fatal error.
  69. &DisplayMsg( $LOGMSG, "Mapping client view for project \"$projname\" and component \"$compname\"..." );
  70. &DisplayMsg($LOGMSG, "cd /d $workdir");
  71. chdir( $workdir ) ||
  72. &FatalError( "Unable to change directory to \"$workdir\" to update project's \"$projname\" client view." );
  73. &ExecuteCmd( "sd client -o \> sd.client" );
  74. if ( &UpdateClient( $projname, $compname ) ) {
  75. &ExecuteCmd( "sd client -i \< sd.client" );
  76. &DisplayMsg( $LOGMSG, "Component \"$compname\" successfully mapped in project's \"$projname\" client view.");
  77. }
  78. &ExecuteCmd( "del sd.client");
  79. } # MapClientView
  80. sub UpdateClient {
  81. my ($projname, $compname) = @_;
  82. my $workdir="$SDXROOT\\$SDMAP{lc($projname)}";
  83. my @sdclient=();
  84. # Flag set to 1 if at least one entry is found in the client view for the given project.
  85. my $MAPPED_PROJECT_FLAG=0;
  86. # Flag set to 1 if the component is already mapped in the client view.
  87. my $MAPPED_COMPONENT_FLAG=0;
  88. # Flag set to 1 if the client view file is modified.
  89. # The client view is modified in one of the following situations:
  90. # 1. The component is already mapped, but for a different branch from the given one.
  91. # 2. A new entry, specific to the given component, has been added.
  92. # 3. The '$projname/...' entry has been replaced by the '$projname/*' entry.
  93. my $MODIFIED_FLAG=0;
  94. open( FILE, "sd.client" ) || &FatalError( "Unable to open file $workdir\\sd.client." );
  95. @sdclient=<FILE>;
  96. close(FILE);
  97. for ( $i=0; $i < @sdclient; $i++ ) {
  98. if ( $sdclient[$i] =~ /\/$projname/i ) {
  99. $MAPPED_PROJECT_FLAG=1;
  100. if ( $sdclient[$i] =~ /\/$projname\/$compname\//i ) {
  101. $MAPPED_COMPONENT_FLAG=1;
  102. $sdclient[$i] =~ /\/\/depot\/(\w+)\//i;
  103. if ( lc($1) ne lc($Branch) ) {
  104. $sdclient[$i] =~s/\/$1\//\/$Branch\//;
  105. $MODIFIED_FLAG=1;
  106. }
  107. }
  108. if ( $sdclient[$i] =~ /\/$projname\/\.\.\./i ) {
  109. $sdclient[$i] =~ s/\/\.\.\./\/*/g;
  110. $MODIFIED_FLAG=1;
  111. }
  112. }
  113. }
  114. $MAPPED_PROJECT_FLAG ||
  115. &FatalError( "No entry found for \"$projname\". Enlist project \"$projname\" first." );
  116. if ( !$MAPPED_COMPONENT_FLAG ) {
  117. my $last=@sdclient;
  118. $sdclient[$last]=$SDMAP{lc($projname)};
  119. $sdclient[$last] =~ s/\\/\//g;
  120. $sdclient[$last] = sprintf (" \/\/depot\/\%s\/%s\/%s\/... \/\/%s\/%s\/%s\/...\r\n",
  121. $Branch,
  122. $projname,
  123. $compname,
  124. $SDMAP{client},
  125. $sdclient[$last],
  126. $compname);
  127. $MODIFIED_FLAG=1;
  128. }
  129. if ( $MODIFIED_FLAG ) {
  130. &DisplayMsg( $LOGMSG, "Saving project's \"$projname\" updated client view...");
  131. open(FILE, ">sd.client") ||
  132. &FatalError( "Unable to open \"$workdir\\sd.client\" for writing." );
  133. for ($i=0; $i < @sdclient; $i++ ) {
  134. printf FILE $sdclient[$i];
  135. }
  136. close (FILE);
  137. } else {
  138. &DisplayMsg( $LOGMSG, "Project's \"$projname\" client view is up-to-date.");
  139. }
  140. return $MODIFIED_FLAG;
  141. } # UpdateClient
  142. sub SyncProject {
  143. my ( $projname, $compname, $timestamp ) = @_;
  144. my $workdir = "$SDXROOT\\$SDMAP{lc($projname)}";
  145. my $cmdsync = "";
  146. &DisplayMsg($LOGMSG, "cd /d $workdir");
  147. chdir( $workdir ) ||
  148. &FatalError( "Unable to change directory to $workdir in order to sync up the tree." );
  149. $cmdsync = "sd sync *";
  150. if ( $timstamp ) {
  151. $cmdsync .= @$timestamp;
  152. }
  153. &ExecuteCmd( $cmdsync );
  154. $cmdsync = "sd sync $compname\\...";
  155. if ( $timstamp ) {
  156. $cmdsync .= @$timestamp;
  157. }
  158. # If it fails, ExecuteCmd exits the script automatically.
  159. &ExecuteCmd( $cmdsync );
  160. # Workaround: sd sync does not set the errorlevel in case of error.
  161. ( -e $compname ) || &FatalError( "Command \"$cmdsync\" failed." );
  162. &DisplayMsg( $LOGMSG, "Component \"$compname\" of project \"$projname\" synchronized successfully." );
  163. } # SyncProject
  164. sub LoadSDMap {
  165. my @mapfile=();
  166. my $i=0;
  167. my $sdmap="$SDXROOT\\sd.map";
  168. foreach (keys %SDMAP) {
  169. delete $SDMAP{$_};
  170. }
  171. ( -e $sdmap ) || &FatalError( "Unable to find file $sdmap" );
  172. open( FILE, $sdmap ) || &FatalError( "Unable to open file $sdmap." );
  173. @mapfile=<FILE>;
  174. close(FILE);
  175. for ($i=0; $i < @mapfile; $i++) {
  176. foreach ($mapfile[$i]) {
  177. SWITCH: {
  178. # commented lines
  179. if ( /\s*#/ ) { last SWITCH;}
  180. # valid entries
  181. if (/\s*(\S+)\s*=\s*(\S+)/ ) {
  182. $SDMAP{lc($1)}=$2;
  183. last SWITCH;
  184. }
  185. # default
  186. last SWITCH;
  187. } # SWITCH
  188. } # foreach
  189. } # for
  190. # verify codebase
  191. ( exists $SDMAP{codebase} ) ||
  192. &FatalError( "CODEBASE is not listed in the SD mapping file $sdmap." );
  193. ( lc($SDMAP{codebase}) eq lc($Codebase) ) ||
  194. &FatalError( "Codebase '$Codebase' does not match the SDXROOT '$SDMAP{codebase}' codebase." );
  195. # verify branch
  196. ( exists $SDMAP{branch} ) ||
  197. &FatalError( "BRANCH is not listed in the SD mapping file $sdmap." );
  198. # verify client
  199. ( exists $SDMAP{client} ) ||
  200. &FatalError( "CLIENT is not listed in the SD mapping file $sdmap." );
  201. } # LoadSDMap
  202. sub ParseCmdLine {
  203. my @arguments = @_;
  204. if ( @_ == 0 ) {
  205. &Usage();
  206. }
  207. my @syntax=(
  208. -n => 'l:d:y:',
  209. -o => 'emst:b:',
  210. -p => "Lang CompName CompType Enlist Map Sync Timestamp Branch"
  211. );
  212. &GetParameters(\@syntax, \@arguments);
  213. } # ParseCmdLine
  214. sub ExecuteCmd {
  215. my ($command) = @_;
  216. DisplayMsg( $LOGMSG, $command );
  217. if ( system( "$command" ) ) {
  218. &FatalError( "Command \"$command\" failed." );
  219. }
  220. }
  221. sub VerifyParams {
  222. my $i=0;
  223. my $strerr="";
  224. # Must run this script from a razzle
  225. if ( !$ENV{RazzleToolPath} || !$ENV{SDXROOT} ) {
  226. &DisplayMsg($ERROR, "Please run this script from a razzle.\n");
  227. &Usage();
  228. }
  229. # Verify component types
  230. for ( $i=0; $i < @COMPTYPES; $i++ ) {
  231. if ( lc($CompType) eq lc($COMPTYPES[$i]) ) {
  232. last;
  233. }
  234. }
  235. if ( $i == @COMPTYPES ) {
  236. for ( $i=0; $i < @COMPTYPES; $i++ ) {
  237. $strerr .= "$COMPTYPES[$i] ";
  238. }
  239. &DisplayMsg($ERROR, "Component type must be one of { $strerr}");
  240. &Usage();
  241. }
  242. # If component type is "tools", then language must be "usa" and viceverse.
  243. if ( lc($CompType) eq "tools" || lc($Lang) eq "usa" ) {
  244. ( lc($Lang) eq "usa" && lc($CompType) eq "tools" ) ||
  245. &FatalError( "Only language \"usa\" can be used with \"tools\" as the component type.");
  246. }
  247. # If neither of e, m, and s is specified, set them all.
  248. if ( !$Enlist && !$Map && !$Sync ) {
  249. $Enlist=1;
  250. $Map=1;
  251. $Sync=1;
  252. }
  253. } # VerifyParams
  254. sub GetParameters {
  255. my ($syntax, $arguments)=@_;
  256. my $getparams=GetParams->new;
  257. &{$getparams->{-Process}}(@$syntax,@$arguments);
  258. if ( $HELP ) {
  259. &Usage();
  260. }
  261. } # GetParameters
  262. sub DisplayMsg {
  263. print "$ScriptName : $MSG{@_[0]}@_[1]\n";
  264. } # DisplayMsg
  265. sub FatalError {
  266. my ( $strerr ) = @_;
  267. &DisplayMsg( $ERRMSG, $strerr );
  268. exit 1;
  269. } # FatalError
  270. sub Usage {
  271. print <<USAGE;
  272. perl $0 - Enlist, Map, and Sync localization specific projects.
  273. This script is used by the Whistler localization
  274. partners to set up their Source Depot enlistments.
  275. Usage:
  276. perl $0 -l:<language>
  277. -d:<compname>
  278. -y:res|bin
  279. [-e] [-m] [-s [-t:<timestamp>]]
  280. [-b:<branch>]
  281. <language> Language.
  282. <compname> Component name.
  283. res|bin Component type: resource or binary type.
  284. Also, use 'tools' as component type and 'usa'
  285. as language to enlist in the 'tools' project.
  286. e Enlist project.
  287. m Map client view.
  288. s Sync project.
  289. If none of e, m, and s is specified, they are all executed.
  290. <timestamp> Timestamp to use with sync. Use the format:
  291. yyyy/mm/dd or yyyy/mm/dd:hh:mm:ss.
  292. <branch> Branch name. Default value is "locpart".
  293. Examples:
  294. perl $0 -l:ger -y:res -d:windows
  295. perl $0 -l:jpn -y:bin -d:windows
  296. perl $0 -l:usa -y:tools -d:windows
  297. USAGE
  298. exit(1);
  299. } # Usage