|
1 rem |
|
2 rem Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 rem All rights reserved. |
|
4 rem This component and the accompanying materials are made available |
|
5 rem under the terms of "Eclipse Public License v1.0" |
|
6 rem which accompanies this distribution, and is available |
|
7 rem at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 rem |
|
9 rem Initial Contributors: |
|
10 rem Nokia Corporation - initial contribution. |
|
11 rem |
|
12 rem Contributors: |
|
13 rem |
|
14 rem Description: |
|
15 rem |
|
16 |
|
17 @goto Invoke |
|
18 |
|
19 #!perl |
|
20 # |
|
21 # This Script Runs PCLint Static Code Analysis tool . |
|
22 # |
|
23 # runLint.cmd |
|
24 |
|
25 |
|
26 # Run from a directory containing a bld.inf |
|
27 |
|
28 use strict; |
|
29 use Cwd; |
|
30 |
|
31 my($pclintDir)= "pclint"; |
|
32 mkdir $pclintDir; |
|
33 |
|
34 # Get Code Type. The value for this is blank for production code and test for test code |
|
35 my $type = ""; |
|
36 my $filterFile = "normal.lnt"; |
|
37 my $filterFileDir = "C:\\APPS\\pclint_8.0q"; |
|
38 my $destination; |
|
39 if($#ARGV >= 0 ) { |
|
40 $destination = $ARGV[0] ; |
|
41 } |
|
42 else{ |
|
43 $destination= cwd ; |
|
44 } |
|
45 $destination.="\\".'PCLint'; |
|
46 system("mkdir $destination") ; |
|
47 $filterFileDir=$ARGV[1] if($#ARGV >= 1 ); |
|
48 $filterFile=$ARGV[2] if($#ARGV >= 2 ); |
|
49 $type = $ARGV[3] if($#ARGV >= 3 ); |
|
50 if($ARGV[0]=~m/-h|-H/) |
|
51 { |
|
52 usage(); |
|
53 exit 0; |
|
54 } |
|
55 |
|
56 # Re generate winscw makefile |
|
57 #system( "bldmake -k bldfiles" ); |
|
58 #system( "abld -k $type makefile winscw" ); |
|
59 |
|
60 #copy .lnt file to local folder |
|
61 system( "copy $filterFileDir\\*.lnt . " ); |
|
62 |
|
63 # Run Lint over each of the requested makefiles |
|
64 # The make file is used to determine source, include paths; and #defines to use |
|
65 open WHATCMD, "abld $type makefile winscw -w |"; |
|
66 |
|
67 open(SUMMARY,">$destination\\summary.txt") || die " Can't Open Summary FileName \n"; |
|
68 |
|
69 while( <WHATCMD> ) |
|
70 { |
|
71 chomp; |
|
72 my $makeFile = $_; |
|
73 my @temparray; |
|
74 if( $makeFile =~ /winscw$/i ) |
|
75 { |
|
76 @temparray=split(/\./,$makeFile); |
|
77 @temparray=split(/\\/,$temparray[0]); |
|
78 my $fileName = pop(@temparray); |
|
79 $fileName = $fileName."\.txt"; |
|
80 print "\nRunning PCLint for Module $fileName \n"; |
|
81 my $optionFile = "current.lnt"; |
|
82 unlink( $optionFile ) if( -f $optionFile ); |
|
83 GenerateOptions( $makeFile, $optionFile ); |
|
84 system( "lint-nt.exe -i $filterFile current.lnt >$destination\\$fileName"); |
|
85 unlink( $optionFile ) if( -f $optionFile ); |
|
86 print SUMMARY "Module Name\t: $fileName \n"; |
|
87 print SUMMARY " Total Errors\t: ".countError($fileName,'error')."\n"; |
|
88 print SUMMARY " Total Warnings\t: ".countError($fileName,'Warning')."\n"; |
|
89 } |
|
90 } |
|
91 close SUMMARY; |
|
92 system( "del *.lnt" ); |
|
93 |
|
94 sub GenerateOptions($$) |
|
95 # generate PC-LINT options file from winscw makefile |
|
96 { |
|
97 my ($makeFile, $optionFile) = @_; |
|
98 |
|
99 open INP, $makeFile or die "Can't open $makeFile"; |
|
100 my $line; |
|
101 my $cwd; |
|
102 while(defined($line = <INP>)) |
|
103 { |
|
104 chomp $line; |
|
105 if($line =~ /^# CWD (.+)/) |
|
106 { |
|
107 $cwd = $1; |
|
108 last; |
|
109 } |
|
110 } |
|
111 |
|
112 my $inc = ""; |
|
113 my $defs = ""; |
|
114 my $src = ""; |
|
115 my $totLine = ""; |
|
116 while(defined($line = <INP>)) |
|
117 { |
|
118 chomp $line; |
|
119 if($line =~ /(.*)\\$/) |
|
120 { |
|
121 $totLine .= $1; |
|
122 } |
|
123 else |
|
124 { |
|
125 $totLine .= $line; |
|
126 if($inc eq "" && $totLine =~ /^\s*INCDIR\s*=(.+)/) |
|
127 { |
|
128 my @dirs = split /\s+-i\s+/, $1; |
|
129 foreach my $dir (@dirs) |
|
130 { |
|
131 $dir =~ s/-cwd source/ /g; |
|
132 $dir =~ s/-i-/ /g; |
|
133 $dir =~ s/^\s*//; |
|
134 $dir =~ s/\s*$//; |
|
135 |
|
136 my @forceIncList = split /\s+-include\s+/, $dir; |
|
137 my $isInc = 1; |
|
138 foreach my $force (@forceIncList) |
|
139 { |
|
140 $force =~ s/\"//g; |
|
141 if( $force ) |
|
142 { |
|
143 $inc .= $isInc? "-i$force\n" : "-header($force)\n"; |
|
144 $isInc = 0; |
|
145 } |
|
146 } |
|
147 } |
|
148 } |
|
149 elsif($defs eq "" && $totLine =~ /^\s*CWDEFS\s*=\s*(.+)/) |
|
150 { |
|
151 my @macs = split /\s*-d/, $1; |
|
152 foreach my $mac (@macs) |
|
153 { |
|
154 $mac =~ s/\"//g; |
|
155 $mac =~ s/^ //; |
|
156 $mac =~ s/\s.+$//g; |
|
157 $defs .= "-d$mac\n"; |
|
158 } |
|
159 } |
|
160 elsif($totLine =~ /^\$\(EPOCBLDUREL\)\\.+\.o : (\S+)/) # NB! this presumes that source file paths never include whitespace! if they do then (\S+) has to change to allow for dbl-quote packaging |
|
161 { |
|
162 $src .= "$1\n" if( $1 !~ /\.uid\.cpp$/i ); |
|
163 } |
|
164 $totLine = ""; |
|
165 } |
|
166 } |
|
167 |
|
168 open OUT, ">$optionFile" or die "can't create lint options file $optionFile"; |
|
169 |
|
170 print OUT "$inc$defs-d_DEBUG\n-d_UNICODE\n$src\n"; |
|
171 |
|
172 close OUT; |
|
173 } |
|
174 |
|
175 sub usage |
|
176 { |
|
177 print "\n\t Usage : \n"; |
|
178 print "\t\t runLint <result_destination_directory> <pclint_directory> <filter_file> <option> \n "; |
|
179 print "\t\t Option : The value for this is blank for production code and test for test code\n"; |
|
180 print "\t\t Example:runLint C:\\test C:\\APPS\\pclint_8.0q normal.lnt \n"; |
|
181 print "\n\t Note:This script should be run from where bld.inf file available\n"; |
|
182 print "\t If no arguments available then default will be used.\n"; |
|
183 print "\n\t runLint -h -> To print this help\n"; |
|
184 } |
|
185 |
|
186 |
|
187 sub countError |
|
188 { |
|
189 my($fileName,$searchStr)= @_; |
|
190 my($count) = 0; |
|
191 open FILE , "$destination\\$fileName" or die " Can't open $fileName "; |
|
192 my @lines = <FILE>; |
|
193 foreach my $line (@lines) |
|
194 { |
|
195 if($line=~/: $searchStr/) |
|
196 { |
|
197 $count++; |
|
198 } |
|
199 } |
|
200 close FILE; |
|
201 return $count; |
|
202 } |
|
203 |
|
204 |
|
205 __END__ |
|
206 |
|
207 :Invoke |
|
208 @perl -x -S M:\multimediasharing\internal\group\runLint.cmd %1 %2 %3 %4 %5 %6 %7 %8 %9 |