sl@0
|
1 |
#
|
sl@0
|
2 |
# Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
# All rights reserved.
|
sl@0
|
4 |
# This component and the accompanying materials are made available
|
sl@0
|
5 |
# under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
# which accompanies this distribution, and is available
|
sl@0
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
#
|
sl@0
|
9 |
# Initial Contributors:
|
sl@0
|
10 |
# Nokia Corporation - initial contribution.
|
sl@0
|
11 |
#
|
sl@0
|
12 |
# Contributors:
|
sl@0
|
13 |
#
|
sl@0
|
14 |
# Description:
|
sl@0
|
15 |
# Created by Relja Arandjelovic
|
sl@0
|
16 |
# relja.arandjelovic@symbian.com
|
sl@0
|
17 |
# Used to check for occurrences of "C: , EDriveC and [<index>]='C' and report warnings about it into HTML file
|
sl@0
|
18 |
# USAGE:
|
sl@0
|
19 |
# cdrive.pl -exclude=exclude.txt -excludedir=/common/generic/security/caf2/ -log=logfilename.htm path1 path2 ...
|
sl@0
|
20 |
# log is created in $ENV{EPOCROOT}epoc32\\winscw\\c\\
|
sl@0
|
21 |
# add -mytest option if the log should be stored in the execution directory
|
sl@0
|
22 |
# (for example, if you are not using the script during overnight builds)
|
sl@0
|
23 |
# exclude contains items formated as as follows (new line corresponds to new line in file):
|
sl@0
|
24 |
# filename
|
sl@0
|
25 |
# line content
|
sl@0
|
26 |
# comment about why the warning should be excluded (may be in several lines, but with no line with only whice characters)
|
sl@0
|
27 |
# line with only white characters
|
sl@0
|
28 |
# NB: paths in cdrive.pl argumetns and filename in exclude list should be absolute paths
|
sl@0
|
29 |
#
|
sl@0
|
30 |
|
sl@0
|
31 |
use strict;
|
sl@0
|
32 |
use Getopt::Std;
|
sl@0
|
33 |
use Getopt::Long;
|
sl@0
|
34 |
use File::Find;
|
sl@0
|
35 |
|
sl@0
|
36 |
my @ListOfFiles=();
|
sl@0
|
37 |
my @FileIsTest=();
|
sl@0
|
38 |
my $nTests=0;
|
sl@0
|
39 |
my %Exclude=();
|
sl@0
|
40 |
|
sl@0
|
41 |
my $exclude="";
|
sl@0
|
42 |
my $excludedir="_no_dir_";
|
sl@0
|
43 |
my $LogFileName="";
|
sl@0
|
44 |
|
sl@0
|
45 |
|
sl@0
|
46 |
|
sl@0
|
47 |
################
|
sl@0
|
48 |
########
|
sl@0
|
49 |
sub TypeOfWarning($$$$){
|
sl@0
|
50 |
my ($FileName,$FileIsTest,$linetext,$Warning)=@_;
|
sl@0
|
51 |
|
sl@0
|
52 |
$linetext=~ s/^\s*//; $linetext=~ s/\s*$//;
|
sl@0
|
53 |
|
sl@0
|
54 |
$$Warning="warning";
|
sl@0
|
55 |
|
sl@0
|
56 |
if ($FileIsTest==1){
|
sl@0
|
57 |
$$Warning="test";
|
sl@0
|
58 |
} else {
|
sl@0
|
59 |
# check if in include list
|
sl@0
|
60 |
|
sl@0
|
61 |
my $ExcludeLine;
|
sl@0
|
62 |
foreach $ExcludeLine (@{$Exclude{$FileName}}){
|
sl@0
|
63 |
if ($linetext eq $ExcludeLine) {
|
sl@0
|
64 |
$$Warning="ignoredwarning";
|
sl@0
|
65 |
last;
|
sl@0
|
66 |
}
|
sl@0
|
67 |
}
|
sl@0
|
68 |
}
|
sl@0
|
69 |
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
|
sl@0
|
73 |
|
sl@0
|
74 |
################
|
sl@0
|
75 |
########
|
sl@0
|
76 |
|
sl@0
|
77 |
|
sl@0
|
78 |
my $FirstWarning=1;
|
sl@0
|
79 |
my $PrevFileName="_no_file_";
|
sl@0
|
80 |
|
sl@0
|
81 |
sub printHTML($$$$){
|
sl@0
|
82 |
my ($FileName,$linenumber,$linetext,$Warning)=@_;
|
sl@0
|
83 |
|
sl@0
|
84 |
|
sl@0
|
85 |
$linetext=~ s/^\s*//; $linetext=~ s/\s*$//;
|
sl@0
|
86 |
|
sl@0
|
87 |
# convert special characters to HTML format
|
sl@0
|
88 |
$linetext=~ s/&/&/sg;
|
sl@0
|
89 |
$linetext=~ s/</</sg;
|
sl@0
|
90 |
$linetext=~ s/>/>/sg;
|
sl@0
|
91 |
|
sl@0
|
92 |
|
sl@0
|
93 |
if ($FileName ne $PrevFileName){
|
sl@0
|
94 |
print HTML "
|
sl@0
|
95 |
<tr><td colspan=\"4\" height=\"20\"> </td></tr>
|
sl@0
|
96 |
<tr><td width=\"20\"></td><td colspan=\"3\">
|
sl@0
|
97 |
$FileName
|
sl@0
|
98 |
</td></tr>
|
sl@0
|
99 |
";
|
sl@0
|
100 |
}
|
sl@0
|
101 |
|
sl@0
|
102 |
print HTML "
|
sl@0
|
103 |
<tr><td colspan=\"4\" height=\"10\"> </td></tr>
|
sl@0
|
104 |
<tr class=\"$Warning\"><td width=\"20\"></td><td width=\"60\"></td><td colspan=\"2\">
|
sl@0
|
105 |
Line number: $linenumber
|
sl@0
|
106 |
</td></tr>
|
sl@0
|
107 |
<tr class=\"$Warning\"><td width=\"20\"></td><td width=\"60\"></td><td width=\"80\"></td><td>
|
sl@0
|
108 |
$linetext
|
sl@0
|
109 |
</td></tr>
|
sl@0
|
110 |
";
|
sl@0
|
111 |
|
sl@0
|
112 |
$PrevFileName=$FileName;
|
sl@0
|
113 |
$FirstWarning=0;
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
################
|
sl@0
|
117 |
########
|
sl@0
|
118 |
my $prevDir="_no_previous_dir_";
|
sl@0
|
119 |
my $isTest=0;
|
sl@0
|
120 |
|
sl@0
|
121 |
sub MakeList(){
|
sl@0
|
122 |
|
sl@0
|
123 |
|
sl@0
|
124 |
if (lc($File::Find::dir) =~ /^$excludedir/) { return; }
|
sl@0
|
125 |
if (lc($File::Find::dir) =~ /test/i) { return; }
|
sl@0
|
126 |
if (lc($File::Find::dir) =~ /examples/i) { return; }
|
sl@0
|
127 |
if (lc($File::Find::dir) =~ /tpkcs10/i) { return; }
|
sl@0
|
128 |
if (lc($File::Find::dir) =~ /tocsp/i) { return; }
|
sl@0
|
129 |
if (lc($File::Find::dir) =~ /referencedrmagent/i) { return; }
|
sl@0
|
130 |
if (lc($File::Find::dir) =~ /dumpswicertstoretool/i) { return; }
|
sl@0
|
131 |
if (!(lc($File::Find::name) =~ /\.(cpp|cxx|c\+\+|c|h)$/)){ return; }
|
sl@0
|
132 |
|
sl@0
|
133 |
# include in list of files to be searched only if not test code
|
sl@0
|
134 |
# ie distribution policy doesn't include Reference/Test
|
sl@0
|
135 |
if ($prevDir ne lc($File::Find::dir)){ # new dir => search for distribution.policy
|
sl@0
|
136 |
$isTest=0;
|
sl@0
|
137 |
my $policy="".($File::Find::dir)."/distribution.policy";
|
sl@0
|
138 |
|
sl@0
|
139 |
if (-e $policy){
|
sl@0
|
140 |
open (POLICY , "<$policy" );
|
sl@0
|
141 |
while (<POLICY>){
|
sl@0
|
142 |
if ($_ =~ /Reference\/Test/){
|
sl@0
|
143 |
$isTest=1;
|
sl@0
|
144 |
last;
|
sl@0
|
145 |
}
|
sl@0
|
146 |
}
|
sl@0
|
147 |
close (POLICY);
|
sl@0
|
148 |
}
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
push(@ListOfFiles,lc($File::Find::name));
|
sl@0
|
152 |
push(@FileIsTest,$isTest);
|
sl@0
|
153 |
if ($isTest) { $nTests++; }
|
sl@0
|
154 |
|
sl@0
|
155 |
$prevDir=lc($File::Find::dir);
|
sl@0
|
156 |
}
|
sl@0
|
157 |
|
sl@0
|
158 |
################
|
sl@0
|
159 |
########
|
sl@0
|
160 |
sub FindC($$$$){
|
sl@0
|
161 |
my ($FileName,$FileIsTest,$count,$countunique)=@_;
|
sl@0
|
162 |
|
sl@0
|
163 |
open(SOURCE,"<$FileName") or die ("Could not open file: $FileName");
|
sl@0
|
164 |
|
sl@0
|
165 |
my $prevCount=$$count;
|
sl@0
|
166 |
my $line; my $templine; my $linenumber=1;
|
sl@0
|
167 |
my $MultiLineComment=0;
|
sl@0
|
168 |
my $MadeChangeDueToComments;
|
sl@0
|
169 |
my $FirstLine=0;
|
sl@0
|
170 |
|
sl@0
|
171 |
my $HTMLFirstWarning=1;
|
sl@0
|
172 |
|
sl@0
|
173 |
while ($line=<SOURCE>){
|
sl@0
|
174 |
|
sl@0
|
175 |
$templine=$line;
|
sl@0
|
176 |
$linenumber++;
|
sl@0
|
177 |
$FirstLine=0;
|
sl@0
|
178 |
|
sl@0
|
179 |
# process comments
|
sl@0
|
180 |
do {
|
sl@0
|
181 |
|
sl@0
|
182 |
$MadeChangeDueToComments=0;
|
sl@0
|
183 |
|
sl@0
|
184 |
if ($MultiLineComment==0){
|
sl@0
|
185 |
|
sl@0
|
186 |
# remove text in // coments
|
sl@0
|
187 |
$templine=~ s/(.*?)\/\/.*$/$1/;
|
sl@0
|
188 |
# remove /* */ comments found in one line
|
sl@0
|
189 |
$templine=~ s/\/\*.*\*\///g;
|
sl@0
|
190 |
|
sl@0
|
191 |
# if only /* then remove text after it and mark the start of comment
|
sl@0
|
192 |
if ($templine=~ /^(.*?)\/\*/){
|
sl@0
|
193 |
$templine=$1;
|
sl@0
|
194 |
$MultiLineComment=1;
|
sl@0
|
195 |
$MadeChangeDueToComments=1;
|
sl@0
|
196 |
$FirstLine=1;
|
sl@0
|
197 |
}
|
sl@0
|
198 |
|
sl@0
|
199 |
} else { # $MultiLineComment==1
|
sl@0
|
200 |
|
sl@0
|
201 |
# if */ end comment
|
sl@0
|
202 |
if ($templine=~ /\*\/(.*)$/){
|
sl@0
|
203 |
$templine=$1;
|
sl@0
|
204 |
$MultiLineComment=0;
|
sl@0
|
205 |
$MadeChangeDueToComments=1;
|
sl@0
|
206 |
}
|
sl@0
|
207 |
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
} while ($MadeChangeDueToComments==1);
|
sl@0
|
211 |
# end of processing comments
|
sl@0
|
212 |
|
sl@0
|
213 |
|
sl@0
|
214 |
if ($MultiLineComment==1 && $FirstLine==0) { next; } # skip checking if in comment
|
sl@0
|
215 |
|
sl@0
|
216 |
|
sl@0
|
217 |
if (
|
sl@0
|
218 |
$templine=~ /["'][cC]:/ || # '" # need comment for correct highlighting in codewarrior
|
sl@0
|
219 |
$templine=~ /EDriveC/ ||
|
sl@0
|
220 |
$templine=~ /\[.+\]\s*=\s*'[cC]':/
|
sl@0
|
221 |
){
|
sl@0
|
222 |
|
sl@0
|
223 |
my $Warning;
|
sl@0
|
224 |
TypeOfWarning($FileName,$FileIsTest,$line,\$Warning);
|
sl@0
|
225 |
printHTML($FileName,$linenumber,$line,$Warning);
|
sl@0
|
226 |
if ($Warning eq "warning") { $$count++; }
|
sl@0
|
227 |
|
sl@0
|
228 |
}
|
sl@0
|
229 |
|
sl@0
|
230 |
}
|
sl@0
|
231 |
|
sl@0
|
232 |
close(SOURCE);
|
sl@0
|
233 |
|
sl@0
|
234 |
if ($prevCount<$$count) { $$countunique++; }
|
sl@0
|
235 |
}
|
sl@0
|
236 |
|
sl@0
|
237 |
################
|
sl@0
|
238 |
########
|
sl@0
|
239 |
sub ReadExcludeList(){
|
sl@0
|
240 |
|
sl@0
|
241 |
#print "\n";
|
sl@0
|
242 |
|
sl@0
|
243 |
|
sl@0
|
244 |
if ($exclude eq ""){
|
sl@0
|
245 |
#print "Exclude list file not specified\nCarrying on without an exclude list\n";
|
sl@0
|
246 |
return;
|
sl@0
|
247 |
} elsif (!(-e $exclude)){
|
sl@0
|
248 |
#print "Exclude list file doesn't exist!\nCarrying on without an exclude list\n";
|
sl@0
|
249 |
return;
|
sl@0
|
250 |
}
|
sl@0
|
251 |
|
sl@0
|
252 |
|
sl@0
|
253 |
my $line; my $FileName; my $LineText; my $justification;
|
sl@0
|
254 |
|
sl@0
|
255 |
open (EXCLUDE,"<$exclude");
|
sl@0
|
256 |
while (1){
|
sl@0
|
257 |
|
sl@0
|
258 |
$line=<EXCLUDE> or last;
|
sl@0
|
259 |
$line=~ s/^(\s*)//g; $line=~ s/(\s*)$//g;
|
sl@0
|
260 |
$line=~ s/\\/\//g;
|
sl@0
|
261 |
$FileName=lc($line);
|
sl@0
|
262 |
|
sl@0
|
263 |
$line=<EXCLUDE>; $line=~ s/^(\s*)//g; $line=~ s/(\s*)$//g;
|
sl@0
|
264 |
$LineText=$line;
|
sl@0
|
265 |
|
sl@0
|
266 |
$justification=0;
|
sl@0
|
267 |
while($line=<EXCLUDE>){
|
sl@0
|
268 |
$line=~ s/^(\s*)//g; $line=~ s/(\s*)$//g;
|
sl@0
|
269 |
if ($line eq "") { last;}
|
sl@0
|
270 |
$justification=1;
|
sl@0
|
271 |
}
|
sl@0
|
272 |
|
sl@0
|
273 |
if ($justification==0){
|
sl@0
|
274 |
#print "Not added to the excludion list since no justification found for:\n$FileName\n$LineText\n";
|
sl@0
|
275 |
} else {
|
sl@0
|
276 |
push(@{$Exclude{$FileName}},$LineText);
|
sl@0
|
277 |
}
|
sl@0
|
278 |
|
sl@0
|
279 |
}
|
sl@0
|
280 |
close(EXCLUDE);
|
sl@0
|
281 |
|
sl@0
|
282 |
}
|
sl@0
|
283 |
|
sl@0
|
284 |
################
|
sl@0
|
285 |
######## Main
|
sl@0
|
286 |
|
sl@0
|
287 |
|
sl@0
|
288 |
my $MyTest=0;
|
sl@0
|
289 |
|
sl@0
|
290 |
GetOptions(
|
sl@0
|
291 |
"exclude=s" => \$exclude ,
|
sl@0
|
292 |
"excludedir=s" => \$excludedir, # one dir to be excluded from scaning (along wih its subdirs)
|
sl@0
|
293 |
"log=s" => \$LogFileName,
|
sl@0
|
294 |
"mytest" => \$MyTest # inteded for my personal testing (so that path is not the one for overnight testing)
|
sl@0
|
295 |
);
|
sl@0
|
296 |
|
sl@0
|
297 |
$excludedir=~ s/\\/\//g; # convert \ into / so that it matches perl's path form
|
sl@0
|
298 |
|
sl@0
|
299 |
ReadExcludeList();
|
sl@0
|
300 |
|
sl@0
|
301 |
|
sl@0
|
302 |
if ($MyTest==0){ # overnight
|
sl@0
|
303 |
$LogFileName = "$ENV{EPOCROOT}epoc32\\winscw\\c\\".$LogFileName;
|
sl@0
|
304 |
}
|
sl@0
|
305 |
|
sl@0
|
306 |
|
sl@0
|
307 |
my $iArgv;
|
sl@0
|
308 |
for ($iArgv=0;$iArgv<@ARGV;$iArgv++){
|
sl@0
|
309 |
$ARGV[$iArgv]=~ s/\\/\//g; # convert \ into / so that it matches perl's path form
|
sl@0
|
310 |
find(\&MakeList, ($ARGV[$iArgv]) );
|
sl@0
|
311 |
}
|
sl@0
|
312 |
|
sl@0
|
313 |
|
sl@0
|
314 |
open(HTML,">$LogFileName");
|
sl@0
|
315 |
print HTML "
|
sl@0
|
316 |
<html>
|
sl@0
|
317 |
|
sl@0
|
318 |
<head>
|
sl@0
|
319 |
<title>CDrive warnings</title>
|
sl@0
|
320 |
|
sl@0
|
321 |
<style type=\'text/css\'>
|
sl@0
|
322 |
.warning {
|
sl@0
|
323 |
background-color: #FFAAAA;
|
sl@0
|
324 |
}
|
sl@0
|
325 |
.ignoredwarning {
|
sl@0
|
326 |
background-color: #90ffff;
|
sl@0
|
327 |
}
|
sl@0
|
328 |
.test{
|
sl@0
|
329 |
background-color: #ffc060;
|
sl@0
|
330 |
}
|
sl@0
|
331 |
</style>
|
sl@0
|
332 |
</head>
|
sl@0
|
333 |
<body>
|
sl@0
|
334 |
<table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\">
|
sl@0
|
335 |
";
|
sl@0
|
336 |
|
sl@0
|
337 |
|
sl@0
|
338 |
my $count=0; my $countunique=0;
|
sl@0
|
339 |
my $iList; my $nList=@ListOfFiles;
|
sl@0
|
340 |
for ($iList=0;$iList<$nList;$iList++){
|
sl@0
|
341 |
FindC($ListOfFiles[$iList],$FileIsTest[$iList],\$count,\$countunique);
|
sl@0
|
342 |
}
|
sl@0
|
343 |
|
sl@0
|
344 |
|
sl@0
|
345 |
print HTML "\n</table>\n";
|
sl@0
|
346 |
|
sl@0
|
347 |
my $total=$nList-$nTests;
|
sl@0
|
348 |
# workaround in order to be reported to the standardised system
|
sl@0
|
349 |
print HTML "<br><center>$countunique tests failed out of $total\n</center>\n";
|
sl@0
|
350 |
|
sl@0
|
351 |
print HTML "
|
sl@0
|
352 |
</body>
|
sl@0
|
353 |
</html>
|
sl@0
|
354 |
";
|
sl@0
|
355 |
|
sl@0
|
356 |
#print "\n\tNumber of files:\t$nList\n";
|
sl@0
|
357 |
#print "\n\tNumber of warnings:\t$count\n";
|
sl@0
|
358 |
#print "\n\tNumber of unique warnings:\t$countunique\n";
|
sl@0
|
359 |
|
sl@0
|
360 |
close(HTML);
|
sl@0
|
361 |
|
sl@0
|
362 |
################
|
sl@0
|
363 |
######## end-Main
|
sl@0
|
364 |
|