author | Daniel Jacobs <daniel.jacobs@nokia.com> |
Thu, 10 Dec 2009 16:31:46 +0000 | |
branch | wip |
changeset 75 | 000ba5e4ba7d |
parent 71 | ba3ff6a1ecab |
child 107 | bc8e1b2568a4 |
permissions | -rw-r--r-- |
3 | 1 |
# |
2 |
# Copyright (c) 2008-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 |
# Filter class for filtering XML logs and generating reports |
|
16 |
# Prints errors and warnings to stdout |
|
17 |
# |
|
18 |
||
19 |
import sys |
|
20 |
import raptor |
|
21 |
import filter_interface |
|
22 |
import generic_path |
|
23 |
import os |
|
24 |
import os.path |
|
25 |
import re |
|
26 |
||
27 |
class Recipe(object): |
|
28 |
"""State machine that parses a recipe |
|
29 |
""" |
|
30 |
||
31 |
suppress = [] |
|
32 |
warningRE = re.compile("^.*((Warning:)|(MAKEDEF WARNING:)) .*$", re.DOTALL | re.M | re.I) |
|
33 |
infoRE = None |
|
34 |
name = [ "default" ] |
|
35 |
recipes = [] |
|
36 |
||
37 |
def __init__(self, text): |
|
38 |
self.suppress = self.__class__.suppress |
|
39 |
self.text = text |
|
40 |
self.warningRE = Recipe.warningRE |
|
41 |
||
42 |
def warnings(self): |
|
43 |
return self.warningRE.findall(self.text) |
|
44 |
||
45 |
def info(self): |
|
46 |
if self.infoRE: |
|
47 |
return self.infoRE.findall(self.text) |
|
48 |
else: |
|
49 |
return [] |
|
50 |
||
51 |
@classmethod |
|
52 |
def factory(cls, name, text): |
|
53 |
for r in Recipe.recipes: |
|
54 |
if name in r.name: |
|
55 |
return r(text) |
|
56 |
return Recipe(text) |
|
57 |
||
58 |
||
59 |
class MwLinkerRecipe(Recipe): |
|
60 |
suppress = [ |
|
61 |
re.compile( |
|
62 |
r"^mwldsym2: warning: Cannot locate library \"MSL_All_Static_MSE_Symbian\" specified in #pragma comment\(lib,...\)$" |
|
63 |
r"[\n\r]*mwldsym2: warning: referenced from.*$" |
|
64 |
r"[\n\r]*mwldsym2: warning: Option 'Use default libraries' is enabled but linker used.*$" |
|
65 |
r"[\n\r]*mwldsym2: warning: runtime library from MW\[...\]LibraryFiles \(msl_all_static_mse_symbian_d.lib\);$" |
|
66 |
r"[\n\r]*mwldsym2: warning: this indicates a potential settings/libraries mismatch.*$" |
|
67 |
, re.M) |
|
68 |
, re.compile( |
|
69 |
r"^mwldsym2.exe: warning: Multiply defined symbol: ___get_MSL_init_count in.*$" |
|
70 |
r"[\n\r]*mwldsym2.exe: warning: files uc_cwhelp.obj \(.*\), startup.win32.c.obj \(msl_all_static_mse_symbian_d.lib\),.*$" |
|
71 |
r"[\n\r]*mwldsym2.exe: warning: keeping definition in startup.win32.c.obj.*$" |
|
72 |
, re.M ) |
|
73 |
, re.compile( |
|
74 |
r"^mwldsym2.exe: warning: Option 'Use default libraries' is enabled but linker used.*$" |
|
75 |
r"[\n\r]*mwldsym2.exe: warning: runtime library from MW\[...\]LibraryFiles \(msl_all_static_mse_symbian_d.lib\);.*$" |
|
76 |
r"[\n\r]*mwldsym2.exe: warning: this indicates a potential settings/libraries mismatch.*$" |
|
77 |
, re.M) |
|
78 |
] |
|
79 |
name = [ "win32stagetwolink", "win32simplelink" ] |
|
80 |
||
81 |
def warnings(self): |
|
82 |
edited = self.text |
|
83 |
for s in MwLinkerRecipe.suppress: |
|
84 |
edited = s.sub("", edited) |
|
85 |
return Recipe.warningRE.findall(edited) |
|
86 |
||
87 |
Recipe.recipes.append(MwLinkerRecipe) |
|
88 |
||
89 |
||
90 |
class FreezeRecipe(Recipe): |
|
91 |
name = [ "freeze" ] |
|
92 |
warningRE = re.compile("^(WARNING:) .*$", re.DOTALL | re.M | re.I) |
|
93 |
infoRE = re.compile("^(EFREEZE:) .*$", re.DOTALL | re.M | re.I) |
|
94 |
||
95 |
def __init__(self, text): |
|
96 |
Recipe.__init__(self, text) |
|
97 |
self.warningRE = FreezeRecipe.warningRE |
|
98 |
self.infoRE = FreezeRecipe.infoRE |
|
99 |
||
100 |
Recipe.recipes.append(FreezeRecipe) |
|
101 |
||
102 |
||
103 |
||
104 |
class FilterTerminal(filter_interface.Filter): |
|
105 |
||
106 |
attribute_re = re.compile("([a-z][a-z0-9]*)='([^']*)'",re.I) |
|
107 |
maxdots = 40 # if one prints dots then don't print masses |
|
108 |
recipelinelimit = 200 # don't scan ultra-long recipes in case we run out of memory |
|
109 |
||
110 |
# recipes that we think most users are interested in |
|
111 |
# and the mapping that we will use to output them as |
|
112 |
docare = { |
|
113 |
"asmcompile" : "asmcompile" , |
|
114 |
"compile" : "compile" , |
|
115 |
"postlink" : "target", |
|
75
000ba5e4ba7d
Application of review comments.
Daniel Jacobs <daniel.jacobs@nokia.com>
parents:
71
diff
changeset
|
116 |
"linkandpostlink" : "target", |
3 | 117 |
"resourcecompile" : "resource", |
118 |
"genstringtable" : "strtable", |
|
119 |
"tem" : "tem", |
|
120 |
"bitmapcompile" : "bitmap", |
|
121 |
"bitmapcopy" : "bitmapcopy", |
|
122 |
"win32compile2object" : "compile", |
|
123 |
"win32stagetwolink" : "target", |
|
124 |
"win32simplelink" : "target", |
|
125 |
"tools2install" : "target", |
|
126 |
"compile2object" : "compile", |
|
127 |
"msvctoolsinstall" : "target", |
|
128 |
"msvctoolscompile" : "compile", |
|
129 |
"freeze" : "freeze", |
|
130 |
"win32archive" : "target" |
|
131 |
} |
|
132 |
||
133 |
# Determine the width of the largest mapped recipe name |
|
134 |
recipewidth = 0 |
|
135 |
for i in docare: |
|
136 |
l = len(docare[i]) |
|
137 |
if l > recipewidth: |
|
138 |
recipewidth = l # justification for printing out recipes. |
|
139 |
recipewidth+=1 |
|
140 |
||
141 |
def __init__(self): |
|
142 |
self.analyseonly = False |
|
143 |
self.quiet = False |
|
144 |
# defaults can use EPOCROOT |
|
145 |
if "EPOCROOT" in os.environ: |
|
146 |
self.epocroot = str(generic_path.Path(os.environ["EPOCROOT"])) |
|
147 |
else: |
|
148 |
self.epocroot = str(generic_path.Path('/')) |
|
149 |
self.current_recipe_logged = False |
|
150 |
self.cleaned = 0 # cleaned files |
|
151 |
self.dotcount = 0 # progress dots printed so far |
|
152 |
# list of strings to catch make errors (must be lowercase) |
|
153 |
self.make_error_expr = set([ |
|
154 |
"error:", |
|
155 |
": ***", |
|
156 |
"make: interrupt/exception caught (code =", |
|
157 |
"make.exe: interrupt/exception caught (code =" |
|
158 |
]) |
|
159 |
# list of strings to catch make warnings (must be lowercase) |
|
160 |
self.make_warning_expr = ["warning:"] |
|
161 |
||
162 |
# list of strings to catch recipe warnings (must be lowercase) |
|
163 |
self.recipe_warning_expr = ["warning:"] |
|
164 |
||
165 |
def isMakeWarning(self, text): |
|
166 |
"""A simple test for warnings. |
|
167 |
Can be extended do to more comprehensive checking.""" |
|
168 |
# generic warnings checked |
|
169 |
# array of make_warning_expr holds all the possible values |
|
170 |
for warn in self.make_warning_expr: |
|
171 |
if warn in text.lower(): |
|
172 |
return True |
|
173 |
||
174 |
return False |
|
175 |
||
176 |
||
177 |
def isMakeError(self, text): |
|
178 |
"""A simple test for errors. |
|
179 |
Can be extended to do more comprehensive checking.""" |
|
180 |
||
181 |
# make, emake and pvmgmake spit out things like |
|
182 |
# make: *** No rule to make target X, needed by Y. Stop. |
|
183 |
# |
|
184 |
# array of make_error_expr holds all the possible values |
|
185 |
for err in self.make_error_expr: |
|
186 |
if err in text.lower(): |
|
187 |
return True |
|
188 |
||
189 |
return False |
|
190 |
||
191 |
||
192 |
def open(self, raptor_instance): |
|
193 |
"""Set output to stdout for the various I/O methods to write to.""" |
|
194 |
self.raptor = raptor_instance |
|
195 |
||
196 |
# Be totally silent? |
|
197 |
if self.raptor.logFileName is None: |
|
198 |
self.analyseonly = True |
|
199 |
||
200 |
# Only print errors and warnings? |
|
201 |
if self.raptor.quiet: |
|
202 |
self.quiet = True |
|
203 |
||
204 |
# keep count of errors and warnings |
|
205 |
self.err_count = 0 |
|
206 |
self.warn_count = 0 |
|
207 |
self.suppressed_warn_count = 0 |
|
208 |
self.inBody = False |
|
209 |
self.inRecipe = False |
|
210 |
return True |
|
211 |
||
212 |
def write(self, text): |
|
213 |
"""Write errors and warnings to stdout""" |
|
214 |
||
215 |
if text.startswith("<error"): |
|
216 |
start = text.find(">") |
|
217 |
end = text.rfind("<") |
|
218 |
self.err_count += 1 |
|
219 |
if not self.analyseonly: |
|
220 |
sys.stderr.write(str(raptor.name) + ": error: %s\n" \ |
|
221 |
% text[(start + 1):end]) |
|
222 |
elif text.startswith("<warning"): |
|
223 |
start = text.find(">") |
|
224 |
end = text.rfind("<") |
|
225 |
self.warn_count += 1 |
|
226 |
if not self.analyseonly: |
|
227 |
sys.stdout.write(str(raptor.name) + ": warning: %s\n" \ |
|
228 |
% text[(start + 1):end]) |
|
229 |
elif text.startswith("<status "): |
|
230 |
# detect the status report from a recipe |
|
231 |
if text.find('failed') != -1: |
|
232 |
self.failed = True |
|
233 |
else: |
|
234 |
self.failed = False |
|
235 |
return |
|
236 |
elif text.startswith("<recipe "): |
|
237 |
# detect the start of a recipe |
|
238 |
if self.inRecipe: |
|
239 |
sys.stdout.flush() |
|
240 |
sys.stderr.write(self.formatError("Opening recipe tag found " \ |
|
241 |
+ "before closing recipe tag for previous recipe:\n" \ |
|
242 |
+ "Discarding previous recipe (Possible logfile " \ |
|
243 |
+ "corruption)")) |
|
244 |
sys.stderr.flush() |
|
245 |
self.inRecipe = True |
|
246 |
self.current_recipe_logged = False |
|
247 |
m = FilterTerminal.attribute_re.findall(text) |
|
248 |
self.recipe_dict = dict () |
|
249 |
for i in m: |
|
250 |
self.recipe_dict[i[0]] = i[1] |
|
251 |
||
252 |
# Decide what to tell the user about this recipe |
|
253 |
# The target file or the source file? |
|
254 |
name = None |
|
255 |
if 'source' in self.recipe_dict: |
|
256 |
name = self.recipe_dict['source'] |
|
257 |
||
258 |
name_to_user = "" |
|
259 |
# Make source files relative to the current directory if they are |
|
260 |
# not generated files in epocroot. Also make sure path is in |
|
261 |
# the appropriate format for the user's shell. |
|
262 |
if name and (name.find("epoc32") == -1 or name.endswith('.UID.CPP')): |
|
263 |
for i in name.rsplit(): |
|
264 |
name_to_user += " " + generic_path.Path(i).From(generic_path.CurrentDir()).GetShellPath() |
|
265 |
else: |
|
266 |
# using the target. Shorten it if it's in epocroot by just chopping off |
|
267 |
# epocroot |
|
268 |
name_to_user = self.recipe_dict['target'] |
|
269 |
if name_to_user.find(self.epocroot) != -1: |
|
270 |
name_to_user = name_to_user.replace(self.epocroot,"") |
|
271 |
if name_to_user.startswith('/') or name_to_user.startswith('\\'): |
|
272 |
name_to_user = name_to_user[1:] |
|
273 |
name_to_user = generic_path.Path(name_to_user).GetShellPath() |
|
274 |
self.recipe_dict['name_to_user'] = name_to_user |
|
275 |
self.recipe_dict['mappedname'] = self.recipe_dict['name'] |
|
276 |
||
277 |
# Status message to indicate that we are building |
|
278 |
recipename = self.recipe_dict['name'] |
|
279 |
if recipename in FilterTerminal.docare: |
|
280 |
self.recipe_dict['mappedname'] = FilterTerminal.docare[recipename] |
|
281 |
self.logit_if() |
|
282 |
||
283 |
# This variable holds all recipe information |
|
284 |
self.failed = False # Recipe status |
|
285 |
self.recipeBody = [] |
|
286 |
return |
|
287 |
elif text.startswith("</recipe>"): |
|
288 |
# detect the end of a recipe |
|
289 |
if not self.inRecipe: |
|
290 |
sys.stdout.flush() |
|
291 |
sys.stderr.write(self.formatError("Closing recipe tag found " \ |
|
292 |
+ "before opening recipe tag:\nUnable to print " \ |
|
293 |
+ "recipe data (Possible logfile corruption)")) |
|
294 |
sys.stderr.flush() |
|
295 |
else: |
|
296 |
self.inRecipe = False |
|
297 |
||
298 |
if self.failed == True: |
|
299 |
if not self.analyseonly: |
|
300 |
sys.stderr.write("\n FAILED %s for %s: %s\n" % \ |
|
301 |
(self.recipe_dict['name'], |
|
302 |
self.recipe_dict['config'], |
|
303 |
self.recipe_dict['name_to_user'])) |
|
304 |
||
305 |
mmppath = generic_path.Path(self.recipe_dict['mmp']).From(generic_path.CurrentDir()).GetShellPath() |
|
306 |
sys.stderr.write(" mmp: %s\n" % mmppath) |
|
307 |
for L in self.recipeBody: |
|
308 |
if not L.startswith('+'): |
|
309 |
sys.stdout.write(" %s\n" % L.rstrip()) |
|
310 |
self.err_count += 1 |
|
311 |
else: |
|
312 |
r = Recipe.factory(self.recipe_dict['name'], "".join(self.recipeBody)) |
|
313 |
warnings = r.warnings() |
|
314 |
info = r.info() |
|
315 |
if len(warnings) > 0: |
|
316 |
if not self.analyseonly: |
|
317 |
for L in self.recipeBody: |
|
318 |
if not L.startswith('+'): |
|
319 |
sys.stdout.write(" %s\n" % L.rstrip()) |
|
320 |
self.warn_count += len(warnings) |
|
321 |
||
322 |
self.recipeBody = [] |
|
323 |
return |
|
324 |
elif not self.inRecipe and self.isMakeError(text): |
|
325 |
# these two statements pick up errors coming from make |
|
326 |
self.err_count += 1 |
|
327 |
sys.stderr.write(" %s\n" % text.rstrip()) |
|
328 |
return |
|
329 |
elif not self.inRecipe and self.isMakeWarning(text): |
|
330 |
self.warn_count += 1 |
|
331 |
sys.stdout.write(" %s\n" % text.rstrip()) |
|
332 |
return |
|
333 |
elif text.startswith("<![CDATA["): |
|
334 |
# save CDATA body during a recipe |
|
335 |
if self.inRecipe: |
|
336 |
self.inBody = True |
|
337 |
elif text.startswith("]]>"): |
|
338 |
if self.inRecipe: |
|
339 |
self.inBody = False |
|
340 |
elif text.startswith("<info>Copied"): |
|
341 |
if not self.analyseonly and not self.quiet: |
|
342 |
start = text.find(" to ") + 4 |
|
343 |
end = text.find("</info>",start) |
|
344 |
short_target = text[start:end] |
|
345 |
if short_target.startswith(self.epocroot): |
|
346 |
short_target = short_target.replace(self.epocroot,"")[1:] |
|
347 |
short_target = generic_path.Path(short_target).GetShellPath() |
|
348 |
sys.stdout.write(" %s: %s\n" % ("export".ljust(FilterTerminal.recipewidth), short_target)) |
|
349 |
return |
|
350 |
elif text.find("<rm files") != -1 or text.find("<rmdir ") != -1: |
|
351 |
# search for cleaning output but only if we |
|
352 |
# are not in some recipe (that would be pointless) |
|
353 |
if not self.analyseonly and not self.quiet: |
|
354 |
if self.cleaned == 0: |
|
355 |
sys.stdout.write("\ncleaning ") |
|
356 |
self.cleaned+=1 |
|
357 |
elif self.dotcount < FilterTerminal.maxdots: |
|
358 |
if self.cleaned % 5 == 0: |
|
359 |
self.dotcount+=1 |
|
360 |
sys.stdout.write(".") |
|
361 |
self.cleaned+=1 |
|
362 |
||
363 |
return |
|
364 |
elif self.inBody: |
|
365 |
# We are parsing the output from a recipe |
|
366 |
# we have to keep the output until we find out |
|
367 |
# if the recipe failed. But not all of it if it turns |
|
368 |
# out to be very long |
|
369 |
if len(self.recipeBody) < FilterTerminal.recipelinelimit: |
|
370 |
self.recipeBody.append(text) |
|
371 |
||
372 |
def logit(self): |
|
373 |
""" log a message """ |
|
374 |
info = self.recipe_dict['mappedname'].ljust(FilterTerminal.recipewidth) |
|
375 |
config = self.recipe_dict['config'] |
|
376 |
name = self.recipe_dict['name_to_user'].lstrip() |
|
377 |
# If its a multifile config, we print source files one below the other in a single |
|
378 |
# 'compile:' statement |
|
379 |
if config.endswith('multifile'): |
|
380 |
files = self.recipe_dict['name_to_user'].split() |
|
381 |
name = "" |
|
382 |
for i in files: |
|
383 |
if i == files[0]: |
|
384 |
name += i |
|
385 |
else: |
|
386 |
name += '\n\t ' + i |
|
387 |
sys.stdout.write(" %s: %s \t[%s]\n" % (info, name, config)) |
|
388 |
||
389 |
def logit_if(self): |
|
390 |
""" Tell the user about the recipe that we are processing """ |
|
391 |
if not self.analyseonly and not self.quiet: |
|
392 |
if self.inRecipe and not self.current_recipe_logged: |
|
393 |
self.logit() |
|
394 |
self.current_recipe_logged = True |
|
395 |
||
396 |
def summary(self): |
|
397 |
"""Errors and warnings summary""" |
|
398 |
||
399 |
if self.raptor.skipAll or self.analyseonly: |
|
400 |
return |
|
401 |
||
402 |
||
403 |
if self.cleaned != 0: |
|
404 |
sys.stdout.write("\n\n") |
|
405 |
||
406 |
if self.warn_count > 0 or self.err_count > 0: |
|
407 |
sys.stdout.write("\n%s : warnings: %s\n" % (raptor.name, |
|
408 |
self.warn_count)) |
|
409 |
sys.stdout.write("%s : errors: %s\n" % (raptor.name, |
|
410 |
self.err_count)) |
|
411 |
else: |
|
412 |
sys.stdout.write("\nno warnings or errors\n") |
|
413 |
||
414 |
sys.stdout.write("\nRun time %d seconds\n" % self.raptor.runtime); |
|
415 |
sys.stdout.write("\n") |
|
416 |
return True |
|
417 |
||
418 |
def close(self): |
|
419 |
"""Tell raptor that there were errors.""" |
|
420 |
if self.err_count > 0: |
|
421 |
return False |
|
422 |
return True |
|
423 |