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.

794 lines
25 KiB

  1. @perl -x "%~dpnx0" %*
  2. @goto :EOF
  3. #!perl
  4. # ---------------------------------------------------------------------------
  5. # Script: snapbin.pl
  6. #
  7. # (c) 2000 Microsoft Corporation. All rights reserved.
  8. #
  9. # Purpose: Snapshot US binaries tree to INTL.
  10. #
  11. # Version: 1.00 (05/10/2000) : (bensont) Snap the binaries tree
  12. # 1.01 (05/10/2000) : (bensont) Create __BldInfo__usa__ file
  13. # Version: 1.5 (03/12/2001) : (SERGUEIK) snapbin.pl => snapbin.cmd
  14. #
  15. #---------------------------------------------------------------------
  16. # Set Package
  17. package SnapBin;
  18. # Set the script name
  19. $ENV{script_name} = 'snapbin.cmd';
  20. # Set version
  21. $VERSION = '1.5';
  22. require 5.003;
  23. # Use section
  24. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  25. use lib $ENV{RAZZLETOOLPATH};
  26. use PbuildEnv;
  27. use ParseArgs;
  28. use File::DosGlob qw(glob);
  29. use GetParams;
  30. use GetIniSetting;
  31. use LocalEnvEx;
  32. use Logmsg;
  33. use strict;
  34. use vars qw($lang) ;
  35. use vars qw(
  36. $NETBIOS_COMMAND
  37. $NETVIEW
  38. $ROBOCOPYLOG
  39. $BUILD_NAME_MASK
  40. $DEBUG);
  41. use vars qw($BinarySnapServer
  42. $BinarySnapServers
  43. $BuildNum
  44. $_BuildArch
  45. $_BuildType
  46. $_BuildBranch
  47. $DFSAlternateBranchName
  48. $_BuildTimeStamp
  49. $_BldMarkerFile
  50. $SourceTree
  51. $SourceTreeChoice
  52. $TargetTree
  53. $RoboCopyCmd
  54. $RoboCopyLog
  55. $SnapList
  56. $Incremental
  57. );
  58. use HashText;
  59. use GetIniSetting;
  60. my $NETBIOS_COMMAND = "NET VIEW computer";
  61. my $BUILD_NAME_MASK = q(${BuildNum}.${_BuildArch}${_BuildType}.${_BuildBranch}.([0-9\-]+).${lang});
  62. $BUILD_NAME_MASK =~ s/(\.|[^[]\\a-z0-9_{}()]+)/\Q$1\E/ig;
  63. # Main Function
  64. sub CmdMain {
  65. unless ( &GetIniSetting::CheckIniFile ) {
  66. exit errmsg( "Failed to find ini file ..." );
  67. return;
  68. }
  69. $NETVIEW and &BinarySnapServer($BuildNum, $BinarySnapServer);
  70. return unless &PrepareRoboCopyCmd;
  71. &ExecuteRoboCopy;
  72. &ReExRobocopy($RoboCopyCmd, $RoboCopyCmd, $SourceTree, $TargetTree);
  73. my $dummy = ($NETVIEW) ? &GenerateBldInfo :
  74. &CreateBldInfo($_BuildBranch);
  75. &CountFiles;
  76. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  77. # End CmdMain code section
  78. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  79. }
  80. sub CountFiles{
  81. &logmsg("DESTINATION CHECK: ". &BackTick(<<COUNTING));
  82. \@echo on
  83. rem This is a comment
  84. : note that delayed variable expansion seems not to work.
  85. set WC=%RAZZLETOOLPATH%\\x86\\wc.exe
  86. for /F %. in ('dir /a-d/b/s %_NTTREE% ^|%WC%') do @(echo %. files in ^%_NTTREE^% ^($_BuildArch^))
  87. endlocal
  88. COUNTING
  89. 1;
  90. }
  91. # &SourceTree
  92. #
  93. # net view the setver to see the available builds matching the
  94. # $BuildNum, $_BuildArch, $_BuildType, $_BuildBranch
  95. # implemented via the netBios pipe command
  96. sub SourceTree{
  97. # BinarySnapServer
  98. # suggested by MikeR
  99. no strict 'refs';
  100. local ($BinarySnapServer, $BuildNum, $_BuildArch, $_BuildType, $_BuildBranch, $lang) = @_;
  101. my $BUILD_NAME_MASK = $BUILD_NAME_MASK;
  102. my $NETBIOS_COMMAND = $NETBIOS_COMMAND;
  103. $NETBIOS_COMMAND =~ s/computer/$BinarySnapServer/;
  104. $BUILD_NAME_MASK =~ s/\$\{?(\w+)\b\}?/${$1}/egi;
  105. $DEBUG and print STDERR "netbios command: " , $NETBIOS_COMMAND, "\n";
  106. $DEBUG and print STDERR "build name mask: ", $BUILD_NAME_MASK, "\n";
  107. $DEBUG and print STDERR "available builds list:\n",
  108. grep
  109. {/$BUILD_NAME_MASK/i}
  110. qx($NETBIOS_COMMAND);
  111. [map
  112. {$_->[0]}
  113. map
  114. {[split /\s+/]}
  115. grep
  116. {/$BUILD_NAME_MASK/i}
  117. qx($NETBIOS_COMMAND)];
  118. use strict 'refs';
  119. }
  120. # &_BuildTimeStamp
  121. # filter out the time stamp part of the
  122. # build name
  123. sub _BuildTimeStamp{
  124. no strict 'refs';
  125. local ($_BuildTimeStamp, $BuildNum, $_BuildArch, $_BuildType, $_BuildBranch, $lang) = @_;
  126. my $BUILD_NAME_MASK = $BUILD_NAME_MASK;
  127. $BUILD_NAME_MASK =~ s/\$\{?(\w+)\b\}?/${$1}/egi;
  128. map
  129. {(s/$BUILD_NAME_MASK/$1/ig)}
  130. @$_BuildTimeStamp;
  131. $_BuildTimeStamp;
  132. use strict 'refs';
  133. }
  134. sub BinarySnapServer{
  135. #
  136. # 1. Clean the variables inherited from the default execution environment:
  137. # 2. Read the ini file to relate the build BinarySnapServer
  138. # BinarySnapServer label
  139. # suggested by MikeR
  140. # 3. Given the BinarySnapServer and the %_BUILD...% parameters, determine
  141. # the SourceTree and the _BuildTimeStamp.
  142. #
  143. #
  144. my $_BuildTimeStamps, $SourceTreeChoice;
  145. local $BuildNum = shift;
  146. $SourceTree = undef;
  147. $BinarySnapServer = shift;
  148. $BinarySnapServers = [];
  149. push @$BinarySnapServers, $BinarySnapServer if $BinarySnapServer;
  150. scalar @$BinarySnapServers or
  151. $BinarySnapServers = [split /\s/,
  152. &GetIniSetting::GetSetting( "BinarySnapServers")];
  153. $DEBUG and print STDERR "Binary Snap Servers: @$BinarySnapServers\n";
  154. foreach my $BinarySnapServer (@$BinarySnapServers){
  155. my @arguments = ($BuildNum,
  156. $ENV{"_BuildArch"},
  157. $ENV{"_BuildType"},
  158. $ENV{"_BuildBranch"},
  159. $ENV{"lang"});
  160. $SourceTreeChoice = &SourceTree($BinarySnapServer, @arguments);
  161. scalar @$SourceTreeChoice or next;
  162. $SourceTree = "\\\\".$BinarySnapServer."\\".$SourceTreeChoice->[0];
  163. $DEBUG and print STDERR "Source tree: " , $SourceTree, "\n";
  164. $_BuildTimeStamps=&_BuildTimeStamp($SourceTreeChoice, @arguments);
  165. scalar @$_BuildTimeStamps or next;
  166. $_BuildTimeStamp = $_BuildTimeStamps->[0];
  167. $DEBUG and print STDERR "Build time stamp: ", $_BuildTimeStamp, "\n";
  168. # policy: pick the first available.
  169. $DEBUG or return;
  170. }
  171. $DEBUG or errmsg("unable to determine snap parameters for ".
  172. "binary Snap Servers: @$BinarySnapServers, ".
  173. "build number: $BuildNum, ".
  174. "giving up\n");
  175. $DEBUG or exit (0);
  176. &logmsg($NETBIOS_COMMAND);
  177. &logmsg($BUILD_NAME_MASK);
  178. }
  179. # BackTick
  180. # sample usage: &BackTick("dir");
  181. # &BackTick(<<BLOCKBOUNDARY);
  182. # ...cmd code...
  183. # BLOCKBOUNDARY
  184. # passes block of code to the cmd interpreter.
  185. # lines are concatenated
  186. # commened ones removed from the $cmd
  187. # useful when the code is already
  188. # developed and just needs to be inserted in place
  189. # has limitations.
  190. sub BackTick{
  191. my ($cmd) = @_;
  192. my $res = undef;
  193. $cmd = join(" &", grep (!/^:|REM/i, ($cmd =~ /^(.+)/gm)));
  194. $res=qx ($cmd);
  195. $res;
  196. }
  197. # PrepareRoboCopyCmd
  198. # Purpose : Reference $SourceTree, $TargetTree and file $SnapList to create Robocopy statement
  199. #
  200. # Input : none
  201. # Output : 0 for fails, 1 for success
  202. #
  203. # Note : The Robocopy statement is stored in $RoboCopyCmd
  204. sub PrepareRoboCopyCmd {
  205. my ($Excludedirs, $Excludefiles, $Cmd, $OtherOptions)=();
  206. my %snaplist;
  207. my $machines;
  208. $machines = "machines.txt" unless $machines;
  209. my $Mirror = "/MIR";
  210. -d $TargetTree or qx("md $TargetTree");
  211. HashText::Read_Text_Hash(0, $SnapList, \%snaplist) if ((defined $SnapList) && ($SnapList ne '-'));
  212. # HashText::Read_Text_Hash(1, $machines, \@machines);
  213. # If <var> defined in string, evaluate by the order: global variable, environment variable. Report error if can not evaluate
  214. $SourceTree =~ s/\<(\w+)\>/(eval "defined \$SnapBin::$1") ?
  215. eval "\$SnapBin::$1":((exists $ENV{$1})?
  216. $ENV{$1}:errmsg("Unable to eval $1 in $SourceTree; verify your razzle environment"))/ge;
  217. $TargetTree =~ s/\<(\w+)\>/(eval "defined \$SnapBin::$1") ?
  218. eval "\$SnapBin::$1":((exists $ENV{$1})?
  219. $ENV{$1}:errmsg("Unable to eval $1 in $TargetTree; verify your razzle environment"))/ge;
  220. # If source tree not exist
  221. if (!-e $SourceTree) {
  222. exit errmsg("Source Tree: \"$SourceTree\" not found.");
  223. }
  224. # Any above error should stop (Fail)
  225. if ($ENV{errors} > 0) {return 0;}
  226. # Parse the hash-hash table snaplist
  227. foreach my $x_ (keys %snaplist) {
  228. $_ = $snaplist{$x_}->{Type};
  229. $Excludedirs .= ($x_=~/\\/)? "$SourceTree\\$x_ ": "$x_ " if /\bD\b/;
  230. $Excludefiles .= ($x_=~/\\/)? "$SourceTree\\$x_ ": "$x_ " if (/\bF\b/);
  231. }
  232. $Excludefiles =
  233. join " ", map {glob($_)} split(" ", $Excludefiles)
  234. if ($Excludefiles);
  235. $DEBUG and print STDERR "Exclude files:", $Excludefiles, "\n";
  236. # Check if incremental run.
  237. &ChkBabTree(\%snaplist) and exit;
  238. # Create RoboCopyLogName as %logfile%.RoboCopy
  239. $RoboCopyLog = `uniqfile $ENV{logfile}\.Robocopy`;
  240. if (defined $Incremental) {
  241. $Mirror = ""; # non-Mirror
  242. $OtherOptions = "/XO"; # Exclude Older files
  243. }
  244. # Prepare the robocopy statement
  245. $Cmd = "robocopy $Mirror /S /E $SourceTree $TargetTree $OtherOptions ";
  246. $Cmd .= "/XD $Excludedirs " if ($Excludedirs ne '');
  247. $Cmd .= "/XF $Excludefiles " if ($Excludefiles ne '');
  248. $RoboCopyCmd = $Cmd . " /LOG+:$RoboCopyLog";
  249. 1;
  250. }
  251. # Verify that the snaplist.txt file does not contradict with
  252. # the actual contents of the $TargetTree.
  253. # usage:
  254. # &ChkBabTree(\%snapList)
  255. sub ChkBabTree{
  256. my $snaplist = shift;
  257. my @report = ();
  258. my @children = grep {/\S/} split ("\n", qx ("dir /s/b/ad $TargetTree"));
  259. my ($childrenkeys, %hashchildren, $subdir, $lastdir, );
  260. $DEBUG and print STDERR "$TargetTree ",scalar (@children), " subdirs\n";
  261. return 0 unless @children;
  262. logmsg($TargetTree ." is not empty, possibly incremental run")
  263. if scalar(@children);
  264. map {$_ =~ s/\Q$TargetTree\E\\//} @children;
  265. my %hashchildren = map {$_=>$_} @children;
  266. $childrenkeys = \%hashchildren;
  267. map {$childrenkeys->{$_} =~ s/^.*\\//} @children;
  268. my @report = ();
  269. foreach $subdir (@children){
  270. my $lastdir = $childrenkeys->{$subdir};
  271. push @report, sprintf("%-30s%-30s",$lastdir,$subdir) # and delete ($snaplist->{$lastdir})
  272. if ($snaplist->{$lastdir}->{Type}=~/\bD\b$/) or () ;
  273. }
  274. foreach $lastdir (keys(%$snaplist)){
  275. next unless $snaplist->{$lastdir}->{Type}=~/\bD\b/ && $lastdir=~/\\/;
  276. my @subdir = grep {/\Q$lastdir\E/} @children;
  277. push @report, sprintf("%-30s%-30s",$lastdir,$subdir[0]) if scalar (@subdir);
  278. }
  279. unshift @report, "snaplist.txt %_NTTREE%\n".
  280. "-----------------------------------------------------"
  281. and print join ("\n", @report ), "\n\n"
  282. if scalar(@report);
  283. scalar(@report);
  284. 0;
  285. }
  286. # ExecuteRoboCopy
  287. # Purpose : Execute Robocopy Command ($RoboCopyCmd)
  288. #
  289. # Input : none
  290. # Output : none
  291. #
  292. # Note : The serious error or fatal error will be logged.
  293. sub ExecuteRoboCopy {
  294. my $status_;
  295. my $ROBOCOPY_ERROR = 8;
  296. my $ROBOCOPY_SERIOS_ERROR = 16;
  297. $RoboCopyCmd =~ s/\s+$//g;
  298. logmsg("ROBOCOPY: $RoboCopyCmd\n");
  299. logmsg("SOURCE: $SourceTree");
  300. logmsg("TARGET: $TargetTree");
  301. logmsg("LOGFILE: $RoboCopyLog");
  302. $DEBUG and return;
  303. $status_ = system($RoboCopyCmd) / 256;
  304. # Determine the return value
  305. if ($status_ > $ROBOCOPY_SERIOS_ERROR) {
  306. exit errmsg("Fatal robocopy error.");
  307. # Robocopy did not copy all files. This is either a usage error or an error due to
  308. # insufficient access privileges on the source or destination directions.";
  309. } elsif ($status_ > $ROBOCOPY_ERROR) {
  310. errmsg("Robocopy failed to copy some files or directories.");
  311. }
  312. }
  313. sub ReExRobocopy{
  314. my @stack = @_;
  315. my ($f_, @flist,$d_,$c_);
  316. {
  317. open (F, "$SnapList");
  318. my $startParse = 0;
  319. my @blist = ();
  320. my $flist = ();
  321. my @a = <F>;
  322. foreach (@a){
  323. next if /^;/;
  324. if (/^Additional *$/){
  325. $DEBUG and print "Additional directories:\n";
  326. $startParse = 1;
  327. }
  328. $startParse=0 if ($startParse && $_ !~ /\S/);
  329. if ($startParse && /\S/){
  330. my @alist =
  331. split(" ", $_);
  332. if ($#alist>=2){
  333. $f_ = undef;
  334. $alist[0] =~ s/(.*)\\([^\\]+)/$1/g and $f_=$2 if $alist[1]=~/F/;
  335. push @flist, $f_;
  336. push @blist, $alist[0];
  337. # &logmsg($alist[0]);
  338. }
  339. }
  340. }
  341. close(F);
  342. foreach $c_ (0..$#blist){
  343. $d_ = $blist[$c_];
  344. $f_ = $flist[$c_];
  345. $DEBUG and print STDERR "$d_\n";
  346. ($RoboCopyCmd, $RoboCopyLog, $SourceTree, $TargetTree) = @stack;
  347. $RoboCopyCmd =~ s/\\\\.*$//g;
  348. $RoboCopyLog =~ s|^.*(/LOG\+.*)$|$1.ADDED|g;
  349. chomp $RoboCopyLog;
  350. $SourceTree .= "\\$d_";
  351. $TargetTree .= "\\$d_";
  352. print "$SourceTree skipped\n" and next unless -d $SourceTree;
  353. $RoboCopyCmd = join(" ", $RoboCopyCmd, $SourceTree, $TargetTree, $RoboCopyLog, $f_);
  354. &ExecuteRoboCopy;
  355. }
  356. ($RoboCopyCmd, $RoboCopyLog, $SourceTree, $TargetTree) = @stack;
  357. }
  358. }
  359. # ParseLogFile
  360. # Purpose : Parse the log file which from argument and store to $ENV{logfile} with fully path
  361. #
  362. # Input : templogfile
  363. # Output : none
  364. #
  365. # Note : The log file will contain all file get copied and extra files removed.
  366. sub ParseLogFile {
  367. my ($templogfile) = @_;
  368. my ($type, $file, %slots, %fails, $path)=();
  369. local *F;
  370. # Read temp logfile
  371. open(F, $templogfile) || return;
  372. for(<F>) {
  373. next if (/^\s*\-*\s*$/);
  374. if (/^ROBOCOPY/) {(%slots,%fails)=(); next;}
  375. chomp;
  376. # If is error message, add to previous line
  377. if (!/^\s/) {
  378. if ($#{$fails{$type}} eq '-1') {
  379. errmsg($_);
  380. } else {
  381. ${$fails{$type}}[$#{$fails{$type}}] .= "\n$_";
  382. }
  383. next;
  384. }
  385. logmsg($_) if (defined $ROBOCOPYLOG);
  386. # Parse information according the format of robocopy log
  387. if (/^\s+(?:New Dir\s+)?(\d+)\s+([\w\:\\]+)$/) {
  388. $path = $2;
  389. next;
  390. }
  391. if (/^\s+((?:New File)|(?:Newer)|(?:\*EXTRA File)|(?:Older))\s+(\d+)\s+([\w\.]+)/) {
  392. ($type, $file) = ($1, $3);
  393. ((/100\%/)||(/\*EXTRA File/))?push(@{$slots{$type}}, $path . $file):push(@{$fails{$type}}, $path . $file);
  394. }
  395. }
  396. close(F);
  397. # Separate the log to success and fail
  398. logmsg("\n\[Copy Success\]");
  399. for $type (keys %slots) {
  400. logmsg(" \[$type\]");
  401. for $file (@{$slots{$type}}) {
  402. logmsg("\t$file");
  403. }
  404. }
  405. if (scalar(%fails) ne 0) {
  406. errmsg("\n\[Copy Fails\]");
  407. for $type (keys %fails) {
  408. errmsg(" \[$type\]");
  409. for $file (@{$fails{$type}}) {
  410. errmsg("\t$file");
  411. }
  412. }
  413. }
  414. # If Robocopy log include into the logfile, remove the robocopy its logfile
  415. if (defined $ROBOCOPYLOG) {
  416. unlink($templogfile);
  417. } else {
  418. logmsg("CHECK ROBOCOPY LOGFILE: $templogfile");
  419. }
  420. }
  421. # GenerateBldInfo
  422. # A styripped down version of
  423. # CreateBldInfo used when snapping from US release server
  424. #
  425. sub GenerateBldInfo{
  426. $_BuildTimeStamp = "??????-????" unless $_BuildTimeStamp !~ /[\d-]/
  427. &logmsg("BUILD ${BuildNum} ($_BuildArch) TIMESTAMP: $_BuildTimeStamp");
  428. open(F, ">$_BldMarkerFile");
  429. print F "$BuildNum,$_BuildTimeStamp";
  430. close(F);
  431. ###Copy __blddate__ and __bldnum__ from US release server
  432. map {qx("echo F|xcopy /V /F /R /Y $_ \%SDXROOT\%")}
  433. glob ("${SourceTree}\\congeal_scripts\\__bld*__");
  434. 1;
  435. }
  436. # CreateBldInfo
  437. # Purpose : Create build number and time stamps to $_BldMarkerFile
  438. #
  439. # Input : none
  440. # Output : none
  441. #
  442. # Note : The file $_BldMarkerFile contain one line: '<Build Number>,<Time Stamp>'
  443. #
  444. # 3552.x86fre.main.010914-1644.SRV
  445. sub CreateBldInfo {
  446. local *F;
  447. my @file;
  448. my $BuildLabel = "$BuildNum, ??????-????";
  449. if ($ENV{errors} > 0) {return 0;}
  450. # Search the matched filename in $SourceTree's parent folder
  451. @file = grep {/${BuildNum}\.\w+\.$_BuildBranch\.[0-9\-]+\.[A-Z]{3}/i}
  452. glob("${SourceTree}\\..\\${BuildNum}.*.???");
  453. if (defined $file[1]) {
  454. errmsg("Non unique US marker file found.".
  455. "\n Pick the first from the list:\n" .
  456. join("\n", @file)."\n\n");
  457. } elsif (!defined $file[0]) {
  458. errmsg("Marker file not found. Please make sure the US path is valid:\n".
  459. "${SourceTree}\\..\\${BuildNum}.*.???");
  460. }
  461. if ($file[0]!~/$BuildNum\.\w+\.\w+\.([\d|\-]+).[A-Z]{3}/i) {
  462. errmsg("Marker Filename (".$file[0].") is incorrect format! Expected:\n".
  463. "$BuildNum.$_BuildArch$_BuildType.$_BuildBranch.\$_BuildTimeStamp.???");
  464. } else {
  465. $_BuildTimeStamp = "$1";
  466. }
  467. &GenerateBldInfo();
  468. }
  469. sub ValidateParams {
  470. !exists $ENV{RazzleToolPath} and
  471. exit errmsg("Please run under razzle environment") ;
  472. $BuildNum =~ /[^\d\.]/ and
  473. exit errmsg("Build Number ($BuildNum) contains invalid characters");
  474. $_BuildBranch = $ENV{"_BuildBranch"} unless $_BuildBranch;
  475. $lang = "usa" unless $lang;
  476. $DFSAlternateBranchName = &GetIniSetting::GetSettingEx( $_BuildBranch, $lang, "DFSAlternateBranchName");
  477. $SourceTree = "\\\\ntdev\\release\\<_BuildBranch>\\usa\\<BuildNum>\\<_BuildArch><_BuildType>\\bin" unless $SourceTree;
  478. $SourceTree = "\\\\ntdev\\release\\<DFSAlternateBranchName>\\usa\\<BuildNum>\\<_BuildArch><_BuildType>\\bin" if defined $DFSAlternateBranchName;
  479. &dbgmsg("\$SourceTree=$SourceTree");
  480. $TargetTree = $ENV{"_NTTREE"} unless $TargetTree;
  481. $SnapList = $ENV{"RazzleToolPath"}."\\PostBuildScripts\\SnapList.txt" unless $SnapList;
  482. $_BldMarkerFile = $ENV{"_NTROOT"}."\\__BldInfo__usa__" unless $_BldMarkerFile;
  483. $_BuildArch = $ENV{"_BuildArch"} unless $_BuildArch;
  484. $RoboCopyLog = ".Robocopy" unless $RoboCopyLog;
  485. 1;
  486. }
  487. sub Usage {
  488. my $self = $0;
  489. $self =~ s/^.+\\([^\\]+)$/$1/g;
  490. print <<USAGE;
  491. $self - Snap Tree from US to INTL
  492. ============================================================================
  493. Usage: $self -n buildnum [-s SourceTree] [-t TargetTree] [-f SnapList]
  494. [-y BuildBranch] [-B bldinfo] [-L] [-i] [-d]
  495. -n Build Number : The Build Number you snapshot
  496. -s Source Tree : Source Tree
  497. -t Target Tree : Target Tree
  498. -f SnapList : A snaplist file contain which files or dirs excluded
  499. -y BuildBrahcn : Branch to snap the build from. Default %_BuildBranch%
  500. -B bldinfo : A bldinfo file should be create after snapshot
  501. -L : Include robocopy log into logfile
  502. -i : Incremental
  503. -d : Debug. Display the robocopy command without running it. Useful
  504. when you encountered the error and willing debug it.
  505. -N : use NET access to release server(s) to determine the snap location.
  506. Default behavior is rely on DFS.
  507. -B : specify the release server to form the snap location. Only used when -N
  508. flag set
  509. -? Displays usage
  510. Example:
  511. 1. Snapshot US 2121
  512. $0 -n 2121
  513. 2. Snapshot US 2222 with userlst.txt incrementally
  514. $0 -n 2222 -f userlst.txt -i
  515. 3. Snapshot US 2233 from d:\\nt8.binaries.x86fre to f:\\nt9.binaries.x86fre
  516. with userlst.txt and store buildnumber and time stamp to mynote.txt.
  517. $0 -n 2233 -s d:\\nt8.binaries.x86fre -t f:\\nt9.binaries.x86fre -f userlst.txt -B mynote.txt
  518. 4. Dummy snap the idx02 build in the Razzle enlisted in main branch.
  519. $0 -n 3505 -b idx02 -d
  520. USAGE
  521. exit 0;
  522. }
  523. &parseargs('?' => \&Usage,
  524. 'n:' => \$BuildNum,
  525. 's:' => \$SourceTree,
  526. 't:' => \$TargetTree,
  527. 'y:' => \$_BuildBranch,
  528. 'f:' => \$SnapList,
  529. 'L' => \$ROBOCOPYLOG,
  530. 'i' => \$Incremental,
  531. 'd' => \$DEBUG,
  532. 'N' => \$NETVIEW,
  533. 'B:' => \$BinarySnapServer
  534. );
  535. # Validate the option given as parameter.
  536. &ValidateParams;
  537. # Step 4: Call the CmdMain function
  538. &CmdMain();
  539. # -------------------------------------------------------------------------------------------
  540. # Script: snapbin.pl
  541. # Purpose: Snapshot US binaries tree to INTL.
  542. # SD Location: %sdxroot%\tools\postbuildscripts
  543. #
  544. # (1) Code section description:
  545. # CmdMain - Prepare the robocopyCmd, execute and parse its log
  546. # PrepareRoboCopyCmd - Prepare the Robocopy command
  547. # ExecuteRoboCopy - Execute the Robocopy command and test the return value
  548. # ParseLogFile - Parse the logfile, append logfile from temp logfile
  549. #
  550. # (2) Reserved Variables -
  551. # $ENV{HELP} - Flag that specifies usage.
  552. # $ENV{lang} - The specified language. Defaults to USA.
  553. # $ENV{logfile} - The path and filename of the logs file.
  554. # $ENV{logfile_bak} - The path and filename of the logfile.
  555. # $ENV{errfile} - The path and filename of the error file.
  556. # $ENV{tmpfile} - The path and filename of the temp file.
  557. # $ENV{errors} - The scripts errorlevel.
  558. # $ENV{script_name} - The script name.
  559. # $ENV{_NTPostBld} - Abstracts the language from the files path that
  560. # postbuild operates on.
  561. #
  562. # (3) Reserved Subs -
  563. # Usage - Use this sub to discribe the scripts usage.
  564. # ValidateParams - Use this sub to verify the parameters passed to the script.
  565. #
  566. # (4) Call other executables or command scripts by using:
  567. # system "foo.exe";
  568. # Note that the executable/script you're calling with system must return a
  569. # non-zero value on errors to make the error checking mechanism work.
  570. #
  571. # Example
  572. # if (system("perl.exe foo.pl -l $lang")){
  573. # errmsg("perl.exe foo.pl -l $lang failed.");
  574. # # If you need to terminate function's execution on this error
  575. # goto End;
  576. # }
  577. #
  578. # (5) Log non-error information by using:
  579. # logmsg "<log message>";
  580. # and log error information by using:
  581. # errmsg "<error message>";
  582. #
  583. # (6) Have your changes reviewed by a member of the US build team (ntbusa) and
  584. # by a member of the international build team (ntbintl).
  585. #
  586. # -------------------------------------------------------------------------------------------
  587. =head1 NAME
  588. B<SnapBin> - Snapshot US Binaries tree to INTL
  589. =head1 SYNOPSIS
  590. &SnapBin::PrepareRoboCopyCmd;
  591. &SnapBin::ExecuteRoboCopy;
  592. &SnapBin::ParseLogFile;
  593. &SnapBin::CreateBldInfo;
  594. =head1 DESCRIPTION
  595. According SnapList,
  596. PrepareRoboCopyCmd will prepare the command, such as:
  597. Robocopy /MIR /S /E $SourceTree $TargetTree /XD xxxx /XF xxxx /LOG+:$ENV{logfile}.temp
  598. ExecuteRoboCopy execute the command and verify its log.
  599. And, ParseLogFile will append temp logfile to $ENV{logfile} and generate a separate list into log.
  600. Final, create BldInfo file in nt root.
  601. =head1 INSTANCES
  602. =head2 $SourceTree
  603. US Tree, default is \\\\ntdev\\release\\<_BuildBranch>\\usa\\<BuildNum>\\<_BuildArch><_BuildType>\\bin
  604. =head2 $TargetTree
  605. INTL Tree, default is _NTTREE
  606. =head2 $SnapList
  607. Snap List FileName, default is SnapList.txt
  608. =head2 $BuildNum
  609. Build Number, necessary defined. No default value
  610. =head2 %SnapList
  611. The hash stored by HashText::Read_Text_Hash from file $SnapList.
  612. =head2 $RoboCopyCmd
  613. The command for ExecuteRoboCopy execute
  614. =head1 METHODS
  615. =head2 PrepareRoboCopyCmd
  616. $SnapBin::SourceTree = "f:\\foo";
  617. $SnapBin::TargetTree = "f:\\bar";
  618. $SnapBin::SnapList = "mylist.txt"; # equal to '-' if no exclude list file
  619. &SnapBin::PrepareRoboCopyCmd;
  620. system("$SnapBin::RoboCopyCmd");
  621. =head2 ExecuteRoboCopy
  622. $SnapBin::SourceTree = "f:\\foo";
  623. $SnapBin::TargetTree = "f:\\bar";
  624. $SnapBin::RoboCopyCmd = "Robocopy /S $SnapBin::SourceTree $SnapBin::TargetTree";
  625. &SnapBin::ExecuteRoboCopy;
  626. =head2 ParseLogFile
  627. system("robocopy f:\\temp F:\\tempbak /LOG:abc.log");
  628. &SnapBin::ParseLogFile("abc.log");
  629. =head1 SEE ALSO
  630. HashText.pm
  631. =head1 AUTHOR
  632. Benson Tan <[email protected]>
  633. Serguei Kouzmine <[email protected]>
  634. =cut
  635. 1;