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.

313 lines
7.0 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. &Main;
  62. sub Main {
  63. &InitGlobalVariables;
  64. &CreateSDXResult;
  65. &ParseProjectsNT("$RazPath\\projects.nt", \%Projects);
  66. &IndexSrc;
  67. &StoreFileTimeDateStamp;
  68. if ((defined $Validate) && (&ValidateOffsetFile($SrcFile, $SrcDir) eq "FAIL")) {
  69. errmsg("$SrcFile created failed");
  70. }
  71. }
  72. sub InitGlobalVariables {
  73. $SdxRoot = $ENV{ "SDXROOT" };
  74. $RazPath = $ENV{ "RazzleToolPath" };
  75. $SrcName = "SourceFileLists";
  76. $SrcDir = $ENV{ "_NTPostBld" } . "\\build_logs\\$SrcName" if (!defined $SrcDir);
  77. $SrcFile = $ENV{ "_NTPostBld" } . "\\build_logs\\$SrcName" . ".txt" if (!defined $SrcFile);
  78. $SrcTimeStampFile = $SrcDir . "\\" . &FileName($SrcFile) . ".timestamp";
  79. $ProjectsNT = "$RazPath\\projects.nt";
  80. }
  81. sub CreateSDXResult {
  82. chdir "$SdxRoot";
  83. # Create sdx have list
  84. &SuccessExecute("$RazPath\\sdx.cmd have ...>$SrcFile");
  85. }
  86. sub IndexSrc {
  87. my ($curbytes, $curlen, $SECTION) = (0, 0);
  88. my (%ProjectSlots);
  89. my ( $project );
  90. # Index the result
  91. open(SRC, "$SrcFile");
  92. binmode(SRC);
  93. for($curbytes=0; <SRC> ; $curbytes+=$curlen) {
  94. $curlen=length($_);
  95. next if (!/\S/);
  96. if (/\-{16}\s(\S+)/) {
  97. my $section = $1;
  98. &StoreProjectIndex($SECTION, \%ProjectSlots);
  99. %ProjectSlots=();
  100. $SECTION = $section;
  101. &StoreInfo($SECTION);
  102. next;
  103. }
  104. if (/^(\S+)\s\-\s(\S+)\\([^\\])([^\\]*)\s*$/) {
  105. push @{$ProjectSlots{$3}}, "$2\\$3$4,$1,$curbytes";
  106. }
  107. }
  108. &StoreProjectIndex;
  109. close(SRC);
  110. }
  111. sub ParseProjectsNT {
  112. my ($ProjectsNTFileName, $HashPtr) = @_;
  113. my $NecessaryPattern = &ComposeNecessaryPattern($Project, $Group, "\\S*" . $ServerPort . "\\S*", $DepotName);
  114. my $fh_in;
  115. my $START = 0;
  116. unless ( $fh_in = new IO::File $ProjectsNTFileName, "r" ) {
  117. errmsg( "Failed to open $ProjectsNTFileName for read" );
  118. return;
  119. }
  120. while(<$fh_in>) {
  121. next if (!/\S/);
  122. $START = 1 if (/$const_SD_project_title/i);
  123. next if (/^\s*\#/);
  124. if (($START eq 1) && (/$NecessaryPattern/i)) {
  125. next if ((defined $ProjectRoot) && ($' !~ /$ProjectRoot/i));
  126. ($ProjectValue, $GroupValue, $ServerPortValue, $DeportValue) = ($1, $2, $3, $4);
  127. # print "$ProjectValue, $GroupValue, $ServerPortValue, $DeportValue\n";
  128. $HashPtr->{uc$ProjectValue} = [$GroupValue, $ServerPortValue, $DeportValue, $ProjectRoot];
  129. }
  130. }
  131. undef $fh_in;
  132. }
  133. sub StoreInfo {
  134. my ($project) = shift;
  135. my $fh_info;
  136. my $filename;
  137. &SuccessExecute("md $SrcDir\\$project") if (!-d "$SrcDir\\$project");
  138. $filename = "$SrcDir\\$project\\$project\.txt";
  139. unless ( $fh_info = new IO::File $filename, "w" ) {
  140. errmsg( "Failed to open file $filename for write" );
  141. return;
  142. }
  143. print $fh_info "$Projects{$project}[0] $Projects{$project}[1]\n";
  144. undef $fh_info;
  145. }
  146. sub StoreProjectIndex {
  147. my ($project, $PSptr) = @_;
  148. my $FirstChar;
  149. for $FirstChar (sort keys %$PSptr) {
  150. my $fh_out;
  151. my $filename;
  152. $filename = "$SrcDir\\$project\\Files_" . $FirstChar . ".offset";
  153. unless ( $fh_out = new IO::File $filename, "w" ) {
  154. errmsg( "Failed to open file $filename for write" );
  155. return;
  156. }
  157. binmode($fh_out);
  158. map({&OutputAddress($fh_out, (split(/\,/, $_))[2])} sort @{$PSptr->{$FirstChar}});
  159. undef $fh_out;
  160. }
  161. }
  162. sub StoreFileTimeDateStamp {
  163. my $result = &ReadFileTimeStamp($SrcFile);
  164. my $srctime;
  165. unless ( $srctime = new IO::File $SrcTimeStampFile, "w" ) {
  166. errmsg( "Failed to open file $SrcTimeStampFile for write" );
  167. return;
  168. }
  169. print $srctime "$result\n";
  170. undef $srctime;
  171. }
  172. sub ReadFileTimeStamp {
  173. my ($HH, $MM, $DD, $hh, $mm) = (localtime((lstat($_))[9]))[5,4,3,2,1];
  174. return sprintf("%04d/%02d/%02d:%02d:%02d", $HH + 1900, $MM + 1, $DD, $hh, $mm);
  175. }
  176. sub ValidateOffsetFile {
  177. my ($SRC_filename, $SRC_Root) = @_;
  178. my ($filespec, $vsrctime, $vsrc, $vsrc_ref);
  179. my ($address, $offset, $result, $lastresult);
  180. unless ( $vsrctime = new IO::File $SrcTimeStampFile, "r" ) {
  181. errmsg( "Failed to open file $SrcTimeStampFile for read" );
  182. return;
  183. }
  184. $lastresult = <$vsrctime>;
  185. undef $vsrctime;
  186. chomp $lastresult;
  187. $result = &ReadFileTimeStamp($SRC_filename);
  188. return "FAIL" if ($result ne $lastresult);
  189. unless ( $vsrc = new IO::File $SRC_filename, "r" ) {
  190. errmsg( "Failed to open file $SRC_filename for read" );
  191. return;
  192. }
  193. binmode($vsrc);
  194. for $filespec (`dir /s /b $SRC_Root\\*.offset`) {
  195. chomp $filespec;
  196. unless ( $vsrc_ref = new IO::File $filespec, "r" ) {
  197. errmsg( "Failed to open file $filespec for read" );
  198. return;
  199. }
  200. binmode($vsrc_ref);
  201. while(read($vsrc_ref, $offset, 4)) {
  202. ($address) = unpack("L",$offset);
  203. seek($vsrc, $address, 0);
  204. read($vsrc, $result, 7);
  205. if ($result ne "//depot") {
  206. close($vsrc_ref);
  207. close($vsrc);
  208. print "Error - $filespec($address) $result\n";
  209. return "FAIL";
  210. }
  211. }
  212. close($vsrc_ref);
  213. }
  214. undef $vsrc;
  215. return "SUCCESS";
  216. }
  217. sub SuccessExecute {
  218. my $cmd = shift;
  219. if ($ProcessSuccess eq "TRUE") {
  220. my $r = system($cmd);
  221. $r >>= 8;
  222. if ($r > 0) {
  223. errmsg($cmd);
  224. $ProcessSuccess="FALSE";
  225. }
  226. }
  227. }
  228. sub OutputAddress {
  229. my ($fh, $address) = @_;
  230. my ($len);
  231. for ($len=0;$len<4;$len++) {
  232. print $fh chr($address & 0xFF);
  233. $address>>=8;
  234. }
  235. }
  236. sub FileName {
  237. my ($filespec) = shift;
  238. chomp $filespec;
  239. $filespec=~/\\([^\\]+)$/;
  240. return $1;
  241. }
  242. sub ComposeNecessaryPattern {
  243. return join("\\s+", map({(defined $_)?"($_)":"(\\S+)"} @_));
  244. }