diff options
author | Robert Yang <liezhi.yang@windriver.com> | 2018-11-14 17:46:37 +0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-11-19 17:03:25 +0000 |
commit | c1f46c5064460707500a76a01ec3dc95e3d26667 (patch) | |
tree | 5eae7c7d4ea549a7ee929074014642a14026a5f4 | |
parent | 3de56327b2a50d89399223de5404b3419c2ad309 (diff) | |
download | poky-c1f46c5064460707500a76a01ec3dc95e3d26667.tar.gz |
bitbake: parse/ast: fix line number for anonymous function
Fixed:
- Define an error anonymous function in base.bbclass:
15
16 python() {
17 Compile error
18 }
$ bitbake -p
ERROR: Error in compiling python function in /buildarea1/lyang1/poky/meta/classes/base.bbclass, line 18:
The code lines resulting in this error were:
0001:def __anon_18__buildarea1_lyang1_poky_meta_classes_base_bbclass(d):
*** 0002: Compile error
0003:
SyntaxError: invalid syntax (base.bbclass, line 18)
The lineno should be 17, but it reported 18, this would mislead people a lot
when there more lines.
- Now fix it to:
ERROR: Error in compiling python function in /buildarea1/lyang1/poky/meta/classes/base.bbclass, line 17:
The code lines resulting in this error were:
0001:def __anon_18__buildarea1_lyang1_poky_meta_classes_base_bbclass(d):
*** 0002: Compile error
0003:
SyntaxError: invalid syntax (base.bbclass, line 17)
This is because the anonymous function is constructed by:
text = "def %s(d):\n" % (funcname) + text
The len(self.body) doesn't include the "def " line, the length of the function
should be "len(self.body) + 1", so we need pass "self.lineno - (len(self.body) + 1)"
which is the same as 'self.lineno - len(self.body) - 1' to
bb.methodpool.insert_method() as we already had done to named function. Otherwise, the
lineno is wrong, and would cause other problems such as report which line is
wrong, but the line is not what we want since it reports incorrect line.
(Bitbake rev: 7466c8765fcc792e5ea3daefda3c5895e782d6c4)
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | bitbake/lib/bb/parse/ast.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py index 9d20c323fe..6d7c80b34f 100644 --- a/bitbake/lib/bb/parse/ast.py +++ b/bitbake/lib/bb/parse/ast.py | |||
@@ -178,7 +178,7 @@ class MethodNode(AstNode): | |||
178 | funcname = ("__anon_%s_%s" % (self.lineno, self.filename.translate(MethodNode.tr_tbl))) | 178 | funcname = ("__anon_%s_%s" % (self.lineno, self.filename.translate(MethodNode.tr_tbl))) |
179 | self.python = True | 179 | self.python = True |
180 | text = "def %s(d):\n" % (funcname) + text | 180 | text = "def %s(d):\n" % (funcname) + text |
181 | bb.methodpool.insert_method(funcname, text, self.filename, self.lineno - len(self.body)) | 181 | bb.methodpool.insert_method(funcname, text, self.filename, self.lineno - len(self.body) - 1) |
182 | anonfuncs = data.getVar('__BBANONFUNCS', False) or [] | 182 | anonfuncs = data.getVar('__BBANONFUNCS', False) or [] |
183 | anonfuncs.append(funcname) | 183 | anonfuncs.append(funcname) |
184 | data.setVar('__BBANONFUNCS', anonfuncs) | 184 | data.setVar('__BBANONFUNCS', anonfuncs) |