sbsv1/abld/test/mmpscan.pl
changeset 607 378360dbbdba
parent 599 fa7a3cc6effd
equal deleted inserted replaced
591:22486c9c7b15 607:378360dbbdba
       
     1 # Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "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 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # Perl script to scan tree looking for MMP files with particular keywords
       
    15 # 
       
    16 #
       
    17 
       
    18 use strict;
       
    19 use File::Find;			# for find()
       
    20 use File::Basename;		# for fileparse()
       
    21 use Cwd;				# for getcwd()
       
    22 
       
    23 use Getopt::Long;
       
    24 my %Options=();
       
    25 GetOptions(\%Options, "f=s");
       
    26 
       
    27 my @patterns = (
       
    28 
       
    29 'START\s+BITMAP.*\.MCL',
       
    30 'START\s+BITMAP.*\.MBW',
       
    31 'START\s+BITMAP',
       
    32 'START\s+RESOURCE',
       
    33 'ALWAYS_BUILD_AS_ARM',
       
    34 'ASSPABI',
       
    35 'ASSPEXPORTS',
       
    36 'ASSPLIBRARY',
       
    37 'CAPABILITY',
       
    38 'COMPRESSTARGET',
       
    39 'DEFFILE',
       
    40 'DOCUMENT',
       
    41 'EPOCALLOWDLLDATA',
       
    42 'EPOCCALLDLLENTRYPOINTS',
       
    43 'EPOCDATALINKADDRESS',
       
    44 'EPOCFIXEDPROCESS',
       
    45 'EPOCHEAPSIZE',
       
    46 'EPOCPROCESSPRIORITY',
       
    47 'EPOCSTACKSIZE',
       
    48 'EXPORTLIBRARY',
       
    49 'EXPORTUNFROZEN',
       
    50 'FIRSTLIB',
       
    51 'LANG',
       
    52 # 'LIBRARY',
       
    53 'DEBUGLIBRARY',
       
    54 'LINKAS',
       
    55 'MACRO\s+__SECURE_API__',
       
    56 'MACRO',
       
    57 'NOCOMPRESSTARGET',
       
    58 'NOEXPORTLIBRARY',
       
    59 'NOSTRICTDEF',
       
    60 'OPTION',
       
    61 'RAMTARGET',
       
    62 'RESOURCE',
       
    63 'ROMTARGET',
       
    64 'SECUREID',
       
    65 'SRCDBG',
       
    66 # 'SOURCE',
       
    67 # 'SOURCEPATH',
       
    68 'STATICLIBRARY',
       
    69 'STRICTDEPEND',
       
    70 'SYSTEMINCLUDE',
       
    71 'SYSTEMRESOURCE',
       
    72 # 'TARGET',
       
    73 'TARGETPATH',
       
    74 'TARGETTYPE\s+ANI',
       
    75 'TARGETTYPE\s+APP',
       
    76 'TARGETTYPE\s+CTL',
       
    77 'TARGETTYPE\s+DLL',
       
    78 'TARGETTYPE\s+ECOMIIC',
       
    79 'TARGETTYPE\s+EPOCEXE',
       
    80 'TARGETTYPE\s+EXEDLL',
       
    81 'TARGETTYPE\s+EXEXP',		# must precede TARGETTYPE EXE
       
    82 'TARGETTYPE\s+EXE',
       
    83 'TARGETTYPE\s+FSY',
       
    84 'TARGETTYPE\s+IMPLIB',
       
    85 'TARGETTYPE\s+KDLL',
       
    86 'TARGETTYPE\s+KEXT',
       
    87 'TARGETTYPE\s+KLIB',
       
    88 'TARGETTYPE\s+LDD',
       
    89 'TARGETTYPE\s+LIB',
       
    90 'TARGETTYPE\s+MDA',
       
    91 'TARGETTYPE\s+MDL',
       
    92 'TARGETTYPE\s+NOTIFIER2',
       
    93 'TARGETTYPE\s+NOTIFIER',
       
    94 'TARGETTYPE\s+PDD',
       
    95 'TARGETTYPE\s+PDL',
       
    96 'TARGETTYPE\s+PLUGIN',
       
    97 'TARGETTYPE\s+PLUGIN3',
       
    98 'TARGETTYPE\s+RDL',
       
    99 'TARGETTYPE\s+TEXTNOTIFIER2',
       
   100 'TARGETTYPE\s+VAR',
       
   101 'UID',
       
   102 'USERINCLUDE',
       
   103 'VENDORID',
       
   104 'VERSION',
       
   105 
       
   106 # from START WINS ... END
       
   107 'START\s+WINS',
       
   108 'BASEADDRESS',
       
   109 'WIN32_LIBRARY',
       
   110 'WIN32_RESOURCE',
       
   111 'COPY_FOR_STATIC_LINKAGE',
       
   112 'WIN32_HEADERS',
       
   113 
       
   114 # count some unmatched things
       
   115 'AIF',
       
   116 'SOURCE\s.*\.CIA',			# CIA files
       
   117 'TARGETTYPE\s+(other)?',	# a trick to catch unsupported targettypes
       
   118 'TARGET\s.*DUMMY',			# who doesn't really want a TARGET
       
   119 '#IF',
       
   120 '#INCLUDE_FAILURE',			# unresolved #include directives
       
   121 '#INCLUDE',
       
   122 
       
   123 );
       
   124 
       
   125 my %instances = ();
       
   126 my %patternsbyfile = ();
       
   127 my $mmpcount = 0;
       
   128 
       
   129 sub read_mmp($$$)
       
   130 	{
       
   131 	my ($top,$name,$lines) =@_;
       
   132 	open MMP, "<$name" or print "error: $name $top\n" and return 0;
       
   133 	my @mmplines=<MMP>;
       
   134 	close MMP;
       
   135 	
       
   136 	foreach my $line (@mmplines)
       
   137 		{
       
   138 		push @$lines, $line;
       
   139 		if ($line =~/^\#include\s+(\"|\<)([^"<]+)(\"|\>)/)
       
   140 			{
       
   141 			my $currentdir = getcwd();
       
   142 			my $includename = $2;
       
   143 			if (-f $2)
       
   144 				{
       
   145 				# name exists relative to current directory
       
   146 				}
       
   147 			elsif (-f "$ENV{EPOCROOT}epoc32/include/$includename")
       
   148 				{
       
   149 				$includename = "$ENV{EPOCROOT}epoc32/include/$includename";
       
   150 				}
       
   151 			else
       
   152 				{
       
   153 				print "Can't locate $2 from $currentdir/$name $top\n";
       
   154 				push @$lines, "#INCLUDE_FAILURE";
       
   155 				next;
       
   156 				}
       
   157 			my ($newname, $newdir, $newext) = fileparse($includename, '\..*');
       
   158 			chdir($newdir);
       
   159 			read_mmp("from $name $top", "$newname$newext", $lines);
       
   160 			chdir($currentdir);
       
   161 			}
       
   162 		}
       
   163 	return 1;
       
   164 	}
       
   165 	
       
   166 sub mmpgrep 
       
   167 	{
       
   168 	my $fullname = $File::Find::name;
       
   169 	return if (defined($patternsbyfile{$fullname}));
       
   170 
       
   171 	my ($name,$dir,$ext) = fileparse($fullname,'\..*');
       
   172 	return unless (lc($ext) eq '.mmp');
       
   173 	
       
   174 	my %found = ();
       
   175 	my @lines = ();
       
   176 	return if (read_mmp("", "$name$ext", \@lines)==0);
       
   177 	
       
   178 	$mmpcount++;
       
   179 	my $line;
       
   180 	LINE: foreach $line (@lines)
       
   181 		{
       
   182 		$line = uc $line;
       
   183 		foreach (@patterns)
       
   184 			{
       
   185 			if ($line =~/^\s*$_/)
       
   186 				{
       
   187 				$found{$_} = 1;
       
   188 				next LINE;
       
   189 				}
       
   190 			}
       
   191 		}
       
   192 	close MMP;
       
   193 	foreach (keys %found)
       
   194 		{
       
   195 		@{$instances{$_}} = () if (!defined $instances{$_});
       
   196 		push @{$instances{$_}}, $fullname;
       
   197 		}
       
   198 	@{$patternsbyfile{$fullname}} = sort keys %found;
       
   199 	}
       
   200 
       
   201 # Scan the tree, processing each filename with mmpgrep
       
   202 
       
   203 my @scanlist = ();
       
   204 if ($Options{f})
       
   205 	{
       
   206 	open FILELIST, "<$Options{f}" or die "Cannot open $Options{f}\n";
       
   207 	my $line;
       
   208 	while ($line = <FILELIST>)
       
   209 		{
       
   210 		$line =~ s/#.*$//;		# remove comments
       
   211 		$line =~ s/\s*$//;		# remove trailing ws
       
   212 		$line =~ s/^\s*//;		# remove leading ws
       
   213 		next if ($line eq "");
       
   214 		push @scanlist, $line;
       
   215 		}
       
   216 	close FILELIST;
       
   217 	}
       
   218 push @scanlist, @ARGV;
       
   219 find (\&mmpgrep,@scanlist);
       
   220 
       
   221 # Report the results
       
   222 
       
   223 print "$mmpcount mmp files processed\n";
       
   224 
       
   225 my $pattern;
       
   226 print "\nSummary by pattern\n";
       
   227 foreach $pattern (@patterns)
       
   228 	{
       
   229 	my $count=0;
       
   230 	my $list = $instances{$pattern};
       
   231 	$count = scalar @{$list} if (defined $list);
       
   232 	printf "%-30s %5d\n", $pattern, $count;
       
   233 	}
       
   234 	
       
   235 print "\nDetail\n";
       
   236 foreach $pattern (sort keys %instances)
       
   237 	{
       
   238 	my $list = $instances{$pattern};
       
   239 	my $title = $pattern;
       
   240 	$title =~ s/\\s\+/ /;
       
   241 	print "\n$title:\n";
       
   242 	foreach my $file (@{$list})
       
   243 		{
       
   244 		print "  $file\n";
       
   245 		}
       
   246 	}
       
   247 
       
   248 foreach (sort keys %patternsbyfile)
       
   249 	{
       
   250 	print "\n$_ :  ", join(" ",@{$patternsbyfile{$_}});
       
   251 	}
       
   252 
       
   253 print "\n";