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.

247 lines
6.2 KiB

  1. # FileName: ChangesToFiles.pl
  2. #
  3. #
  4. # Usage = ChangesToFiles.pl [project] changesfile > filesfile
  5. #
  6. # Function: Takes build.changes and runs sd describe on each change to get the file list.
  7. # Specifiying a project limits the output to just that project
  8. #
  9. # WARNING:
  10. # WARNING: make sure pathname comparisons are case insensitive. Either convert the case or do the
  11. # WARNING: comparisons like this:
  12. # WARNING: if ($foo =~ /^\Q$bar\E$/i) {}
  13. # WARNING: or if ($foo !~ /^\Q$bar\E$/i) {}
  14. # WARNING:
  15. $PGM='ChangesToFiles: ';
  16. $Usage = "ChangesToFiles.pl [options] changesfile\n"
  17. . "options:\n"
  18. . " [-verbose]\n"
  19. . " [-descriptions]\n"
  20. . " [-integrates]\n"
  21. . " [-branches]\n"
  22. . " [-deletes]\n"
  23. . " [-publics]\n"
  24. . " [-all]\n"
  25. . " [-project depotname]\n"
  26. ;
  27. $DefaultChangesFile = "build.Changes";
  28. #
  29. # Debug routines for printing out variables
  30. #
  31. sub gvar {
  32. for (@_) {
  33. print "\$$_ = $$_\n";
  34. }
  35. }
  36. #
  37. # get current directory
  38. #
  39. sub thisdir () {
  40. open CWD, 'cd 2>&1|';
  41. my $here = <CWD>;
  42. close CWD;
  43. return $here;
  44. }
  45. #
  46. # grap sdxroot from the environment
  47. #
  48. $sdxroot = $ENV{'SDXROOT'} or die $PGM, "SDXROOT not set in environment\n";
  49. $sdxpath = $sdxroot;
  50. $sdxpath =~ s/^[A-Z]://i;
  51. #
  52. # Process arguments
  53. #
  54. while ($_ = shift) {
  55. $nextarg = $ARGV[0];
  56. $nextarg =~ tr/A-Z/a-z/;
  57. if (/^-verbose$/i) { $Verbose++; next; }
  58. if (/^-v/i) { $Verbose++; next; }
  59. if (/^-all$/i) { $DoAll++; next; }
  60. if (/^-a$/i) { $DoAll++; next; }
  61. if (/^-debug$/i) { $Debug++; next; }
  62. if (/^-d$/i) { $Debug++; next; }
  63. if (/^-descriptions$/i) { $DoDescriptions++; next; }
  64. if (/^-integrates$/i) { $DoIntegrates++; next; }
  65. if (/^-branches$/i) { $DoBranches++; next; }
  66. if (/^-deletes$/i) { $DoDeletes++; next; }
  67. if (/^-publics$/i) { $DoPublics++; next; }
  68. if (/^-nofiles$/i) { $NoFiles++; next; }
  69. if (/^-project$/i) { $OnlyProjects++; $ProjectList{$nextarg}++; shift; next; }
  70. if (/^-p$/i) { $OnlyProjects++; $ProjectList{$nextarg}++; shift; next; }
  71. if (/^-?$/i) { die $Usage; }
  72. if (/^-help$/i) { die $Usage; }
  73. if (/^-/) { die $Usage; }
  74. if (not $ChangesFile) {
  75. $ChangesFile = $_;
  76. next;
  77. }
  78. die $Usage;
  79. }
  80. if ($DoAll) {
  81. $DoIntegrates++;
  82. $DoBranches++;
  83. $DoDeletes++;
  84. $DoPublics++;
  85. $DoDescriptions++;
  86. }
  87. $ChangesFile = "$sdxroot\\$DefaultChangesFile" unless $ChangesFile;
  88. # gvar Verbose, DoAll, Debug, DoDescriptions, DoIntegrates, DoBranches, DoDeletes, DoPublics, OnlyProjects, ChangesFile;
  89. #
  90. # setup SD.MAP mapping from projects to directories
  91. #
  92. $sdxmapfile = "$sdxroot\\sd.map";
  93. open SDMAPFILE, $sdxmapfile or die $PGM, "Could not open $sdxmapfile <$!>\n";
  94. while (<SDMAPFILE>) {
  95. last if /^#\s*project\s*root\s*$/i;
  96. }
  97. die $PGM, "Malformed sd.map file\n" if <SDMAPFILE> !~ /^#\s*-+\s+-+\s*$/;
  98. while (<SDMAPFILE>) {
  99. last if /^\s*$/;
  100. next unless /^\s*(\S+)\s*=\s*(\S+)\s*$/;
  101. $p = $1;
  102. $r = $2;
  103. $p =~ tr/A-Z/a-z/;
  104. $r =~ tr/A-Z/a-z/;
  105. $SDProjectDir{$p} = "$sdxpath\\$r";
  106. }
  107. close SDMAPFILE;
  108. #
  109. # Check the -projects arguments against SDMAP
  110. #
  111. if ($Project) {
  112. for (keys %ProjectList) {
  113. die $PGM, $_, " not found in sd.map\n";
  114. }
  115. }
  116. #
  117. # Open and process the changes file
  118. #
  119. open BUILDCHANGES, $ChangesFile or die $PGM, "Could not open: ", $ChangesFile, "\n";
  120. $CurrentProject = "";
  121. for (<BUILDCHANGES>) {
  122. $CurrentProject = $1 if /^---+\s*(\w+)\s*$/;
  123. $CurrentProject =~ tr/A-Z/a-z/;
  124. next unless /^Change\s(\d+)\s+on\s+(\S+)\s+(\S+)\s+by\s+(\S+)\\(\S+)\@(\S+)\s*'/i;
  125. $Change = $1;
  126. $Timestamp = "$2 $3";
  127. $Domain = "$4";
  128. $Alias = "$5";
  129. $Machine = "$6";
  130. next if $Project and not $ProjectList{$CurrentProject};
  131. $ProjectChanges{$CurrentProject} .= "$Change ";
  132. }
  133. $origdir = thisdir();
  134. for (keys %ProjectChanges) {
  135. $Depot = $_;
  136. #
  137. # Change to the project and run sd describe
  138. #
  139. chdir $SDProjectDir{$_} or die $PGM, "Could not chdir to $SDProjectDir{$_}: $!\n";
  140. open SDOUT, "sd describe -s $ProjectChanges{$_} |" or die "Could not run sd describe: $!\n";
  141. chdir $origdir;
  142. TOP: while (<SDOUT>) {
  143. next if /^\s*$/; # skip initial blank lines
  144. if (not /^Change\s+(\d+)\s+by\s+(\S+)\\(\S+)\@(\S+)\s+on\s+(\S+)\s+(\S+)\s*$/i) {
  145. warn $PGM, "Could not parse sd output: $_";
  146. last;
  147. }
  148. $Change = $1;
  149. $Domain = "$2";
  150. $Alias = "$3";
  151. $Machine = "$4";
  152. $Timestamp = "$5 $6";
  153. #
  154. # Collect the description lines
  155. #
  156. $Description = "";
  157. while (<SDOUT>) {
  158. last if /^Affected files/i;
  159. $Description .= $_;
  160. }
  161. #
  162. # Output Change summary if doing descriptions
  163. #
  164. printf "Description of %-10s %6d by %s:%s", $Depot, $Change, $Alias, $Description if $DoDescriptions;
  165. #
  166. # Collect the files
  167. #
  168. while (<SDOUT>) {
  169. redo TOP if /^Change\s/i;
  170. next if /^\s*$/;
  171. warn $PGM, "Can't parse: $_" unless /^\.\.\.\s/;
  172. ($dots, $Filename, $FileStatus) = split ' ';
  173. #
  174. # Finally, the output happens...
  175. #
  176. $dontprint = (not $DoIntegrates and $FileStatus =~ /integrat/i
  177. or not $DoBranches and $FileStatus =~ /branch/i
  178. or not $DoDeletes and $FileStatus =~ /delete/i
  179. or not $DoPublics and $Filename =~ m+root/public/+i
  180. or $NoFiles );
  181. printf "%-10s %6d %-8s %19s %s %s\n", $Depot, $Change, $Alias, $Timestamp, $Filename, $FileStatus unless $dontprint;
  182. }
  183. }
  184. close SDOUT;
  185. }
  186. exit 0;