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.

361 lines
10 KiB

  1. # ---------------------------------------------------------------------------
  2. # Script: bindiff.pl
  3. #
  4. # (c) 2000 Microsoft Corporation. All rights reserved.
  5. #
  6. # Purpose: This script is an example of a perl script in the NT postbuild
  7. # environment.
  8. #
  9. # Version: 1.00 (06/13/2000) : (dmiura) Add international complience
  10. #---------------------------------------------------------------------
  11. # Set Package
  12. package bindiff;
  13. # Set the script name
  14. $ENV{script_name} = 'bindiff.pl';
  15. # Set version
  16. $VERSION = '1.00';
  17. # Set required perl version
  18. require 5.003;
  19. # Use section
  20. use lib $ENV{ "RazzleToolPath" } . "\\PostBuildScripts";
  21. use GetParams;
  22. use strict;
  23. no strict 'vars';
  24. use LocalEnvEx;
  25. use Logmsg;
  26. # Require section
  27. require Exporter;
  28. # Global variable section
  29. my( $ScriptName, $LogFile, $Return, $Argument, $AppendMode );
  30. my( $MyBinaries, $ExitCode );
  31. my( $DataFile, $SnapShotFile, $SnapShotFileBak, $SnapShotFileBakName );
  32. my( $ShapShotFileBakName, $DiffFile, $AltDiffFile, $TmpDiffFile, $FirstPass );
  33. my( $FirstPassFile );
  34. my( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime );
  35. my( $ctime, $blksize, $blocks );
  36. my( $ShortDiffFileName );
  37. sub Main {
  38. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  39. # Begin Main code section
  40. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  41. # Return when you want to exit on error
  42. # <Implement your code here>
  43. # before anything, if we're running first pass, we don't want to generate
  44. # bindiff files
  45. $FirstPassFile = $ENV{ "_NTPostBld" } . "\\congeal_scripts\\firstpass.txt";
  46. undef( $FirstPass );
  47. if ( -e $FirstPassFile ) { $FirstPass = "TRUE"; }
  48. # Check command line option
  49. if (defined $append) {$AppendMode = "-a"};
  50. $ExitCode = 0;
  51. $Logmsg::DEBUG = 1; # set to 1 to activate logging of dbgmsg's
  52. $DataFile = $ENV{_NTPostBld} . "\\build_logs\\CdData.txt";
  53. if ( -e "$DataFile\.full" ) { $DataFile .= "\.full"; }
  54. $SnapShotFile = $ENV{_NTPostBld} . "\\build_logs\\BinSnapShot.txt";
  55. $SnapShotFileBak = $ENV{_NTPostBld} . "\\build_logs\\BinSnapShot.bak";
  56. $SnapShotFileBakName = $SnapShotFileBak;
  57. if ( $SnapShotFileBak =~ /.*\\([^\\]+?)$/ ) { $SnapShotFileBakName = $1; }
  58. $DiffFile = $ENV{_NTPostBld} . "\\build_logs\\BinDiff.txt";
  59. $ShortDiffFileName = "BinDiff";
  60. $TmpDiffFile = $ENV{_NTPostBld} . "\\build_logs\\BinDiff1.txt";
  61. $AltDiffFile = $ENV{_NTPostBld} . "\\build_logs\\BinDiff2.txt";
  62. unless ( $AppendMode ) { &DeleteFile( $DiffFile ); }
  63. &DeleteFile( $SnapShotFileBak );
  64. # move the old snap shot file
  65. if ( -e $SnapShotFile ) { system( "ren $SnapShotFile $SnapShotFileBakName" ); }
  66. # parse CdData.txt to get our list of files
  67. &ReadDataFile();
  68. # if the backup exists, we need to compare now
  69. if ( -e $SnapShotFileBak ) {
  70. system( "windiff $SnapShotFileBak $SnapShotFile -Fx $TmpDiffFile" );
  71. system( "perl \%RazzleToolPath\%\\PostBuildScripts\\GenDiff.pl $AppendMode" );
  72. }
  73. # uniqify the bindiff.txt file
  74. if ( -e $DiffFile ) {
  75. system( "perl \%RazzleToolPath\%\\PostBuildScripts\\unique.pl -i\:$DiffFile " .
  76. "-o\:$AltDiffFile" );
  77. system( "copy $AltDiffFile $DiffFile" );
  78. }
  79. # save off each bindiff.txt for debugging
  80. &SaveFile ($ShortDiffFileName);
  81. # if we're first, pass delete the bindiff.txt file
  82. if ( $FirstPass eq "TRUE" ) { &DeleteFile( $DiffFile ); }
  83. # delete the old backup file
  84. &DeleteFile( $SnapShotFileBak );
  85. # delete the temporary diff file
  86. &DeleteFile( $TmpDiffFile );
  87. QuitGracefully:
  88. ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
  89. $ctime, $blksize, $blocks ) = stat( $DiffFile );
  90. #I don't think we want to delete 0-lenght bindiffs, but there may
  91. #be implications I don't realize, so I'm leaving the code in for now. Wade
  92. #if ( $size == 0 ) {
  93. # logmsg( "Zero length bindiff file, deleting ..." );
  94. # if (-e $DiffFile) {
  95. # system( "del $DiffFile" );
  96. # }
  97. #
  98. #}
  99. $ENV{errors} = "$ExitCode";
  100. return;
  101. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  102. # End Main code section
  103. # /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  104. }
  105. # <Implement your subs here>
  106. sub ReadDataFile
  107. {
  108. my( @DataLines, $Line, $FileName, $Junk );
  109. my( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime );
  110. my( $ctime, $blksize, $blocks );
  111. unless ( open( INFILE, $DataFile ) ) {
  112. errmsg( "Failed to open $DataFile, exiting." );
  113. $ExitCode++;
  114. goto QuitGracefully;
  115. }
  116. @DataLines = <INFILE>;
  117. close( INFILE );
  118. unless ( open( OUTFILE, ">$SnapShotFile" ) ) {
  119. errmsg( "Failed to open $SnapShotFile for write, exiting." );
  120. $ExitCode++;
  121. goto QuitGracefully;
  122. }
  123. foreach $Line ( @DataLines ) {
  124. if ( $Line =~ /\;/ ) { next; }
  125. ( $FileName, $Junk ) = split( /\s+/, $Line );
  126. ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
  127. $ctime, $blksize, $blocks ) = stat( $ENV{_NTPostBld} . "\\" . $FileName );
  128. print( OUTFILE "$ENV{_NTPostBld}\\$FileName , $size , $mtime\n" );
  129. }
  130. # add the ddk files brute force
  131. @DataLines = `\@for \/f \%a in \(\'dir \/b \/s \/a-d $ENV{_NTPostBld}\\ddk_flat\'\) do \@echo \%a , \%\~za , \%\~ta`;
  132. foreach $Line ( @DataLines ) {
  133. ( $FileName, $Junk ) = split( /\s+/, $Line );
  134. ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
  135. $ctime, $blksize, $blocks ) = stat( $FileName );
  136. print( OUTFILE "$FileName , $size , $mtime\n" );
  137. }
  138. # add the shimdll files brute force
  139. @DataLines = `\@for \/f \%a in \(\'dir \/b \/s \/a-d $ENV{_NTPostBld}\\shimdll\'\) do \@echo \%a , \%\~za , \%\~ta`;
  140. foreach $Line ( @DataLines ) {
  141. ( $FileName, $Junk ) = split( /\s+/, $Line );
  142. ( $dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime,
  143. $ctime, $blksize, $blocks ) = stat( $FileName );
  144. print( OUTFILE "$FileName , $size , $mtime\n" );
  145. }
  146. close( OUTFILE );
  147. }
  148. sub SaveFile
  149. {
  150. my( $FileName ) = @_;
  151. my( $DirName ) = "$ENV{_NTPostBld}\\build_logs\\Bindiff_logs";
  152. my( $Return );
  153. my( $MaxNum ) = 0;
  154. my( $NextNum ) = 0;
  155. $Return = 0;
  156. $Return = system( "md $DirName" ) unless -d $DirName;
  157. if ( $Return != 0 ) {
  158. logmsg( "Failed to make $DirName." );
  159. }
  160. # Find the next available integer to distinguish bindiff files
  161. foreach (<$DirName\\$FileName*.txt>) {
  162. if (/BinDiff(\d+)\.txt$/) {
  163. $MaxNum = $1 if $1 >= $MaxNum;
  164. }
  165. }
  166. $NextNum = $MaxNum + 1;
  167. $DiffFileSave = "$DirName\\$FileName$NextNum.txt";
  168. $Return = system( "copy $DiffFile $DiffFileSave" );
  169. if ( $Return != 0) {
  170. logmsg( "Failed to copy $DiffFile to $DiffFileSave" );
  171. }
  172. }
  173. sub DeleteFile
  174. {
  175. my( $FileName ) = @_;
  176. my( $Return );
  177. $Return = 0;
  178. if ( -e $FileName ) {
  179. $Return = system( "del /f $FileName" );
  180. if ( $Return != 0 ) {
  181. logmsg( "Failed to delete $FileName, will append." );
  182. }
  183. }
  184. return( $Return );
  185. }
  186. sub ValidateParams {
  187. #<Add your code for validating the parameters here>
  188. }
  189. # <Add your usage here>
  190. sub Usage {
  191. print <<USAGE;
  192. Purpose of program
  193. Usage: $0 [-a -l lang]
  194. -a Append mode
  195. -l Language
  196. -? Displays usage
  197. Example:
  198. $0 -l jpn
  199. USAGE
  200. }
  201. sub GetParams {
  202. # Step 1: Call pm getparams with specified arguments
  203. &GetParams::getparams(@_);
  204. # Step 2: Set the language into the enviroment
  205. $ENV{lang}=$lang;
  206. # Step 3: Call the usage if specified by /?
  207. if ($HELP) {
  208. &Usage();
  209. exit 1;
  210. }
  211. }
  212. # Cmd entry point for script.
  213. if (eval("\$0 =~ /" . __PACKAGE__ . "\\.pl\$/i")) {
  214. # Step 1: Parse the command line
  215. # <run perl.exe GetParams.pm /? to get the complete usage for GetParams.pm>
  216. &GetParams ('-o', 'al:', '-p', 'append lang', @ARGV);
  217. # Include local environment extensions
  218. &LocalEnvEx::localenvex('initialize');
  219. # Set lang from the environment
  220. $lang=$ENV{lang};
  221. # Validate the option given as parameter.
  222. &ValidateParams;
  223. # Step 4: Call the main function
  224. &bindiff::Main();
  225. # End local environment extensions.
  226. &LocalEnvEx::localenvex('end');
  227. }
  228. # -------------------------------------------------------------------------------------------
  229. # Script: template_script.pl
  230. # Purpose: Template perl perl script for the NT postbuild environment
  231. # SD Location: %sdxroot%\tools\postbuildscripts
  232. #
  233. # (1) Code section description:
  234. # CmdMain - Developer code section. This is where your work gets done.
  235. # <Implement your subs here> - Developer subs code section. This is where you write subs.
  236. #
  237. # (2) Reserved Variables -
  238. # $ENV{HELP} - Flag that specifies usage.
  239. # $ENV{lang} - The specified language. Defaults to USA.
  240. # $ENV{logfile} - The path and filename of the logs file.
  241. # $ENV{logfile_bak} - The path and filename of the logfile.
  242. # $ENV{errfile} - The path and filename of the error file.
  243. # $ENV{tmpfile} - The path and filename of the temp file.
  244. # $ENV{errors} - The scripts errorlevel.
  245. # $ENV{script_name} - The script name.
  246. # $ENV{_NTPostBld} - Abstracts the language from the files path that
  247. # postbuild operates on.
  248. #
  249. # (3) Reserved Subs -
  250. # Usage - Use this sub to discribe the scripts usage.
  251. # ValidateParams - Use this sub to verify the parameters passed to the script.
  252. #
  253. # (4) Call other executables or command scripts by using:
  254. # system "foo.exe";
  255. # Note that the executable/script you're calling with system must return a
  256. # non-zero value on errors to make the error checking mechanism work.
  257. #
  258. # Example
  259. # if (system("perl.exe foo.pl -l $lang")){
  260. # errmsg("perl.exe foo.pl -l $lang failed.");
  261. # # If you need to terminate function's execution on this error
  262. # goto End;
  263. # }
  264. #
  265. # (5) Log non-error information by using:
  266. # logmsg "<log message>";
  267. # and log error information by using:
  268. # errmsg "<error message>";
  269. #
  270. # (6) Have your changes reviewed by a member of the US build team (ntbusa) and
  271. # by a member of the international build team (ntbintl).
  272. #
  273. # -------------------------------------------------------------------------------------------
  274. =head1 NAME
  275. B<mypackage> - What this package for
  276. =head1 SYNOPSIS
  277. <An code example how to use>
  278. =head1 DESCRIPTION
  279. <Use above example to describe this package>
  280. =head1 INSTANCES
  281. =head2 <myinstances>
  282. <Description of myinstances>
  283. =head1 METHODS
  284. =head2 <mymathods>
  285. <Description of mymathods>
  286. =head1 SEE ALSO
  287. <Some related package or None>
  288. =head1 AUTHOR
  289. <Your Name <your e-mail address>>
  290. =cut
  291. 1;