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.

197 lines
5.5 KiB

  1. # script for crc file generation
  2. # version : 1.1
  3. # date : 5/17/99
  4. # author : hiroi
  5. # 1/12/00 - updated by jfeltis
  6. #ARGV[0] : src prop server path : \\ntdev\\release\main\usa\2197\x86fre
  7. #ARGV[1] : dst path : \\ntbldsrv\\crc$
  8. #ARGV[2], ARGV[3], ARGV[4]... : products : pro, bla, sbs, srv, ent, ads
  9. %Products = (
  10. 'pro' => 0, 'bla' => 0, 'sbs' => 0, 'srv' => 0, 'ads' => 0, 'dtc' => 0
  11. );
  12. @Products = (
  13. 'pro', 'bla', 'sbs', 'srv', 'ads', 'dtc'
  14. );
  15. $SleepTime = 300; # 5 minutes
  16. $RetryCount= 100; # 100 times
  17. #main
  18. # argument check
  19. if( $#ARGV < 2 ) { &usage; exit(1); }
  20. $SrcBasePath;
  21. $DstPath;
  22. $Error = &argcheck;
  23. die $Error if ($Error ne '');
  24. print "src is $SrcBasePath\n";
  25. print "dst is $DstPath\n";
  26. $LogFileName = &MakeLogFileName($SrcBasePath, $DstPath);
  27. $BaseCRCFileName= &MakeBaseCRCFileName($SrcBasePath, $DstPath);
  28. # if the log file exists then another release server is working on the CRCs, so exit
  29. if( -e $LogFileName ) {print "$LogFileName exists\n"; exit 0; }
  30. #print "doing CRC for $ARGV[0]\n";
  31. open(LOGFILE, "> $LogFileName");
  32. select( (select(LOGFILE), $|=1)[0] ); # auto flush LOGFILE
  33. foreach $Product (@Products) {
  34. if( $Products{$Product} ) {
  35. print "compute CRC for $Product\n";
  36. $SrcPath = "$SrcBasePath\\$Product";
  37. $CRCFileName1 = "$BaseCRCFileName\_$Product\.crc";
  38. $CRCFileName2 = "$BaseCRCFileName\_$Product\.txt";
  39. $CompressedCRCFileName = "$BaseCRCFileName\_$Product\.tx\_";
  40. if( -e $SrcPath && -d_ ) { # if src dir exists
  41. $rc = &DoCommand( "crcwalk $SrcPath > $CRCFileName1") &&
  42. &ModifyCRCFile($CRCFileName1,$CRCFileName2,$Product)&&
  43. &DoCommand( "compress -r $CRCFileName2 > nul") &&
  44. &GetCRCofCRCFile($CompressedCRCFileName) &&
  45. &DoCommand( "del /F/Q $CRCFileName2 > nul");
  46. if( $rc ) {
  47. &LogOutput( "$CRCFileName2 was generated and compressed successfully\n" );
  48. } else {
  49. &LogOutput( "Error:Couldn't generate CRC file $SrcPath\n" );
  50. }
  51. } else {
  52. &LogOutput( "Error:Target product $Product is not found at $SrcBasePath\n" );
  53. }
  54. }
  55. }
  56. close(LOGFILE);
  57. #end main
  58. sub DoCommand {
  59. local( $command ) = @_;
  60. do {
  61. $rc = !system($command);
  62. unless($rc) {
  63. &LogOutput( "Retrying $command\n");
  64. sleep($SleepTime);
  65. $RetryCount--;
  66. }
  67. } until( $rc || !$RetryCount );
  68. $rc;
  69. }
  70. # param1 Input file name
  71. # param2 Output file name
  72. # param3 Product name
  73. # This routine modify the each line of the crc file(input file)
  74. # \\kkntx86t\2040.usa.x86\chk.pub\ddk\inc\afilter.h 0x01BE1502 89FB5DD4 7313 0x307989D0
  75. # to like below
  76. # chk.pub\ddk\inc\afilter.h 0x01BE1502 89FB5DD4 7313 0x307989D0
  77. sub ModifyCRCFile {
  78. local($inFile, $outFile, $product) = @_;
  79. do {
  80. $rc = open(IN,$inFile) && open(OUT,">$outFile");
  81. if( $rc ) {
  82. while(<IN>) {
  83. chop;
  84. /\\$product\\(.*)$/;
  85. print OUT "$1\n";
  86. }
  87. close(IN);
  88. close(OUT);
  89. &DoCommand( "del /F/Q $inFile > nul");
  90. } else {
  91. &LogOutput( "Couldn't modify CRC file $inFile to $outFile\n");
  92. }
  93. } until $rc;
  94. $rc;
  95. }
  96. # This routine calculate the CRC of $file
  97. # and output the result to logfile
  98. sub GetCRCofCRCFile {
  99. local( $fname ) = @_;
  100. $command = "crcwalk $fname > $fname\.crc";
  101. $rc = &DoCommand( $command );
  102. if( $rc ) {
  103. open( CRC, "$fname\.crc" );
  104. &LogOutput( <CRC> );
  105. close(CRC);
  106. &DoCommand( "del /F/Q $fname\.crc > nul");
  107. }
  108. $rc;
  109. }
  110. # param1 src path : \\\\ntrelic2\\release\usa\2197.x86fre.main.000106-2102
  111. # param1 src path : \\ntbuilds\\release\main\usa\2197\x86fre
  112. # param2 dst path : \\\\scratch\\scratch\\crc$
  113. # return logfilename : \\\\scratch\\scratch\\crc\\crc_usa_2197_x86_fre.log
  114. sub MakeLogFileName {
  115. local( $srcpath, $dstpath ) = @_;
  116. # $srcpath =~ /.*\\([^\.]+)\\([^\.]+)\.([^\.]+)\.([^\.]+)\.([0-9]+\-[0-9]+)$/;
  117. # $srcpath =~ /.*\\([^\.]+)\\([^\.]+)\.([^\.]{3})([^\.]{3})\.([^\.]+)\.([0-9]+\-[0-9]+)$/;
  118. $srcpath =~ /.*\\([^\.]+)\\([0-9]+)\\([^\.]+)([^\.]{3})$/;
  119. $logfilename = "$dstpath\\crc\_$1\_$2\_$3\_$4\.log";
  120. $logfilename;
  121. }
  122. # param1 src path : \\\\ntrelic2\\release\usa\2197.x86fre.main.000106-2102
  123. # param1 src path : \\ntbuilds\\release\main\usa\2197\x86fre
  124. # param2 dst path : \\\\scratch\\scratch\\crc$
  125. # return baseCRCFileName : \\\\scratch\\scratch\\crc\\crc_usa_2197_x86_fre
  126. sub MakeBaseCRCFileName {
  127. local( $srcpath, $dstpath ) = @_;
  128. # $srcpath =~ /.*\\([^\.]+)\\([^\.]+)\.([^\.]{3})([^\.]{3})\.([^\.]+)\.([0-9]+\-[0-9]+)$/;
  129. $srcpath =~ /.*\\([^\.]+)\\([0-9]+)\\([^\.]+)([^\.]{3})$/;
  130. $baseCRCFileName = "$dstpath\\crc\_$1\_$2\_$3\_$4";
  131. $baseCRCFileName;
  132. }
  133. sub LogOutput {
  134. local($message) = @_;
  135. @tm = localtime(time());
  136. $tm[4]++;
  137. $str = "$tm[4]/$tm[3] $tm[2]:$tm[1]:$tm[0] $message";
  138. print $str;
  139. print LOGFILE $str;
  140. }
  141. # Check if arguments are right or not
  142. sub argcheck {
  143. $ErrorMessage = "";
  144. ARGCHK: {
  145. $ARGV[0]=~ s/[\\]+$//;
  146. $ARGV[1]=~ s/[\\]+$//;
  147. # unless ( -e $ARGV[0] && -d _ ) { $ErrorMessage = "$ARGV[0] not found\n"; last ARGCHK; }
  148. $SrcBasePath = $ARGV[0];
  149. # unless ( -e $ARGV[1] && -d _ ) { $ErrorMessage = "$ARGV[1] not found\n"; last ARGCHK; }
  150. $DstPath = $ARGV[1];
  151. $i = 2;
  152. do {
  153. $str = $ARGV[$i]; $str =~ tr/A-Z/a-z/;
  154. unless ( defined $Products{ $str } ) { $ErrorMessage = "$ARGV[$i] is not correct product\n"; last ARGCHK; }
  155. $Products{$str} = 1;
  156. } until( $ARGV[++$i] =~ /^[\/\-](.*)/ || $i > $#ARGV);
  157. }
  158. $ErrorMessage;
  159. }
  160. # Show the usage about arguments when they were not right
  161. sub usage {
  162. print " perl $thispl buildpath dstpath products\n" .
  163. "\n" .
  164. " i.e) perl $thispl \\\\ntrelic2\\usa\.2033\.x86 \\\\SomeServer\\SomeShare\\crc pro\n" .
  165. " perl $thispl \\\\ntrelic2\\usa\.2033\.x86 \\\\SomeServer\\SomeShare\\crc pro bla sbs srv ads dtc\n";
  166. }