summaryrefslogtreecommitdiffstats
path: root/lib/bb
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2006-02-26 11:07:47 +0000
committerHolger Hans Peter Freyther <zecke@selfish.org>2006-02-26 11:07:47 +0000
commit4f807c93f8f72eb73b8600d1f73a3e26014a3167 (patch)
tree7e1d0b5a52c45081238da4c067e9c462a20a7198 /lib/bb
parent7dc97df197bde5dde7fffad737f493b0cb94c576 (diff)
downloadbitbake-4f807c93f8f72eb73b8600d1f73a3e26014a3167.tar.gz
bitbake/parser,build,utils:
We compile strings into code. In case of erros the traceback is not useful at all. It doesn't print the function name, accurate line number etc. Introduce a better_compile method that excepts the Error and prints the surrounding lines of code. We make use of it on the parsing level and execution level of python methods.
Diffstat (limited to 'lib/bb')
-rw-r--r--lib/bb/build.py7
-rw-r--r--lib/bb/parse/parse_py/BBHandler.py4
-rw-r--r--lib/bb/utils.py23
3 files changed, 29 insertions, 5 deletions
diff --git a/lib/bb/build.py b/lib/bb/build.py
index 599b45d9d..5a72be73b 100644
--- a/lib/bb/build.py
+++ b/lib/bb/build.py
@@ -25,7 +25,7 @@ You should have received a copy of the GNU General Public License along with
Based on functions from the base bb module, Copyright 2003 Holger Schurig
"""
-from bb import debug, data, fetch, fatal, error, note, event, mkdirhier
+from bb import debug, data, fetch, fatal, error, note, event, mkdirhier, utils
import bb, os
# data holds flags and function name for a given task
@@ -122,8 +122,9 @@ def exec_func_python(func, d):
"""Execute a python BB 'function'"""
import re, os
- tmp = "def " + func + "():\n%s" % data.getVar(func, d)
- comp = compile(tmp + '\n' + func + '()', bb.data.getVar('FILE', d, 1) + ':' + func, "exec")
+ tmp = "def " + func + "():\n%s" % data.getVar(func, d)
+ tmp += '\n' + func + '()'
+ comp = utils.better_compile(tmp, func, bb.data.getVar('FILE', d, 1) )
prevdir = os.getcwd()
g = {} # globals
g['bb'] = bb
diff --git a/lib/bb/parse/parse_py/BBHandler.py b/lib/bb/parse/parse_py/BBHandler.py
index fac3e85b3..d083bb312 100644
--- a/lib/bb/parse/parse_py/BBHandler.py
+++ b/lib/bb/parse/parse_py/BBHandler.py
@@ -22,7 +22,7 @@
Place, Suite 330, Boston, MA 02111-1307 USA."""
import re, bb, os, sys
-import bb.fetch, bb.build
+import bb.fetch, bb.build, bb.utils
from bb import debug, data, fetch, fatal
from ConfHandler import include, localpath, obtain, init
@@ -206,7 +206,7 @@ def feeder(lineno, s, fn, d):
return
else:
text = '\n'.join(__body__)
- comp = compile(text, "<bb>", "exec")
+ comp = bb.utils.better_compile(text, "<bb>", fn )
exec comp in __builtins__
__body__ = []
__inpython__ = False
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 2f53c65ec..31dc4e372 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -93,3 +93,26 @@ def explode_deps(s):
# Ignore version
#r[-1] += ' ' + ' '.join(j)
return r
+
+
+def better_compile(text, file, realfile):
+ try:
+ return compile(text, file, "exec")
+ except Exception, e:
+ import bb,sys
+
+ # split the text into lines again
+ body = text.split('\n')
+ bb.error("Error in compiling: ", realfile)
+ bb.error("The lines resulting into thiis error were:")
+ bb.error("\t%d:%s:'%s'" % (e.lineno, e.__class__.__name__, body[e.lineno-1]))
+ # print the environment of the method
+ bb.error("Printing the environment of the function")
+ min_line = max(1,e.lineno-4)
+ max_line = min(e.lineno+4,len(body))
+ for i in range(min_line,max_line+1):
+ bb.error("\t%.4d:%s" % (i, body[i-1]) )
+
+ # exit now
+ sys.exit(1)
+