sbsv1/abld/e32util/checksource.pl
author Bob Rosenberg <bob.rosenberg@nokia.com>
Fri, 27 Aug 2010 14:50:55 +0100
changeset 638 024a31e39848
parent 599 fa7a3cc6effd
permissions -rw-r--r--
Change bld.inf install location to epoc32\tools\sysdeftools
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     1
# Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     2
# All rights reserved.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     3
# This component and the accompanying materials are made available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     4
# under the terms of "Eclipse Public License v1.0"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     5
# which accompanies this distribution, and is available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     7
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     8
# Initial Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    10
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    11
# Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    12
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    13
# Description:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    14
# Front-end to routines checking that source matches filename policy constraints
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    15
# 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    16
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    17
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    18
use FindBin;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    19
use Cwd;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    20
use Getopt::Long qw(:config posix_default);		#permits "+" in arguments, rather than as an option identifier
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    21
use lib $FindBin::Bin;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    22
use CheckSource;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    23
use Pathutl;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    24
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    25
my $preprocessCall = "cpp.exe -w -undef -nostdinc -+ -dI";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    26
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    27
my $verbose = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    28
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    29
my $preprocess = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    30
my $parsefile = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    31
my $metadata = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    32
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    33
GetOptions ('preprocess|pp' => \$preprocess, 'parsefile|pf' => \$parsefile, 'metadata|md' => \$metadata);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    34
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    35
my %warnings;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    36
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    37
$verbose = 1 if $ENV{CHECKSOURCE_VERBOSE};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    38
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    39
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    40
if (!@ARGV)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    41
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    42
	print ("\nchecksource.pl --preprocess|--parsefile|--metadata args\n\n");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    43
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    44
elsif ($preprocess)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    45
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    46
	my $PREPROCESSPIPE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    47
	open PREPROCESSPIPE,"$preprocessCall @ARGV |" or die "ERROR: Can't invoke preprocessor for checksource processing.\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    48
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    49
	my %processedIncludes;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    50
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    51
	my %homelessInclude;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    52
	$homelessInclude{REFERENCE} = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    53
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    54
	my $lineNumber = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    55
	my $currentFile = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    56
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    57
	print "Preprocessing file    : ".$ARGV[scalar(@ARGV)-1]."\n" if ($verbose);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    58
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    59
	while (<PREPROCESSPIPE>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    60
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    61
		if (/^\s*$/o)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    62
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    63
			$lineNumber++;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    64
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    65
			}	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    66
		elsif (/^# (\d+) "(.*)"( \d+)?/o)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    67
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    68
			$lineNumber = scalar $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    69
			$currentFile=$2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    70
			$currentFile=~s-\\\\-\\-go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    71
			$currentFile=~s-\\\/-\\-go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    72
			$currentFile=~s-\/\\-\\-go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    73
			$currentFile=~s-\/\/-\\-go;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    74
			$currentFile=~s/\//\\/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
			$currentFile=~s/^\w://;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    78
		if ($homelessInclude{REFERENCE})
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    79
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    80
			# Resolve #include references using "locating" comments in CPP output.  These may either follow the reference directly,
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    81
			# or may have appeared earlier in prior CPP processing
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    82
			if ($currentFile =~ /$homelessInclude{SEARCH}$/i)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    83
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    84
				CheckSource_Physical (%warnings, $homelessInclude{SOURCEFILE}, "#include", $homelessInclude{REFERENCE}, $homelessInclude{LINENUMBER}, $currentFile, $verbose);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    85
				$processedIncludes{lc($currentFile)} = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    86
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    87
			else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    88
				{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    89
				my @foundProcessedIncludes;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    90
				foreach my $processedInclude (keys %processedIncludes)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    91
					{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    92
					push @foundProcessedIncludes, $processedInclude if ($processedInclude =~ /$homelessInclude{SEARCH}$/i);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    93
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    94
		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    95
				if (@foundProcessedIncludes == 1)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    96
					{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    97
					CheckSource_Physical  (%warnings, $homelessInclude{SOURCEFILE}, "#include", $homelessInclude{REFERENCE}, $homelessInclude{LINENUMBER}, $foundProcessedIncludes[0], $verbose);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    98
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    99
				elsif ((@foundProcessedIncludes > 1) && $verbose)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   100
					{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   101
					print ("WARNING: Multiple matches for #include reference $homelessInclude{REFERENCE} : $homelessInclude{SOURCEFILE}($homelessInclude{LINENUMBER})\n");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   102
					print "\t$_\n" foreach (@foundProcessedIncludes);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   103
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   104
				elsif ($verbose)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   105
					{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   106
					print ("WARNING: Couldn't find #include reference $homelessInclude{REFERENCE} : $homelessInclude{SOURCEFILE}($homelessInclude{LINENUMBER})\n");
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   107
					}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   108
				}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   109
			$homelessInclude{REFERENCE} = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   110
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   111
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   112
		if (/^\s*#include\s*[\"|\<]{1}(.*)[\"|\>]{1}/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   113
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   114
			CheckSource_UnixSlash (%warnings, $currentFile, "#include", $1, $lineNumber, $verbose);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   115
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   116
			$homelessInclude{SOURCEFILE} = $currentFile;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   117
			$homelessInclude{REFERENCE} = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   118
			$homelessInclude{LINENUMBER} = $lineNumber;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   119
			$homelessInclude{SEARCH} = "\\".$homelessInclude{REFERENCE};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   120
			$homelessInclude{SEARCH} =~ s/\//\\/g;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   121
			$homelessInclude{SEARCH} = quotemeta($homelessInclude{SEARCH});
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   122
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   123
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   124
		$lineNumber++ if (!/^# (\d+) "(.*)"( \d+)?/o);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   125
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   126
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   127
	close PREPROCESSPIPE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   128
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   129
elsif ($parsefile)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   130
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   131
	my $SOURCE_FILE = $ARGV[0];		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   132
	open SOURCE_FILE, "< $SOURCE_FILE" or die "ERROR: Can't open $SOURCE_FILE for \"-checksource\".\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   133
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   134
	print "Parsing include file  : $SOURCE_FILE\n" if ($verbose);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   135
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   136
	my $lineNumber = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   137
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   138
	while (<SOURCE_FILE>)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   139
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   140
		$lineNumber++;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   141
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   142
		if (/^\s*#include\s*[\"|\<]{1}(.*)[\"|\>]{1}/)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   143
			{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   144
			CheckSource_UnixSlash (%warnings, $SOURCE_FILE, "#include", $1, $lineNumber, $verbose);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   145
			CheckSource_Lowercase (%warnings, $SOURCE_FILE, "#include", $1, $lineNumber, $verbose);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   146
			}		
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   147
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   148
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   149
	close SOURCE_FILE;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   150
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   151
elsif ($metadata)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   152
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   153
	my ($sourcefile, $item, $reference, $linenumber, $physical, $offset) = @ARGV;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   154
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   155
	$physical = 0 if (!$physical);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   156
	$offset = undef if (!$offset);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   157
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   158
	CheckSource_UnixSlash (%warnings, $sourcefile, $item, $reference, $linenumber, $verbose);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   159
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   160
	if ($physical)
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   161
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   162
		CheckSource_Physical (%warnings, $sourcefile, $item, $reference, $linenumber, $offset, $verbose);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   163
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   164
	else
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   165
		{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   166
		CheckSource_Lowercase (%warnings, $sourcefile, $item, $reference, $linenumber, $verbose);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   167
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   168
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   169
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   170
print "$_\n" foreach (keys %warnings);