tools/static_dependencies.pl
changeset 12 ab7598bdae30
child 16 58fdbe891c31
equal deleted inserted replaced
11:9fac6902f40b 12:ab7598bdae30
       
     1 # Copyright (c) 2010 Symbian Foundation Ltd.
       
     2 # All rights reserved.
       
     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 - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description: 
       
    14 # This script generates a list of static dependencies for files in a ROM
       
    15 
       
    16 use strict;
       
    17 
       
    18 my %romfiles;
       
    19 my @contents;
       
    20 
       
    21 my $line;
       
    22 while ($line = <>)
       
    23 	{
       
    24   my ($romfile,$hostfile,@columns) = split /,/, $line;		# first two fields are guaranteed to be simple
       
    25 	next if (!defined $hostfile);
       
    26 	next if ($romfile eq "ROM file");		# skip header line
       
    27 	
       
    28 	push @contents, "$romfile\t$hostfile";		# for use with "grep" later
       
    29 	$romfiles{lc $romfile} = $romfile;
       
    30 	}
       
    31 
       
    32 my %dependents;
       
    33 
       
    34 sub print_dependency($$@)
       
    35 	{
       
    36 	my ($romfile,$hostfile,@dependencies) = @_;
       
    37 	print "$romfile\t$hostfile\t", join(":",@dependencies), "\n";
       
    38 	
       
    39 	# Create inverted table 
       
    40 	foreach my $dependent (@dependencies)
       
    41 		{
       
    42 		next if ($dependent =~ /^sid=/);
       
    43 		$dependent = lc $dependent;
       
    44 		
       
    45 		$dependent =~ s/^sys\\bin\\//;	# no directory => sys\bin anyway
       
    46 		$dependent =~ s/\[\S+\]//;	# ignore the UIDs for now
       
    47 		
       
    48 		if (!defined $dependents{$dependent})
       
    49 			{
       
    50 			$dependents{$dependent} = $romfile;
       
    51 			}
       
    52 		else
       
    53 			{
       
    54 			$dependents{$dependent} .= "\t$romfile";
       
    55 			}
       
    56 		}
       
    57 	}
       
    58 
       
    59 sub generate_elftran_dependencies($$)
       
    60 	{
       
    61 	my ($romfile,$hostfile) = @_;
       
    62 	
       
    63 	return if ($hostfile =~ /\/z\//); 	# data files in armv5\urel\z
       
    64 	return if ($hostfile =~ /\.sis$/);	# not an e32 image file
       
    65 
       
    66 	my @elftran = `elftran $hostfile`;
       
    67 	
       
    68 	my $sid;
       
    69 	my @imports;
       
    70 	foreach my $line (@elftran)
       
    71 		{
       
    72 		if ($line =~ /imports from (\S+)\{000a0000\}(\S+)$/)
       
    73 			{
       
    74 			push @imports, $1.$2;
       
    75 			next;
       
    76 			}
       
    77 		if ($line =~ /^Secure ID: (\S+)$/)
       
    78 			{
       
    79 			$sid = $1; 	# presumably owns private/$sid  and various $sid.etxn files
       
    80 			next;
       
    81 			}
       
    82 		}
       
    83 	print_dependency($romfile,$hostfile,"sid=$sid",@imports);
       
    84 	}
       
    85 
       
    86 sub find_dependency_in_sys_bin($$$)
       
    87 	{
       
    88 	my ($romfile,$hostfile,$basename) = @_;
       
    89 	$basename = lc $basename;
       
    90 	foreach my $extension (".exe",".dll")
       
    91 		{
       
    92 		my $dependency = "sys\\bin\\$basename$extension";
       
    93 		if (defined $romfiles{$dependency})
       
    94 			{
       
    95 			print_dependency($romfile,$hostfile,$romfiles{$dependency});
       
    96 			return;
       
    97 			}
       
    98 		}
       
    99 	# grep in the contents list?
       
   100 	# print_dependency($romfile,$hostfile,"unmatched sys\\bin\\$basename");
       
   101 	}
       
   102 
       
   103 foreach $line (@contents)
       
   104 	{
       
   105 	my ($romfile,$hostfile) = split /\t/, $line;
       
   106 	
       
   107 	if ($hostfile =~ /epoc32.release.arm/i)
       
   108 		{
       
   109 		generate_elftran_dependencies($romfile,$hostfile);
       
   110 		next;
       
   111 		}
       
   112 	
       
   113 	# App registration files
       
   114 	if ($romfile =~ /private.10003a3f.*apps\\(.*)_reg\.rsc$/i)
       
   115 		{
       
   116 		my $dependency = "sys\\bin\\$1.exe";
       
   117 		print_dependency($romfile,$hostfile,$dependency);
       
   118 		next;
       
   119 		}
       
   120 	# app resources
       
   121 	if ($romfile =~ /resource.apps\\(.*)(\.mif|\.mbm|\.rsc)$/)
       
   122 		{
       
   123 		my $executable = $1;
       
   124 		$executable =~ s/_aif$//; 	# xxx_aif.mif
       
   125 		$executable =~ s/_loc$//; 	# xxx_loc.rsc
       
   126 		
       
   127 		find_dependency_in_sys_bin($romfile,$hostfile,$executable);
       
   128 		next;
       
   129 		}
       
   130 
       
   131 	# Assume that the rest don't depend on anything, and leave them out.
       
   132 	}
       
   133 
       
   134 print "\n";
       
   135 foreach my $inverted (sort keys %dependents)
       
   136 	{
       
   137 	print "x\t$inverted\t$dependents{$inverted}\n";
       
   138 	}