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
"""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
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
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
# 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)
+