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.

218 lines
5.9 KiB

  1. @REM -----------------------------------------------------------------
  2. @REM
  3. @REM layout.cmd - WadeLa
  4. @REM Updates layout.inf for each sku with the sizes of the binaries
  5. @REM
  6. @REM Copyright (c) Microsoft Corporation. All rights reserved.
  7. @REM
  8. @REM -----------------------------------------------------------------
  9. @if defined _CPCMAGIC goto CPCBegin
  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 File::Temp;
  17. use File::Copy;
  18. use PbuildEnv;
  19. use ParseArgs;
  20. use Logmsg;
  21. use cksku;
  22. sub Usage { print<<USAGE; exit(1) }
  23. layout [-l <language>]
  24. Updates layout.inf for each sku with the sizes of the binaries
  25. USAGE
  26. parseargs('?' => \&Usage);
  27. # Support incremental runs.
  28. if ( -f "$ENV{_NTPOSTBLD}\\build_logs\\bindiff.txt" ) {
  29. if ( system "findstr /ilc:\"layout\" $ENV{_NTPOSTBLD}\\build_logs\\bindiff.txt" ) {
  30. logmsg "Not running layout.cmd - layout has not changed";
  31. exit;
  32. }
  33. }
  34. # Find file sizes for all of the skus.
  35. my %filesizes;
  36. my %dirs = (
  37. PRO => "$ENV{_NTPOSTBLD}",
  38. PER => "$ENV{_NTPOSTBLD}\\perinf",
  39. SRV => "$ENV{_NTPOSTBLD}\\srvinf",
  40. BLA => "$ENV{_NTPOSTBLD}\\blainf",
  41. SBS => "$ENV{_NTPOSTBLD}\\sbsinf",
  42. ADS => "$ENV{_NTPOSTBLD}\\entinf",
  43. DTC => "$ENV{_NTPOSTBLD}\\dtcinf"
  44. );
  45. my %profs = {};
  46. logmsg "Reading in default file sizes.";
  47. addDefaults(\%profs);
  48. logmsg "Finding actual file sizes...";
  49. addSizes($dirs{PRO}, \%profs);
  50. $filesizes{PRO} = \%profs;
  51. my %perfs = %profs;
  52. addSizes($dirs{PER}, \%perfs);
  53. $filesizes{PER} = \%perfs;
  54. my %srvfs = %profs;
  55. addSizes($dirs{SRV}, \%srvfs);
  56. $filesizes{SRV} = \%srvfs;
  57. my %blafs = %srvfs;
  58. addSizes($dirs{BLA}, \%blafs);
  59. $filesizes{BLA} = \%blafs;
  60. my %sbsfs = %srvfs;
  61. addSizes($dirs{SBS}, \%sbsfs);
  62. $filesizes{SBS} = \%sbsfs;
  63. my %adsfs = %srvfs;
  64. addSizes($dirs{ADS}, \%adsfs);
  65. $filesizes{ADS} = \%adsfs;
  66. my %dtcfs = %adsfs;
  67. addSizes($dirs{DTC}, \%dtcfs);
  68. $filesizes{DTC} = \%dtcfs;
  69. # Figure out what skus need to be done.
  70. foreach my $sku (keys %dirs) {
  71. if ( !cksku::CkSku($sku, $ENV{LANG}, $ENV{_BUILDARCH}) ) {
  72. delete $dirs{$sku};
  73. logmsg "Sku $sku skipped.";
  74. }
  75. }
  76. # Figure out what files need to be updated.
  77. foreach my $sku (keys %dirs) {
  78. my $i;
  79. for ($i=0; $i < 2; ++$i ) {
  80. my $dir = $i ? "$dirs{$sku}\\realsign":$dirs{$sku};
  81. my $inf_file = "$dir\\layout.inf";
  82. my $temp_inf = "$dir\\layout.inf.tmp";
  83. logmsg "Adding file sizes to $inf_file.";
  84. # Open files for making changes to layout.inf.
  85. if ( !open TEMP, ">$temp_inf" ) {
  86. errmsg "Unable to create temporary file -- fatal";
  87. die;
  88. }
  89. if ( !open INF, $inf_file ) {
  90. errmsg "Could not open $inf_file ($!)";
  91. die;
  92. }
  93. # Insert file sizes into the inf.
  94. my $arch = $ENV{_BUILDARCH};
  95. my $fParseLine;
  96. my $line_num = 0;
  97. foreach (<INF>) {
  98. $line_num++;
  99. next if /^\s*(;.*)?$/;
  100. # Check for new SourceDisksFiles section entries
  101. if (/^\s*\[([^\]]*)\]\s*$/) {
  102. my $sect = $1;
  103. if ( $sect =~ /^sourcedisksfiles(\.$arch)?$/i ) {
  104. $fParseLine = 1;
  105. } else {
  106. undef $fParseLine;
  107. }
  108. next;
  109. }
  110. # Process lines inside of matching sections
  111. if( $fParseLine ) {
  112. if (/^(\s*([^\s=]+)[^\,]*\,[^\,]*\,)(\d*)(.*)$/) {
  113. # Get size of file
  114. my $file_name = lc $2;
  115. my $file_size = $filesizes{$sku}->{$file_name};
  116. if ( !$file_size ) {
  117. wrnmsg "Unable to get size info for: $file_name";
  118. $file_size = 222222;
  119. }
  120. # Add/replace size
  121. $_ = "$1$file_size$4\n";
  122. } else {
  123. wrnmsg( "Unrecognized entry in $inf_file at line $line_num: $_" );
  124. }
  125. }
  126. } continue {
  127. print TEMP $_;
  128. }
  129. close INF;
  130. close TEMP;
  131. # Move the new version into place.
  132. if ( !unlink $inf_file ) {
  133. errmsg "Could not remove old $inf_file ($!) -- new version is located at $temp_inf";
  134. die;
  135. }
  136. if ( !copy( $temp_inf, $inf_file ) ) {
  137. errmsg "Unable to copy new $inf_file ($!) -- new version is located at $temp_inf";
  138. die;
  139. }
  140. unlink $temp_inf;
  141. }
  142. }
  143. # Populate the oc infs with file sizes.
  144. foreach my $dir (values %dirs) {
  145. logmsg "Calling ocinf for $dir\\sysoc.inf";
  146. sys("ocinf.exe -inf:$dir\\sysoc.inf -layout:$dir\\layout.inf >> $ENV{TEMP}\\layout.err");
  147. }
  148. # Call an external function, then handle errors.
  149. sub sys {
  150. my $cmd = shift;
  151. print "$cmd\n";
  152. system($cmd);
  153. if ($?) {
  154. die "ERROR: $cmd ($?)\n";
  155. }
  156. }
  157. # Add file sizes from a directory to a hash.
  158. sub addSizes {
  159. my ($dir, $hash) = @_;
  160. return if !-d $dir;
  161. if ( !opendir DIR, $dir ) {
  162. errmsg "Could not open dir $dir ($!)";
  163. die;
  164. }
  165. my @files = readdir DIR;
  166. closedir DIR;
  167. foreach my $file (@files) {
  168. my $full = "$dir\\$file";
  169. next if -d $full;
  170. my $size = -s $full;
  171. $hash->{lc$file} = $size;
  172. }
  173. return;
  174. }
  175. # Add file sizes from the defaults file.
  176. sub addDefaults {
  177. my ($hash) = @_;
  178. my $deffile = "$ENV{RazzleToolPath}\\postbuildscripts\\infsizedefs.$ENV{_BuildArch}.tbl";
  179. return if !-f $deffile;
  180. if ( !open DEFAULT, $deffile ) {
  181. errmsg "Could not open $deffile ($!)";
  182. die;
  183. }
  184. my $line_num = 0;
  185. foreach (<DEFAULT>) {
  186. $line_num++;
  187. if ( /^\s*$/ ) {next} # skip empty lines
  188. if ( /^\s*;/ ) {next} # skip comments (;)
  189. if ( /^([^:]+):(\d+)\s*$/ ) {
  190. $hash->{lc$1} = $2;
  191. } else {
  192. wrnmsg "Unrecognized entry in $deffile at line $line_num: $_";
  193. }
  194. }
  195. close DEFAULT;
  196. return;
  197. }