diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-12-15 17:41:12 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-12-18 12:18:19 +0000 |
commit | 0019edc8180e859544da4820fa390b23d975fe08 (patch) | |
tree | 16ea6385b9faae8a718dbe5dcedaacea232e938e /bitbake/lib/bb/utils.py | |
parent | b14ccb2367983b2263608b6d618647ecd22bf00d (diff) | |
download | poky-0019edc8180e859544da4820fa390b23d975fe08.tar.gz |
bitbake: ast/event/utils: Improve tracebacks to include file and line numbers more correctly
Currently bitbake tracebacks can have places where the line numbers are
inaccurate and filenames may be missing. These changes start to try and
correct this.
The only way I could find to correct line numbers was to compile as a
python ast, tweak the line numbers then compile to bytecode. I'm open
to better ways of doing this if anyone knows of any.
This does mean passing a few more parameters into functions, and putting
more data into the data store about functions (i.e. their filenames
and line numbers) but the improvement in debugging is more than worthwhile).
Before:
----------------
ERROR: Execution of event handler 'run_buildstats' failed
Traceback (most recent call last):
File "run_buildstats(e)", line 43, in run_buildstats(e=<bb.build.TaskStarted object at 0x7f7b7c57a590>)
NameError: global name 'notexist' is not defined
ERROR: Build of do_patch failed
ERROR: Traceback (most recent call last):
File "/media/build1/poky/bitbake/lib/bb/build.py", line 560, in exec_task
return _exec_task(fn, task, d, quieterr)
File "/media/build1/poky/bitbake/lib/bb/build.py", line 497, in _exec_task
event.fire(TaskStarted(task, logfn, flags, localdata), localdata)
File "/media/build1/poky/bitbake/lib/bb/event.py", line 170, in fire
fire_class_handlers(event, d)
File "/media/build1/poky/bitbake/lib/bb/event.py", line 109, in fire_class_handlers
execute_handler(name, handler, event, d)
File "/media/build1/poky/bitbake/lib/bb/event.py", line 81, in execute_handler
ret = handler(event)
File "run_buildstats(e)", line 43, in run_buildstats
NameError: global name 'notexist' is not defined
----------------
After:
----------------
ERROR: Execution of event handler 'run_buildstats' failed
Traceback (most recent call last):
File "/media/build1/poky/meta/classes/buildstats.bbclass", line 143, in run_buildstats(e=<bb.build.TaskStarted object at 0x7efe89284e10>):
if isinstance(e, bb.build.TaskStarted):
> trigger = notexist
pn = d.getVar("PN", True)
NameError: global name 'notexist' is not defined
ERROR: Build of do_package failed
ERROR: Traceback (most recent call last):
File "/media/build1/poky/bitbake/lib/bb/build.py", line 560, in exec_task
return _exec_task(fn, task, d, quieterr)
File "/media/build1/poky/bitbake/lib/bb/build.py", line 497, in _exec_task
event.fire(TaskStarted(task, logfn, flags, localdata), localdata)
File "/media/build1/poky/bitbake/lib/bb/event.py", line 170, in fire
fire_class_handlers(event, d)
File "/media/build1/poky/bitbake/lib/bb/event.py", line 109, in fire_class_handlers
execute_handler(name, handler, event, d)
File "/media/build1/poky/bitbake/lib/bb/event.py", line 81, in execute_handler
ret = handler(event)
File "/media/build1/poky/meta/classes/buildstats.bbclass", line 143, in run_buildstats
trigger = notexist
NameError: global name 'notexist' is not defined
----------------
(Bitbake rev: 1ff860960919ff6f8097138bc68de85bcb5f88b0)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r-- | bitbake/lib/bb/utils.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py index 31ec2b7c9a..c5ff903cef 100644 --- a/bitbake/lib/bb/utils.py +++ b/bitbake/lib/bb/utils.py | |||
@@ -33,6 +33,7 @@ import fnmatch | |||
33 | import traceback | 33 | import traceback |
34 | import errno | 34 | import errno |
35 | import signal | 35 | import signal |
36 | import ast | ||
36 | from commands import getstatusoutput | 37 | from commands import getstatusoutput |
37 | from contextlib import contextmanager | 38 | from contextlib import contextmanager |
38 | from ctypes import cdll | 39 | from ctypes import cdll |
@@ -291,19 +292,22 @@ def _print_trace(body, line): | |||
291 | error.append(' %.4d:%s' % (i, body[i-1].rstrip())) | 292 | error.append(' %.4d:%s' % (i, body[i-1].rstrip())) |
292 | return error | 293 | return error |
293 | 294 | ||
294 | def better_compile(text, file, realfile, mode = "exec"): | 295 | def better_compile(text, file, realfile, mode = "exec", lineno = None): |
295 | """ | 296 | """ |
296 | A better compile method. This method | 297 | A better compile method. This method |
297 | will print the offending lines. | 298 | will print the offending lines. |
298 | """ | 299 | """ |
299 | try: | 300 | try: |
300 | return compile(text, file, mode) | 301 | code = compile(text, realfile, mode, ast.PyCF_ONLY_AST) |
302 | if lineno is not None: | ||
303 | ast.increment_lineno(code, lineno) | ||
304 | return compile(code, realfile, mode) | ||
301 | except Exception as e: | 305 | except Exception as e: |
302 | error = [] | 306 | error = [] |
303 | # split the text into lines again | 307 | # split the text into lines again |
304 | body = text.split('\n') | 308 | body = text.split('\n') |
305 | error.append("Error in compiling python function in %s:\n" % realfile) | 309 | error.append("Error in compiling python function in %s, line %s:\n" % (realfile, lineno)) |
306 | if e.lineno: | 310 | if hasattr(e, "lineno"): |
307 | error.append("The code lines resulting in this error were:") | 311 | error.append("The code lines resulting in this error were:") |
308 | error.extend(_print_trace(body, e.lineno)) | 312 | error.extend(_print_trace(body, e.lineno)) |
309 | else: | 313 | else: |