<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 4, 2016 at 10:34 AM, Richard Purdie <span dir="ltr"><<a href="mailto:richard.purdie@linuxfoundation.org" target="_blank">richard.purdie@linuxfoundation.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div id=":pc" class="" style="overflow:hidden">Poking around the ast to correct linenumbers works well for runtime failures<br>
but not for parsing ones. We can use blank linefeeds to correct the line<br>
numbers instead, with the advantage that we don't need to double compile.<br>
<br>
Signed-off-by: Richard Purdie <<a href="mailto:richard.purdie@linuxfoundation.org">richard.purdie@linuxfoundation.org</a>><br>
<br>
diff --git a/<span class="">bitbake</span>/lib/<span class="">bb</span>/utils.py b/<span class="">bitbake</span>/lib/<span class="">bb</span>/utils.py<br>
index cd5fced..9a3efb2 100644<br>
--- a/<span class="">bitbake</span>/lib/<span class="">bb</span>/utils.py<br>
+++ b/<span class="">bitbake</span>/lib/<span class="">bb</span>/utils.py<br>
@@ -292,7 +292,7 @@ def _print_trace(body, line):<br>
error.append(' %.4d:%s' % (i, body[i-1].rstrip()))<br>
return error<br>
<br>
-def better_compile(text, file, realfile, mode = "exec", lineno = None):<br>
+def better_compile(text, file, realfile, mode = "exec", lineno = 0):<br>
"""<br>
A better compile method. This method<br>
will print the offending lines.<br>
@@ -301,10 +301,9 @@ def better_compile(text, file, realfile, mode = "exec", lineno = None):<br>
cache = <span class="">bb</span>.methodpool.compile_cache(text)<br>
if cache:<br>
return cache<br>
- code = compile(text, realfile, mode, ast.PyCF_ONLY_AST)<br>
- if lineno is not None:<br>
- ast.increment_lineno(code, lineno)<br>
- code = compile(code, realfile, mode)<br>
+ # We can't add to the linenumbers for compile, we can pad to the correct number of blank lines though<br>
+ text2 = "\n" * int(lineno) + text<br>
+ code = compile(text2, realfile, mode)</div></blockquote></div><br></div><div class="gmail_extra">A SyntaxError can have its line numbers adjusted fairly easily, if that's your concern. Afaik that's the usual case which ast.increment_lineno isn't sufficient to handle. See <a href="https://gist.github.com/kergoth/743677#file-compile-py-L67-L86">https://gist.github.com/kergoth/743677#file-compile-py-L67-L86</a>.<br>-- <br><div class="gmail_signature">Christopher Larson<br>clarson at kergoth dot com<br>Founder - BitBake, OpenEmbedded, OpenZaurus<br>Maintainer - Tslib<br>Senior Software Engineer, Mentor Graphics</div>
</div></div>