diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-01-04 17:31:19 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-01-06 15:27:34 +0000 |
commit | 958f0ff56b37a08c905f8f8fdc17353dcad8ef60 (patch) | |
tree | a27c0229c26d665a963b1a337ded58b22894ebcc /bitbake | |
parent | db4376ed64f5d8f828862085a272b3e451a191cb (diff) | |
download | poky-958f0ff56b37a08c905f8f8fdc17353dcad8ef60.tar.gz |
bitbake: codeparser: Add support for correct linenumbers
Currently, if there is something like a python indentation error in a
python function, the linenumbers and even file aren't reported correctly.
This allows lineno and filename parameters to be passed in to correct this.
The lack of a lineno parameter to python's compile() function is worked
around by using empty linefeeds. Ugly, but effective and with minimal
performance overhead.
(Bitbake rev: 5796ed550d127853808f38257f8dcc8c1cf59342)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/codeparser.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/bitbake/lib/bb/codeparser.py b/bitbake/lib/bb/codeparser.py index 6c9a42dc39..577b4271cf 100644 --- a/bitbake/lib/bb/codeparser.py +++ b/bitbake/lib/bb/codeparser.py | |||
@@ -28,6 +28,10 @@ def check_indent(codestr): | |||
28 | return codestr | 28 | return codestr |
29 | 29 | ||
30 | if codestr[i-1] == "\t" or codestr[i-1] == " ": | 30 | if codestr[i-1] == "\t" or codestr[i-1] == " ": |
31 | if codestr[0] == "\n": | ||
32 | # Since we're adding a line, we need to remove one line of any empty padding | ||
33 | # to ensure line numbers are correct | ||
34 | codestr = codestr[1:] | ||
31 | return "if 1:\n" + codestr | 35 | return "if 1:\n" + codestr |
32 | 36 | ||
33 | return codestr | 37 | return codestr |
@@ -248,7 +252,7 @@ class PythonParser(): | |||
248 | self.unhandled_message = "in call of %s, argument '%s' is not a string literal" | 252 | self.unhandled_message = "in call of %s, argument '%s' is not a string literal" |
249 | self.unhandled_message = "while parsing %s, %s" % (name, self.unhandled_message) | 253 | self.unhandled_message = "while parsing %s, %s" % (name, self.unhandled_message) |
250 | 254 | ||
251 | def parse_python(self, node): | 255 | def parse_python(self, node, lineno=0, filename="<string>"): |
252 | if not node or not node.strip(): | 256 | if not node or not node.strip(): |
253 | return | 257 | return |
254 | 258 | ||
@@ -270,7 +274,9 @@ class PythonParser(): | |||
270 | self.contains[i] = set(codeparsercache.pythoncacheextras[h].contains[i]) | 274 | self.contains[i] = set(codeparsercache.pythoncacheextras[h].contains[i]) |
271 | return | 275 | return |
272 | 276 | ||
273 | code = compile(check_indent(str(node)), "<string>", "exec", | 277 | # We can't add to the linenumbers for compile, we can pad to the correct number of blank lines though |
278 | node = "\n" * int(lineno) + node | ||
279 | code = compile(check_indent(str(node)), filename, "exec", | ||
274 | ast.PyCF_ONLY_AST) | 280 | ast.PyCF_ONLY_AST) |
275 | 281 | ||
276 | for n in ast.walk(code): | 282 | for n in ast.walk(code): |