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