<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">&lt;<a href="mailto:richard.purdie@linuxfoundation.org" target="_blank">richard.purdie@linuxfoundation.org</a>&gt;</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&#39;t need to double compile.<br>
<br>
Signed-off-by: Richard Purdie &lt;<a href="mailto:richard.purdie@linuxfoundation.org">richard.purdie@linuxfoundation.org</a>&gt;<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(&#39;     %.4d:%s&#39; % (i, body[i-1].rstrip()))<br>
     return error<br>
<br>
-def better_compile(text, file, realfile, mode = &quot;exec&quot;, lineno = None):<br>
+def better_compile(text, file, realfile, mode = &quot;exec&quot;, lineno = 0):<br>
     &quot;&quot;&quot;<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 = &quot;exec&quot;, 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&#39;t add to the linenumbers for compile, we can pad to the correct number of blank lines though<br>
+        text2 = &quot;\n&quot; * 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&#39;s your concern. Afaik that&#39;s the usual case which ast.increment_lineno isn&#39;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>