summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/build.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2016-02-09 15:08:42 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-02-10 15:47:11 +0000
commit400f53003e430e1a5f7302a0a40ed5afbf80904e (patch)
treeffa605c5694dd348cd48b946b161d9ad8f21b84d /bitbake/lib/bb/build.py
parentaece74876271f692296c5f792104c627e15b5c3e (diff)
downloadpoky-400f53003e430e1a5f7302a0a40ed5afbf80904e.tar.gz
bitbake: build: Improve python execution tracebacks
If something fails in a exec_func_python() the current stack trace shows incorrect filenames and linenumbers. For example: The stack trace of python calls that resulted in this exception/failure was: File: '/media/build1/poky/meta/recipes-sato/images/core-image-sato.bb', lineno: 200, function: <module> 0196: chksum = bb.utils.sha256_file(fn) 0197: f.write('%s\t%s\n' % (chksum, os.path.relpath(fn, baseoutpath))) 0198: 0199: *** 0200:copy_buildsystem(d) 0201: File: '/media/build1/poky/meta/recipes-sato/images/core-image-sato.bb', lineno: 9, function: copy_buildsystem 0005:IMAGE_FEATURES += "splash package-management x11-base x11-sato ssh-server-dropbear hwcodecs" 0006: 0007:LICENSE = "MIT" 0008: *** 0009:inherit core-image 0010: 0011:IMAGE_INSTALL += "packagegroup-core-x11-sato-games" File: '/usr/lib/python2.7/subprocess.py', lineno: 535, function: check_call 0531: The arguments are the same as for the Popen constructor. Example: 0532: 0533: check_call(["ls", "-l"]) 0534: """ *** 0535: retcode = call(*popenargs, **kwargs) 0536: if retcode: 0537: cmd = kwargs.get("args") 0538: if cmd is None: 0539: cmd = popenargs[0] The problem is the use of "FILE" to obtain the current filename. Instead, we therefore inject the function being executed into the methodpool which allows us to correct its linenumber and filename information. We can then clearly mark the initial piece as autogenerated and the rest of the linenumber and filename information should be correct. Afterwards the trace starts: The stack trace of python calls that resulted in this exception/failure was: File: 'exec_python_func() autogenerated', lineno: 2, function: <module> 0001: *** 0002:copy_buildsystem(d) 0003: File: '/media/build1/poky/meta/classes/populate_sdk_ext.bbclass', lineno: 66, function: copy_buildsystem 0062: import glob 0063: import oe.copy_buildsystem 0064: import subprocess 0065: *** 0066: subprocess.check_call("foo") 0067: 0068: oe_init_env_script = d.getVar('OE_INIT_ENV_SCRIPT', True) 0069: 0070: conf_bbpath = '' File: '/usr/lib/python2.7/subprocess.py', lineno: 535, function: check_call 0531: The arguments are the same as for the Popen constructor. Example: 0532: 0533: check_call(["ls", "-l"]) 0534: """ *** 0535: retcode = call(*popenargs, **kwargs) 0536: if retcode: 0537: cmd = kwargs.get("args") 0538: if cmd is None: 0539: cmd = popenargs[0] We can't inject into methodpool at parsing time, since there may be _append or other override operations against the function before its execution. (Bitbake rev: fae153095d23157dd7e72c29f683f86149ee33a8) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/build.py')
-rw-r--r--bitbake/lib/bb/build.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py
index 1cd546a712..d20ee065b2 100644
--- a/bitbake/lib/bb/build.py
+++ b/bitbake/lib/bb/build.py
@@ -229,17 +229,13 @@ def exec_func(func, d, dirs = None):
229 exec_func_shell(func, d, runfile, cwd=adir) 229 exec_func_shell(func, d, runfile, cwd=adir)
230 230
231_functionfmt = """ 231_functionfmt = """
232def {function}(d):
233{body}
234
235{function}(d) 232{function}(d)
236""" 233"""
237logformatter = bb.msg.BBLogFormatter("%(levelname)s: %(message)s") 234logformatter = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
238def exec_func_python(func, d, runfile, cwd=None): 235def exec_func_python(func, d, runfile, cwd=None):
239 """Execute a python BB 'function'""" 236 """Execute a python BB 'function'"""
240 237
241 bbfile = d.getVar('FILE', True) 238 code = _functionfmt.format(function=func)
242 code = _functionfmt.format(function=func, body=d.getVar(func, False))
243 bb.utils.mkdirhier(os.path.dirname(runfile)) 239 bb.utils.mkdirhier(os.path.dirname(runfile))
244 with open(runfile, 'w') as script: 240 with open(runfile, 'w') as script:
245 bb.data.emit_func_python(func, script, d) 241 bb.data.emit_func_python(func, script, d)
@@ -254,8 +250,13 @@ def exec_func_python(func, d, runfile, cwd=None):
254 bb.debug(2, "Executing python function %s" % func) 250 bb.debug(2, "Executing python function %s" % func)
255 251
256 try: 252 try:
257 comp = utils.better_compile(code, func, bbfile) 253 text = "def %s(d):\n%s" % (func, d.getVar(func, False))
258 utils.better_exec(comp, {"d": d}, code, bbfile) 254 fn = d.getVarFlag(func, "filename", False)
255 lineno = int(d.getVarFlag(func, "lineno", False))
256 bb.methodpool.insert_method(func, text, fn, lineno - 1)
257
258 comp = utils.better_compile(code, func, "exec_python_func() autogenerated")
259 utils.better_exec(comp, {"d": d}, code, "exec_python_func() autogenerated")
259 except (bb.parse.SkipRecipe, bb.build.FuncFailed): 260 except (bb.parse.SkipRecipe, bb.build.FuncFailed):
260 raise 261 raise
261 except: 262 except: