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.

321 lines
7.6 KiB

  1. @echo off
  2. REM ------------------------------------------------------------------
  3. REM
  4. REM <<template_script.cmd>>
  5. REM <<purpose of this script>>
  6. REM
  7. REM Copyright (c) Microsoft Corporation. All rights reserved.
  8. REM
  9. REM ------------------------------------------------------------------
  10. perl -x "%~f0" %*
  11. goto :EOF
  12. #!perl
  13. use strict;
  14. use lib $ENV{RAZZLETOOLPATH} . "\\PostBuildScripts";
  15. use lib $ENV{RAZZLETOOLPATH};
  16. use PbuildEnv;
  17. use ParseArgs;
  18. use Logmsg;
  19. my $const_SD_project_title =
  20. "project\\s+group\\s+server:port\\s+depotname\\s+projectroot";
  21. my ($ProcessSuccess) = ("TRUE");
  22. my ($SrcFile, $SrcDir, $Group, $Project, $ServerPort, $DepotName, $ProjectRoot, $Validate) = ();
  23. my ($ProjectValue, $GroupValue, $ServerPortValue, $DeportValue) = ();
  24. my ($SrcName, $SdxRoot, $RazPath, $SrcTimeStampFile, $ProjectsNT) = ();
  25. my (%Projects)=();
  26. sub Usage { print<<USAGE; exit(1) }
  27. $0 - Capture Source File List from Source Depot
  28. =============================================================
  29. Syntax:
  30. $0 [-f <SourceFileList>] [-d <SoureFileDir>]
  31. [-g <Group>] [-p <Project>] [-s <ServerPort>]
  32. [-n <DepotName>] [-r <ProjectRoot>] [-v]
  33. Parameter:
  34. SourceFileList : The filename for stored sdx have result
  35. SourceFileDir : The root for stored .offset file
  36. Group : Source depot group
  37. Project : Source depot project
  38. ServerPort : Source depot server port
  39. DepotName : Source depot name
  40. ProjectRoot : Source depot project root
  41. Validate : Validate SourceFileList
  42. Default:
  43. SourceFileList : \%_NTPOSTBLD\%\\build_logs\\SourceFileLists.txt
  44. SourceFileDir : \%_NTPOSTBLD\%\\build_logs\\SourceFileLists
  45. Projects.net : \%RazzleToolPath\%\\projects.nt
  46. Example:
  47. 1. Create NTDEV build's SourceFileList
  48. $0 -g ntdev
  49. USAGE
  50. parseargs(
  51. 'f:' => \$SrcFile,
  52. 'd:' => \$SrcDir,
  53. 'g:' => \$Group,
  54. 'p:' => \$Project,
  55. 's:' => \$ServerPort,
  56. 'n:' => \$DepotName,
  57. 'r:' => \$ProjectRoot,
  58. 'v' => \$Validate,
  59. '?' => \&Usage
  60. );
  61. #
  62. # Add if-clause so pbuild.dat entry can be BEGIN instead of OFFICIAL and we
  63. # still don't waste much time unless a non-official machine has set PDB_SRC_STREAM
  64. # which also controls PdbSrcStream.cmd.
  65. #
  66. if ( defined($ENV{OFFICIAL_BUILD_MACHINE}) || defined($ENV{PDB_SRC_STREAM})) {
  67. &Main;
  68. }
  69. sub Main {
  70. &InitGlobalVariables;
  71. &CreateSDXResult;
  72. &ParseProjectsNT("$RazPath\\projects.nt", \%Projects);
  73. &IndexSrc;
  74. &StoreFileTimeDateStamp;
  75. if ((defined $Validate) && (&ValidateOffsetFile($SrcFile, $SrcDir) eq "FAIL")) {
  76. errmsg("$SrcFile created failed");
  77. }
  78. }
  79. sub InitGlobalVariables {
  80. $SdxRoot = $ENV{ "SDXROOT" };
  81. $RazPath = $ENV{ "RazzleToolPath" };
  82. $SrcName = "SourceFileLists";
  83. $SrcDir = $ENV{ "_NTPostBld" } . "\\build_logs\\$SrcName" if (!defined $SrcDir);
  84. $SrcFile = $ENV{ "_NTPostBld" } . "\\build_logs\\$SrcName" . ".txt" if (!defined $SrcFile);
  85. $SrcTimeStampFile = $SrcDir . "\\" . &FileName($SrcFile) . ".timestamp";
  86. $ProjectsNT = "$RazPath\\projects.nt";
  87. }
  88. sub CreateSDXResult {
  89. chdir "$SdxRoot";
  90. # Create sdx have list
  91. &SuccessExecute("$RazPath\\sdx.cmd have ...>$SrcFile");
  92. }
  93. sub IndexSrc {
  94. my ($curbytes, $curlen, $SECTION) = (0, 0);
  95. my (%ProjectSlots);
  96. my ( $project );
  97. # Index the result
  98. open(SRC, "$SrcFile");
  99. binmode(SRC);
  100. for($curbytes=0; <SRC> ; $curbytes+=$curlen) {
  101. $curlen=length($_);
  102. next if (!/\S/);
  103. if (/\-{16}\s(\S+)/) {
  104. my $section = $1;
  105. &StoreProjectIndex($SECTION, \%ProjectSlots);
  106. %ProjectSlots=();
  107. $SECTION = $section;
  108. &StoreInfo($SECTION);
  109. next;
  110. }
  111. if (/^(\S+)\s\-\s(\S+)\\([^\\])([^\\]*)\s*$/) {
  112. push @{$ProjectSlots{$3}}, "$2\\$3$4,$1,$curbytes";
  113. }
  114. }
  115. &StoreProjectIndex;
  116. close(SRC);
  117. }
  118. sub ParseProjectsNT {
  119. my ($ProjectsNTFileName, $HashPtr) = @_;
  120. my $NecessaryPattern = &ComposeNecessaryPattern($Project, $Group, "\\S*" . $ServerPort . "\\S*", $DepotName);
  121. my $fh_in;
  122. my $START = 0;
  123. unless ( $fh_in = new IO::File $ProjectsNTFileName, "r" ) {
  124. errmsg( "Failed to open $ProjectsNTFileName for read" );
  125. return;
  126. }
  127. while(<$fh_in>) {
  128. next if (!/\S/);
  129. $START = 1 if (/$const_SD_project_title/i);
  130. next if (/^\s*\#/);
  131. if (($START eq 1) && (/$NecessaryPattern/i)) {
  132. next if ((defined $ProjectRoot) && ($' !~ /$ProjectRoot/i));
  133. ($ProjectValue, $GroupValue, $ServerPortValue, $DeportValue) = ($1, $2, $3, $4);
  134. # print "$ProjectValue, $GroupValue, $ServerPortValue, $DeportValue\n";
  135. $HashPtr->{uc$ProjectValue} = [$GroupValue, $ServerPortValue, $DeportValue, $ProjectRoot];
  136. }
  137. }
  138. undef $fh_in;
  139. }
  140. sub StoreInfo {
  141. my ($project) = shift;
  142. my $fh_info;
  143. my $filename;
  144. &SuccessExecute("md $SrcDir\\$project") if (!-d "$SrcDir\\$project");
  145. $filename = "$SrcDir\\$project\\$project\.txt";
  146. unless ( $fh_info = new IO::File $filename, "w" ) {
  147. errmsg( "Failed to open file $filename for write" );
  148. return;
  149. }
  150. print $fh_info "$Projects{$project}[0] $Projects{$project}[1]\n";
  151. undef $fh_info;
  152. }
  153. sub StoreProjectIndex {
  154. my ($project, $PSptr) = @_;
  155. my $FirstChar;
  156. for $FirstChar (sort keys %$PSptr) {
  157. my $fh_out;
  158. my $filename;
  159. $filename = "$SrcDir\\$project\\Files_" . $FirstChar . ".offset";
  160. unless ( $fh_out = new IO::File $filename, "w" ) {
  161. errmsg( "Failed to open file $filename for write" );
  162. return;
  163. }
  164. binmode($fh_out);
  165. map({&OutputAddress($fh_out, (split(/\,/, $_))[2])} sort @{$PSptr->{$FirstChar}});
  166. undef $fh_out;
  167. }
  168. }
  169. sub StoreFileTimeDateStamp {
  170. my $result = &ReadFileTimeStamp($SrcFile);
  171. my $srctime;
  172. unless ( $srctime = new IO::File $SrcTimeStampFile, "w" ) {
  173. errmsg( "Failed to open file $SrcTimeStampFile for write" );
  174. return;
  175. }
  176. print $srctime "$result\n";
  177. undef $srctime;
  178. }
  179. sub ReadFileTimeStamp {
  180. my ($HH, $MM, $DD, $hh, $mm) = (localtime((lstat($_))[9]))[5,4,3,2,1];
  181. return sprintf("%04d/%02d/%02d:%02d:%02d", $HH + 1900, $MM + 1, $DD, $hh, $mm);
  182. }
  183. sub ValidateOffsetFile {
  184. my ($SRC_filename, $SRC_Root) = @_;
  185. my ($filespec, $vsrctime, $vsrc, $vsrc_ref);
  186. my ($address, $offset, $result, $lastresult);
  187. unless ( $vsrctime = new IO::File $SrcTimeStampFile, "r" ) {
  188. errmsg( "Failed to open file $SrcTimeStampFile for read" );
  189. return;
  190. }
  191. $lastresult = <$vsrctime>;
  192. undef $vsrctime;
  193. chomp $lastresult;
  194. $result = &ReadFileTimeStamp($SRC_filename);
  195. return "FAIL" if ($result ne $lastresult);
  196. unless ( $vsrc = new IO::File $SRC_filename, "r" ) {
  197. errmsg( "Failed to open file $SRC_filename for read" );
  198. return;
  199. }
  200. binmode($vsrc);
  201. for $filespec (`dir /s /b $SRC_Root\\*.offset`) {
  202. chomp $filespec;
  203. unless ( $vsrc_ref = new IO::File $filespec, "r" ) {
  204. errmsg( "Failed to open file $filespec for read" );
  205. return;
  206. }
  207. binmode($vsrc_ref);
  208. while(read($vsrc_ref, $offset, 4)) {
  209. ($address) = unpack("L",$offset);
  210. seek($vsrc, $address, 0);
  211. read($vsrc, $result, 7);
  212. if ($result ne "//depot") {
  213. close($vsrc_ref);
  214. close($vsrc);
  215. print "Error - $filespec($address) $result\n";
  216. return "FAIL";
  217. }
  218. }
  219. close($vsrc_ref);
  220. }
  221. undef $vsrc;
  222. return "SUCCESS";
  223. }
  224. sub SuccessExecute {
  225. my $cmd = shift;
  226. if ($ProcessSuccess eq "TRUE") {
  227. my $r = system($cmd);
  228. $r >>= 8;
  229. if ($r > 0) {
  230. errmsg($cmd);
  231. $ProcessSuccess="FALSE";
  232. }
  233. }
  234. }
  235. sub OutputAddress {
  236. my ($fh, $address) = @_;
  237. my ($len);
  238. for ($len=0;$len<4;$len++) {
  239. print $fh chr($address & 0xFF);
  240. $address>>=8;
  241. }
  242. }
  243. sub FileName {
  244. my ($filespec) = shift;
  245. chomp $filespec;
  246. $filespec=~/\\([^\\]+)$/;
  247. return $1;
  248. }
  249. sub ComposeNecessaryPattern {
  250. return join("\\s+", map({(defined $_)?"($_)":"(\\S+)"} @_));
  251. }