common/tools/analysis/depends.pl
changeset 1259 5f8149838262
equal deleted inserted replaced
1258:7c13417d5e31 1259:5f8149838262
       
     1 #!perl -w
       
     2 # Copyright (c) 2010 Symbian Foundation Ltd
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of the License "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Symbian Foundation Ltd - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # Wrapper for dependency analysis tool (http://www.dependencywalker.com), which identifies missing dependencies. This script will
       
    15 # process a set of given binaries and produce a tab separated output in the following format
       
    16 #
       
    17 #   Missing DLL/EXE		(binary with broken dependancy)
       
    18 #
       
    19 # Note: 
       
    20 # 1) Requires minimum of v2.0 of depends.exe to be available in the path.
       
    21 # 2) Binaries are dealt with sequentially. Any parallelisation should be dealt with by whoever calls this tool.
       
    22 #
       
    23 # Usage:
       
    24 # perl depends.pl <file pattern>
       
    25 #
       
    26 # Example:
       
    27 # perl depends.pl M:\epoc32\release\winscw\udeb\avkon.dll
       
    28 # perl depends.pl M:\epoc32\release\winscw\udeb\libOpenV* 
       
    29 # perl depends.pl M:\epoc32\release\winscw\udeb\*
       
    30 #
       
    31 use Text::CSV;
       
    32 my %missing_binaries;
       
    33 my $debug = 0;
       
    34 
       
    35 sub walk_binary($)
       
    36 {
       
    37   my $filename = shift;
       
    38   my $walk_cmd = "depends.exe /oc:$filename.csv /c $filename";
       
    39   my $ret = system("$walk_cmd");
       
    40   print "$walk_cmd --DONE\n" if $debug==1;
       
    41 
       
    42   # Load CSV
       
    43   
       
    44   my $csv = Text::CSV->new();
       
    45   my @rows;
       
    46   
       
    47   open my $csvText, "<", $filename.".csv" or die;
       
    48   while ( my $row = $csv->getline( $csvText ) ) 
       
    49   {
       
    50      # column 0 is "?" if unknown dependency
       
    51      if ($row->[0] =~ m/^\?$/)
       
    52 	 {
       
    53          # column 1 contains missing dependency	
       
    54 	 print "MISSING: $filename is missing $row->[1]\n" if $debug==1;
       
    55 	 $missing_binaries{"$row->[1] \t\t($filename)"} = 1;
       
    56 	 } 
       
    57   }
       
    58   $csv->eof or $csv->error_diag();
       
    59   # cleanup
       
    60   close $csvText;
       
    61   system("del $filename.csv");
       
    62   
       
    63 }
       
    64 
       
    65 
       
    66 my @files = map(glob,@ARGV);
       
    67 foreach my $file (@files)
       
    68 {
       
    69   print "Walking $file...\n" if $debug==1;
       
    70   walk_binary($file);
       
    71 }
       
    72 print join("\n", sort keys %missing_binaries, "");