summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r--bitbake/lib/bb/utils.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 31ec2b7c9a..c5ff903cef 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -33,6 +33,7 @@ import fnmatch
33import traceback 33import traceback
34import errno 34import errno
35import signal 35import signal
36import ast
36from commands import getstatusoutput 37from commands import getstatusoutput
37from contextlib import contextmanager 38from contextlib import contextmanager
38from ctypes import cdll 39from ctypes import cdll
@@ -291,19 +292,22 @@ def _print_trace(body, line):
291 error.append(' %.4d:%s' % (i, body[i-1].rstrip())) 292 error.append(' %.4d:%s' % (i, body[i-1].rstrip()))
292 return error 293 return error
293 294
294def better_compile(text, file, realfile, mode = "exec"): 295def better_compile(text, file, realfile, mode = "exec", lineno = None):
295 """ 296 """
296 A better compile method. This method 297 A better compile method. This method
297 will print the offending lines. 298 will print the offending lines.
298 """ 299 """
299 try: 300 try:
300 return compile(text, file, mode) 301 code = compile(text, realfile, mode, ast.PyCF_ONLY_AST)
302 if lineno is not None:
303 ast.increment_lineno(code, lineno)
304 return compile(code, realfile, mode)
301 except Exception as e: 305 except Exception as e:
302 error = [] 306 error = []
303 # split the text into lines again 307 # split the text into lines again
304 body = text.split('\n') 308 body = text.split('\n')
305 error.append("Error in compiling python function in %s:\n" % realfile) 309 error.append("Error in compiling python function in %s, line %s:\n" % (realfile, lineno))
306 if e.lineno: 310 if hasattr(e, "lineno"):
307 error.append("The code lines resulting in this error were:") 311 error.append("The code lines resulting in this error were:")
308 error.extend(_print_trace(body, e.lineno)) 312 error.extend(_print_trace(body, e.lineno))
309 else: 313 else: