aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2024-01-08 23:45:33 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-01-10 13:54:46 +0000
commitc212933d9c786806852c87f188250a4f0a14c048 (patch)
tree21c3d51d2cc8022c9c240a7f8aa30b9df7ac4189 /lib
parent5b0a48265aafa62259c575707c3afa6dd56f8008 (diff)
downloadbitbake-c212933d9c786806852c87f188250a4f0a14c048.tar.gz
bitbake: event: Inject empty lines to make code match lineno in filename
So that we can get the correct error messages. * In python 3.10.9, the error message was: ERROR: Unable to register event handler 'defaultbase_eventhandler': File "/path/to/poky/meta/classes-global/base.bbclass", line 4 # SPDX-License-Identifier: MIT ^^^^^ SyntaxError: invalid syntax This is hard to debug since the error line number 4 is incorrect, but nothing is wrong with the code in line 4. * Now the error message and lineno is correct: ERROR: Unable to register event handler 'defaultbase_eventhandler': File "/path/to/poky/meta/classes-global/base.bbclass", line 256 an error line ^^^^^ SyntaxError: invalid syntax And no impact on parsing time: * Before: $ rm -fr cache tmp; time bitbake -p real 0m27.254s * Now: $ rm -fr cache tmp; time bitbake -p real 0m27.200s Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/bb/event.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/bb/event.py b/lib/bb/event.py
index f8acacd80..4761c8688 100644
--- a/lib/bb/event.py
+++ b/lib/bb/event.py
@@ -257,14 +257,15 @@ def register(name, handler, mask=None, filename=None, lineno=None, data=None):
# handle string containing python code
if isinstance(handler, str):
tmp = "def %s(e, d):\n%s" % (name, handler)
+ # Inject empty lines to make code match lineno in filename
+ if lineno is not None:
+ tmp = "\n" * (lineno-1) + tmp
try:
code = bb.methodpool.compile_cache(tmp)
if not code:
if filename is None:
filename = "%s(e, d)" % name
code = compile(tmp, filename, "exec", ast.PyCF_ONLY_AST)
- if lineno is not None:
- ast.increment_lineno(code, lineno-1)
code = compile(code, filename, "exec")
bb.methodpool.compile_cache_add(tmp, code)
except SyntaxError: