summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/parse
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/parse
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/parse')
-rw-r--r--bitbake/lib/bb/parse/ast.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py
index 11db1801b3..e1bf82fe90 100644
--- a/bitbake/lib/bb/parse/ast.py
+++ b/bitbake/lib/bb/parse/ast.py
@@ -148,17 +148,19 @@ class MethodNode(AstNode):
148 148
149 def eval(self, data): 149 def eval(self, data):
150 text = '\n'.join(self.body) 150 text = '\n'.join(self.body)
151 funcname = self.func_name
151 if self.func_name == "__anonymous": 152 if self.func_name == "__anonymous":
152 funcname = ("__anon_%s_%s" % (self.lineno, self.filename.translate(MethodNode.tr_tbl))) 153 funcname = ("__anon_%s_%s" % (self.lineno, self.filename.translate(MethodNode.tr_tbl)))
153 text = "def %s(d):\n" % (funcname) + text 154 text = "def %s(d):\n" % (funcname) + text
154 bb.methodpool.insert_method(funcname, text, self.filename) 155 bb.methodpool.insert_method(funcname, text, self.filename, self.lineno - len(self.body))
155 anonfuncs = data.getVar('__BBANONFUNCS', False) or [] 156 anonfuncs = data.getVar('__BBANONFUNCS', False) or []
156 anonfuncs.append(funcname) 157 anonfuncs.append(funcname)
157 data.setVar('__BBANONFUNCS', anonfuncs) 158 data.setVar('__BBANONFUNCS', anonfuncs)
158 data.setVar(funcname, text, parsing=True)
159 else: 159 else:
160 data.setVarFlag(self.func_name, "func", 1) 160 data.setVarFlag(self.func_name, "func", 1)
161 data.setVar(self.func_name, text, parsing=True) 161 data.setVar(funcname, text, parsing=True)
162 data.setVarFlag(funcname, 'filename', self.filename)
163 data.setVarFlag(funcname, 'lineno', str(self.lineno - len(self.body)))
162 164
163class PythonMethodNode(AstNode): 165class PythonMethodNode(AstNode):
164 def __init__(self, filename, lineno, function, modulename, body): 166 def __init__(self, filename, lineno, function, modulename, body):
@@ -172,10 +174,12 @@ class PythonMethodNode(AstNode):
172 # 'this' file. This means we will not parse methods from 174 # 'this' file. This means we will not parse methods from
173 # bb classes twice 175 # bb classes twice
174 text = '\n'.join(self.body) 176 text = '\n'.join(self.body)
175 bb.methodpool.insert_method(self.modulename, text, self.filename) 177 bb.methodpool.insert_method(self.modulename, text, self.filename, self.lineno - len(self.body) - 1)
176 data.setVarFlag(self.function, "func", 1) 178 data.setVarFlag(self.function, "func", 1)
177 data.setVarFlag(self.function, "python", 1) 179 data.setVarFlag(self.function, "python", 1)
178 data.setVar(self.function, text, parsing=True) 180 data.setVar(self.function, text, parsing=True)
181 data.setVarFlag(self.function, 'filename', self.filename)
182 data.setVarFlag(self.function, 'lineno', str(self.lineno - len(self.body) - 1))
179 183
180class MethodFlagsNode(AstNode): 184class MethodFlagsNode(AstNode):
181 def __init__(self, filename, lineno, key, m): 185 def __init__(self, filename, lineno, key, m):
@@ -317,7 +321,9 @@ def finalize(fn, d, variant = None):
317 all_handlers = {} 321 all_handlers = {}
318 for var in d.getVar('__BBHANDLERS', False) or []: 322 for var in d.getVar('__BBHANDLERS', False) or []:
319 # try to add the handler 323 # try to add the handler
320 bb.event.register(var, d.getVar(var, False), (d.getVarFlag(var, "eventmask", True) or "").split()) 324 handlerfn = d.getVarFlag(var, "filename", False)
325 handlerln = int(d.getVarFlag(var, "lineno", False))
326 bb.event.register(var, d.getVar(var, False), (d.getVarFlag(var, "eventmask", True) or "").split(), handlerfn, handlerln)
321 327
322 bb.event.fire(bb.event.RecipePreFinalise(fn), d) 328 bb.event.fire(bb.event.RecipePreFinalise(fn), d)
323 329