author | MattD <mattd@symbian.org> |
Wed, 24 Mar 2010 16:42:06 +0000 | |
branch | DBRToolsDev |
changeset 219 | fa4867282f20 |
parent 187 | ec83a06d23a8 |
child 215 | a403724f631c |
permissions | -rw-r--r-- |
177 | 1 |
# Copyright (c) 2009 Symbian Foundation Ltd |
2 |
# This component and the accompanying materials are made available |
|
3 |
# under the terms of the License "Eclipse Public License v1.0" |
|
4 |
# which accompanies this distribution, and is available |
|
5 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
6 |
# |
|
7 |
# Initial Contributors: |
|
8 |
# Symbian Foundation Ltd - initial contribution. |
|
9 |
# |
|
10 |
# Contributors: |
|
11 |
# |
|
12 |
# Description: |
|
13 |
# Unite and HTML-ize Raptor log files |
|
14 |
||
15 |
use strict; |
|
16 |
use FindBin; |
|
17 |
use lib $FindBin::Bin; |
|
18 |
use RaptorError; |
|
19 |
use RaptorWarning; |
|
20 |
use RaptorInfo; |
|
21 |
use RaptorUnreciped; |
|
22 |
use RaptorRecipe; |
|
23 |
||
24 |
use XML::SAX; |
|
25 |
use RaptorSAXHandler; |
|
26 |
use Getopt::Long; |
|
27 |
||
187
ec83a06d23a8
HTML escape failures so that they can be viewed correctly
Dario Sestito <darios@symbian.org>
parents:
186
diff
changeset
|
28 |
use CGI; |
ec83a06d23a8
HTML escape failures so that they can be viewed correctly
Dario Sestito <darios@symbian.org>
parents:
186
diff
changeset
|
29 |
|
177 | 30 |
our $raptorbitsdir = 'raptorbits'; |
31 |
our $basedir = ''; |
|
32 |
my $outputdir = "html"; |
|
33 |
our $raptor_config = 'dummy_config'; |
|
34 |
our $current_log_file = ''; |
|
35 |
my $help = 0; |
|
36 |
GetOptions(( |
|
37 |
'basedir=s' => \$basedir, |
|
38 |
'help!' => \$help |
|
39 |
)); |
|
40 |
my @logfiles = @ARGV; |
|
41 |
||
42 |
$help = 1 if (!@logfiles); |
|
43 |
||
44 |
if ($help) |
|
45 |
{ |
|
46 |
print "Unite and HTML-ize Raptor log files.\n"; |
|
47 |
print "Usage: perl uh.pl [OPTIONS] FILE1 FILE2 ...\n"; |
|
48 |
print "where OPTIONS are:\n"; |
|
49 |
print "\t--basedir=DIR Generate output under DIR (defaults to current dir)\n"; |
|
50 |
exit(0); |
|
51 |
} |
|
52 |
||
53 |
if ($basedir) |
|
54 |
{ |
|
55 |
$raptorbitsdir = "$basedir/raptorbits"; |
|
56 |
$outputdir = "$basedir/html"; |
|
57 |
} |
|
58 |
mkdir($basedir) if (!-d$basedir); |
|
59 |
||
60 |
$raptorbitsdir =~ s,/,\\,g; # this is because rmdir doens't cope correctly with the forward slashes |
|
61 |
||
62 |
system("rmdir /S /Q $raptorbitsdir") if (-d $raptorbitsdir); |
|
63 |
mkdir($raptorbitsdir); |
|
64 |
#print "Created dir $raptorbitsdir.\n"; |
|
65 |
||
186
b76adfbc6648
Don't dump failures which aren't reported
Dario Sestito <darios@symbian.org>
parents:
177
diff
changeset
|
66 |
our $failure_item_number = 0; |
b76adfbc6648
Don't dump failures which aren't reported
Dario Sestito <darios@symbian.org>
parents:
177
diff
changeset
|
67 |
|
177 | 68 |
# create empty summary file anyway |
69 |
open(SUMMARY, ">$raptorbitsdir/summary.csv"); |
|
70 |
close(SUMMARY); |
|
71 |
||
72 |
my $saxhandler = RaptorSAXHandler->new(); |
|
73 |
$saxhandler->add_observer('RaptorError', $RaptorError::reset_status); |
|
74 |
$saxhandler->add_observer('RaptorWarning', $RaptorWarning::reset_status); |
|
75 |
$saxhandler->add_observer('RaptorInfo', $RaptorInfo::reset_status); |
|
76 |
$saxhandler->add_observer('RaptorUnreciped', $RaptorUnreciped::reset_status); |
|
77 |
$saxhandler->add_observer('RaptorRecipe', $RaptorRecipe::reset_status); |
|
78 |
||
79 |
our $allbldinfs = {}; |
|
80 |
||
81 |
my $parser = XML::SAX::ParserFactory->parser(Handler=>$saxhandler); |
|
82 |
for (@logfiles) |
|
83 |
{ |
|
84 |
print "Reading file: $_\n"; |
|
85 |
$current_log_file = $_; |
|
86 |
$parser->parse_uri($_); |
|
87 |
} |
|
88 |
||
89 |
my @allpackages = distinct_packages($allbldinfs); |
|
90 |
||
91 |
print "Generating HTML...\n"; |
|
92 |
||
93 |
system("rd /S /Q $outputdir") if (-d $outputdir); |
|
94 |
mkdir ($outputdir); |
|
95 |
||
96 |
my $raptor_errors = {}; |
|
97 |
my $raptor_warnings = {}; |
|
98 |
my $raptor_unreciped = {}; |
|
99 |
my $general_failures_num_by_severity = {}; |
|
100 |
my $general_failures_by_category_severity = {}; |
|
101 |
my $recipe_failures_num_by_severity = {}; |
|
102 |
my $recipe_failures_by_package_severity = {}; |
|
103 |
#my $severities = {}; |
|
104 |
my @severities = ('critical', 'major', 'minor', 'unknown'); |
|
105 |
||
106 |
# READ SUMMARY.CSV FILE |
|
107 |
my $csv_file = "$raptorbitsdir/summary.csv"; |
|
108 |
my $csv_linenum = 0; |
|
109 |
open(CSV, $csv_file); |
|
110 |
while(<CSV>) |
|
111 |
{ |
|
112 |
$csv_linenum ++; |
|
113 |
my $line = $_; |
|
114 |
||
115 |
if ($line =~ /([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*),([^,]*)/) |
|
116 |
{ |
|
117 |
my $failure = {}; |
|
118 |
$failure->{category} = $1; |
|
119 |
$failure->{subcategory} = $2; |
|
120 |
$failure->{severity} = $3; |
|
121 |
$failure->{config} = $4; |
|
122 |
$failure->{component} = $5; |
|
123 |
$failure->{mmp} = $6; |
|
124 |
$failure->{phase} = $7; |
|
125 |
$failure->{recipe} = $8; |
|
126 |
$failure->{file} = $9; |
|
127 |
$failure->{linenum} = $10; |
|
128 |
||
129 |
my $failure_package = ''; |
|
130 |
||
131 |
if (!$failure->{category}) |
|
132 |
{ |
|
133 |
print "WARNING: summary line without a category at $csv_file line $csv_linenum. Skipping\n"; |
|
134 |
next; |
|
135 |
} |
|
136 |
||
137 |
if ($failure->{category} =~ m,^recipe_failure$,i and !$failure->{component}) |
|
138 |
{ |
|
139 |
print "WARNING: recipe_failure with component field empty at $csv_file line $csv_linenum. Skipping\n"; |
|
140 |
next; |
|
141 |
} |
|
142 |
if ($failure->{component}) |
|
143 |
{ |
|
144 |
if ($failure->{component} =~ m,/((os|mw|app|tools|ostools|adaptation)/[^/]*),) |
|
145 |
{ |
|
146 |
$failure_package = $1; |
|
147 |
} |
|
148 |
else |
|
149 |
{ |
|
150 |
print "WARNING: summary line with wrong component path at $csv_file line $csv_linenum. Skipping\n"; |
|
151 |
next; |
|
152 |
} |
|
153 |
} |
|
154 |
||
155 |
$failure->{subcategory} = 'uncategorized' if (!$failure->{subcategory}); |
|
156 |
$failure->{severity} = 'unknown' if (!$failure->{severity}); |
|
157 |
$failure->{mmp} = '-' if (!$failure->{mmp}); |
|
158 |
||
159 |
# populate severities dynamically. |
|
160 |
#$severities->{$failure->{severity}} = 1; |
|
161 |
||
162 |
# put failure items into their category container |
|
163 |
if ($failure->{category} =~ /^raptor_(error|warning|unreciped)$/i) |
|
164 |
{ |
|
165 |
$general_failures_num_by_severity->{$failure->{category}} = {} if (!defined $general_failures_num_by_severity->{$failure->{category}}); |
|
166 |
my $general_failure = $general_failures_num_by_severity->{$failure->{category}}; |
|
167 |
||
168 |
if (!defined $general_failure->{$failure->{severity}}) |
|
169 |
{ |
|
170 |
$general_failure->{$failure->{severity}} = 1; |
|
171 |
} |
|
172 |
else |
|
173 |
{ |
|
174 |
$general_failure->{$failure->{severity}} ++; |
|
175 |
} |
|
176 |
||
177 |
$general_failures_by_category_severity->{$failure->{category}} = {} if (!defined $general_failures_by_category_severity->{$failure->{category}}); |
|
178 |
$general_failures_by_category_severity->{$failure->{category}}->{$failure->{severity}} = [] if (!defined $general_failures_by_category_severity->{$failure->{category}}->{$failure->{severity}}); |
|
179 |
push(@{$general_failures_by_category_severity->{$failure->{category}}->{$failure->{severity}}}, $failure); |
|
180 |
} |
|
181 |
elsif ($failure->{category} =~ /^recipe_failure$/i) |
|
182 |
{ |
|
183 |
$recipe_failures_num_by_severity->{$failure_package} = {} if (!defined $recipe_failures_num_by_severity->{$failure_package}); |
|
184 |
my $package_failure = $recipe_failures_num_by_severity->{$failure_package}; |
|
185 |
||
186 |
if (!defined $package_failure->{$failure->{severity}}) |
|
187 |
{ |
|
188 |
$package_failure->{$failure->{severity}} = 1; |
|
189 |
} |
|
190 |
else |
|
191 |
{ |
|
192 |
$package_failure->{$failure->{severity}} ++; |
|
193 |
} |
|
194 |
||
195 |
$recipe_failures_by_package_severity->{$failure_package} = {} if (!defined $recipe_failures_by_package_severity->{$failure_package}); |
|
196 |
$recipe_failures_by_package_severity->{$failure_package}->{$failure->{severity}} = [] if (!defined $recipe_failures_by_package_severity->{$failure_package}->{$failure->{severity}}); |
|
197 |
push(@{$recipe_failures_by_package_severity->{$failure_package}->{$failure->{severity}}}, $failure); |
|
198 |
} |
|
199 |
} |
|
200 |
else |
|
201 |
{ |
|
202 |
print "WARNING: line does not match expected format at $csv_file line $csv_linenum. Skipping\n"; |
|
203 |
} |
|
204 |
} |
|
205 |
close(CSV); |
|
206 |
||
207 |
# PRINT HTML SUMMARY |
|
208 |
my $aggregated_html = "$outputdir/index.html"; |
|
209 |
open(AGGREGATED, ">$aggregated_html"); |
|
210 |
print AGGREGATED "RAPTOR BUILD SUMMARY<br/>\n"; |
|
211 |
||
212 |
print AGGREGATED "<br/>GENERAL FAILURES<br/>\n"; |
|
213 |
print AGGREGATED "<table border='1'>\n"; |
|
214 |
my $tableheader = "<tr><th>category</th>"; |
|
215 |
for (@severities) { $tableheader .= "<th>$_</th>"; } |
|
216 |
$tableheader .= "</tr>"; |
|
217 |
print AGGREGATED "$tableheader\n"; |
|
218 |
for my $category (keys %{$general_failures_num_by_severity}) |
|
219 |
{ |
|
220 |
print_category_specific_summary($category, $general_failures_by_category_severity->{$category}); |
|
221 |
my $categoryline = "<tr><td><a href='$category.html'>$category</a></td>"; |
|
222 |
for (@severities) |
|
223 |
{ |
|
224 |
my $failuresbyseverity = 0; |
|
225 |
$failuresbyseverity = $general_failures_num_by_severity->{$category}->{$_} if (defined $general_failures_num_by_severity->{$category}->{$_}); |
|
226 |
$categoryline .= "<td>$failuresbyseverity</td>"; |
|
227 |
} |
|
228 |
$categoryline .= "</tr>"; |
|
229 |
print AGGREGATED "$categoryline\n"; |
|
230 |
} |
|
231 |
print AGGREGATED "</table>\n"; |
|
232 |
print AGGREGATED "<br/>\n"; |
|
233 |
||
234 |
print AGGREGATED "<br/>PACKAGE-SPECIFIC FAILURES<br/>\n"; |
|
235 |
print AGGREGATED "<table border='1'>\n"; |
|
236 |
$tableheader = "<tr><th>package</th>"; |
|
237 |
for (@severities) { $tableheader .= "<th>$_</th>"; } |
|
238 |
$tableheader .= "</tr>"; |
|
239 |
print AGGREGATED "$tableheader\n"; |
|
240 |
for my $package (@allpackages) |
|
241 |
{ |
|
242 |
if (defined $recipe_failures_num_by_severity->{$package}) |
|
243 |
{ |
|
244 |
print_package_specific_summary($package, $recipe_failures_by_package_severity->{$package}); |
|
245 |
my $packagesummaryhtml = $package; |
|
246 |
$packagesummaryhtml =~ s,/,_,; |
|
247 |
$packagesummaryhtml .= ".html"; |
|
248 |
my $packageline = "<tr><td><a href='$packagesummaryhtml'>$package</a></td>"; |
|
249 |
for (@severities) |
|
250 |
{ |
|
251 |
my $failuresbyseverity = 0; |
|
252 |
$failuresbyseverity = $recipe_failures_num_by_severity->{$package}->{$_} if (defined $recipe_failures_num_by_severity->{$package}->{$_}); |
|
253 |
$packageline .= "<td>$failuresbyseverity</td>"; |
|
254 |
} |
|
255 |
$packageline .= "</tr>"; |
|
256 |
print AGGREGATED "$packageline\n"; |
|
257 |
} |
|
258 |
else |
|
259 |
{ |
|
260 |
my $packageline = "<tr><td>$package</td>"; |
|
261 |
for (@severities) { $packageline .= "<td>0</td>"; } |
|
262 |
$packageline .= "</tr>"; |
|
263 |
print AGGREGATED "$packageline\n"; |
|
264 |
} |
|
265 |
} |
|
266 |
print AGGREGATED "</table>\n"; |
|
267 |
close(AGGREGATED); |
|
268 |
||
269 |
translate_detail_files_to_html(); |
|
270 |
||
271 |
print "OK, done. Please open $outputdir/index.html.\n"; |
|
272 |
||
273 |
||
274 |
sub print_category_specific_summary |
|
275 |
{ |
|
276 |
my ($category, $failures_by_severity) = @_; |
|
277 |
||
278 |
my $filenamebase = $category; |
|
279 |
$filenamebase =~ s,/,_,; |
|
280 |
||
281 |
open(SPECIFIC, ">$outputdir/$filenamebase.html"); |
|
282 |
print SPECIFIC "FAILURES FOR CATEGORY $category<br/>\n"; |
|
283 |
||
284 |
for my $severity (@severities) |
|
285 |
{ |
|
286 |
if (defined $failures_by_severity->{$severity}) |
|
287 |
{ |
|
288 |
print SPECIFIC "<br/>".uc($severity)."<br/>\n"; |
|
289 |
print SPECIFIC "<table border='1'>\n"; |
|
290 |
# $subcategory, $severity, $mmp, $phase, $recipe, $file, $line |
|
291 |
my $tableheader = "<tr><th>category</th><th>log file</th><th>log snippet</th></tr>"; |
|
292 |
print SPECIFIC "$tableheader\n"; |
|
293 |
||
294 |
for my $failure (@{$failures_by_severity->{$severity}}) |
|
295 |
{ |
|
296 |
my $failureline = "<tr><td>$failure->{subcategory}</td>"; |
|
297 |
$failureline .= "<td>$failure->{config}</td>"; |
|
298 |
$failureline .= "<td><a href='$filenamebase\_failures.html#failure_item_$failure->{linenum}'>item $failure->{linenum}</a></td>"; |
|
299 |
$failureline .= "</tr>"; |
|
300 |
print SPECIFIC "$failureline\n"; |
|
301 |
} |
|
302 |
||
303 |
print SPECIFIC "</table>\n"; |
|
304 |
print SPECIFIC "<br/>\n"; |
|
305 |
} |
|
306 |
} |
|
307 |
||
308 |
close(SPECIFIC); |
|
309 |
} |
|
310 |
||
311 |
sub print_package_specific_summary |
|
312 |
{ |
|
313 |
my ($package, $failures_by_severity) = @_; |
|
314 |
||
315 |
my $filenamebase = $package; |
|
316 |
$filenamebase =~ s,/,_,; |
|
317 |
||
318 |
open(SPECIFIC, ">$outputdir/$filenamebase.html"); |
|
319 |
print SPECIFIC "FAILURES FOR PACKAGE $package<br/>\n"; |
|
320 |
||
321 |
for my $severity (@severities) |
|
322 |
{ |
|
323 |
if (defined $failures_by_severity->{$severity}) |
|
324 |
{ |
|
325 |
print SPECIFIC "<br/>".uc($severity)."<br/>\n"; |
|
326 |
print SPECIFIC "<table border='1'>\n"; |
|
327 |
# $subcategory, $severity, $mmp, $phase, $recipe, $file, $line |
|
328 |
my $tableheader = "<tr><th>category</th><th>configuration</th><th>mmp</th><th>phase</th><th>recipe</th><th>log snippet</th></tr>"; |
|
329 |
print SPECIFIC "$tableheader\n"; |
|
330 |
||
331 |
for my $failure (@{$failures_by_severity->{$severity}}) |
|
332 |
{ |
|
333 |
my $failureline = "<tr><td>$failure->{subcategory}</td>"; |
|
334 |
$failureline .= "<td>$failure->{config}</td>"; |
|
335 |
$failureline .= "<td>$failure->{mmp}</td>"; |
|
336 |
$failureline .= "<td>$failure->{phase}</td>"; |
|
337 |
$failureline .= "<td>$failure->{recipe}</td>"; |
|
338 |
$failureline .= "<td><a href='$filenamebase\_failures.html#failure_item_$failure->{linenum}'>item $failure->{linenum}</a></td>"; |
|
339 |
$failureline .= "</tr>"; |
|
340 |
print SPECIFIC "$failureline\n"; |
|
341 |
} |
|
342 |
||
343 |
print SPECIFIC "</table>\n"; |
|
344 |
print SPECIFIC "<br/>\n"; |
|
345 |
} |
|
346 |
} |
|
347 |
||
348 |
close(SPECIFIC); |
|
349 |
} |
|
350 |
||
351 |
sub translate_detail_files_to_html |
|
352 |
{ |
|
353 |
opendir(DIR, $raptorbitsdir); |
|
354 |
my @failurefiles = readdir(DIR); |
|
355 |
closedir(DIR); |
|
356 |
@failurefiles = grep(/\.txt$/, @failurefiles); |
|
357 |
||
358 |
for my $file (@failurefiles) |
|
359 |
{ |
|
360 |
$file =~ /(.*)\.txt$/; |
|
361 |
my $filenamebase = $1; |
|
362 |
||
363 |
my $filecontent = ''; |
|
364 |
open(FILE, "$raptorbitsdir/$file"); |
|
365 |
{ |
|
366 |
local $/=undef; |
|
367 |
$filecontent = <FILE>; |
|
368 |
} |
|
369 |
close(FILE); |
|
370 |
||
187
ec83a06d23a8
HTML escape failures so that they can be viewed correctly
Dario Sestito <darios@symbian.org>
parents:
186
diff
changeset
|
371 |
$filecontent = CGI::escapeHTML($filecontent); |
177 | 372 |
$filecontent =~ s,---(failure_item_\d+)---,<a name="$1">---$1---</a>,g; |
373 |
$filecontent = "<pre>$filecontent</pre>"; |
|
374 |
||
375 |
open(FILE, ">$outputdir/$filenamebase\_failures.html"); |
|
376 |
print FILE $filecontent; |
|
377 |
close(FILE); |
|
378 |
} |
|
379 |
} |
|
380 |
||
381 |
sub distinct_packages |
|
382 |
{ |
|
383 |
my ($allbldinfs) = @_; |
|
384 |
||
385 |
my $allpackages = {}; |
|
386 |
||
387 |
for my $bldinf (keys %{$allbldinfs}) |
|
388 |
{ |
|
389 |
# normalize bldinf path |
|
390 |
$bldinf = lc($bldinf); |
|
391 |
$bldinf =~ s,^[A-Za-z]:,,; |
|
392 |
$bldinf =~ s,[\\],/,g; |
|
393 |
||
394 |
my $package = ''; |
|
395 |
if ($bldinf =~ m,/((os|mw|app|tools|ostools|adaptation)/[^/]*),) |
|
396 |
{ |
|
397 |
$package = $1; |
|
398 |
} |
|
399 |
else |
|
400 |
{ |
|
401 |
print "WARNING: can't understand bldinf attribute of recipe: $bldinf. Won't dump to failed recipes file.\n"; |
|
402 |
} |
|
403 |
||
404 |
$allpackages->{$package} = 1; |
|
405 |
} |
|
406 |
||
407 |
return sort {$a cmp $b} keys %{$allpackages}; |
|
408 |
} |