summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/event.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2015-12-15 17:41:12 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-12-18 12:18:19 +0000
commit0019edc8180e859544da4820fa390b23d975fe08 (patch)
tree16ea6385b9faae8a718dbe5dcedaacea232e938e /bitbake/lib/bb/event.py
parentb14ccb2367983b2263608b6d618647ecd22bf00d (diff)
downloadpoky-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/event.py')
-rw-r--r--bitbake/lib/bb/event.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py
index ec25ce77fb..bd2b0a4b05 100644
--- a/bitbake/lib/bb/event.py
+++ b/bitbake/lib/bb/event.py
@@ -177,7 +177,7 @@ def fire_from_worker(event, d):
177 fire_ui_handlers(event, d) 177 fire_ui_handlers(event, d)
178 178
179noop = lambda _: None 179noop = lambda _: None
180def register(name, handler, mask=None): 180def register(name, handler, mask=None, filename=None, lineno=None):
181 """Register an Event handler""" 181 """Register an Event handler"""
182 182
183 # already registered 183 # already registered
@@ -189,7 +189,13 @@ def register(name, handler, mask=None):
189 if isinstance(handler, basestring): 189 if isinstance(handler, basestring):
190 tmp = "def %s(e):\n%s" % (name, handler) 190 tmp = "def %s(e):\n%s" % (name, handler)
191 try: 191 try:
192 code = compile(tmp, "%s(e)" % name, "exec") 192 import ast
193 if filename is None:
194 filename = "%s(e)" % name
195 code = compile(tmp, filename, "exec", ast.PyCF_ONLY_AST)
196 if lineno is not None:
197 ast.increment_lineno(code, lineno-1)
198 code = compile(code, filename, "exec")
193 except SyntaxError: 199 except SyntaxError:
194 logger.error("Unable to register event handler '%s':\n%s", name, 200 logger.error("Unable to register event handler '%s':\n%s", name,
195 ''.join(traceback.format_exc(limit=0))) 201 ''.join(traceback.format_exc(limit=0)))