summaryrefslogtreecommitdiffstats
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:55:33 +0000
commit3f415929200c44850b27e70ecafc70c7de4692f4 (patch)
treef56f8ee9b9076e8b6d83b00895848fbb4d46cbfd
parent36dc42bde7d9df305a8ffcef3c6118afd66410af (diff)
downloadpoky-3f415929200c44850b27e70ecafc70c7de4692f4.tar.gz
bitbake: 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 (Bitbake rev: c212933d9c786806852c87f188250a4f0a14c048) Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/bb/event.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py
index f8acacd80d..4761c86880 100644
--- a/bitbake/lib/bb/event.py
+++ b/bitbake/lib/bb/event.py
@@ -257,14 +257,15 @@ def register(name, handler, mask=None, filename=None, lineno=None, data=None):
257 # handle string containing python code 257 # handle string containing python code
258 if isinstance(handler, str): 258 if isinstance(handler, str):
259 tmp = "def %s(e, d):\n%s" % (name, handler) 259 tmp = "def %s(e, d):\n%s" % (name, handler)
260 # Inject empty lines to make code match lineno in filename
261 if lineno is not None:
262 tmp = "\n" * (lineno-1) + tmp
260 try: 263 try:
261 code = bb.methodpool.compile_cache(tmp) 264 code = bb.methodpool.compile_cache(tmp)
262 if not code: 265 if not code:
263 if filename is None: 266 if filename is None:
264 filename = "%s(e, d)" % name 267 filename = "%s(e, d)" % name
265 code = compile(tmp, filename, "exec", ast.PyCF_ONLY_AST) 268 code = compile(tmp, filename, "exec", ast.PyCF_ONLY_AST)
266 if lineno is not None:
267 ast.increment_lineno(code, lineno-1)
268 code = compile(code, filename, "exec") 269 code = compile(code, filename, "exec")
269 bb.methodpool.compile_cache_add(tmp, code) 270 bb.methodpool.compile_cache_add(tmp, code)
270 except SyntaxError: 271 except SyntaxError: