summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb')
-rw-r--r--bitbake/lib/bb/build.py8
-rw-r--r--bitbake/lib/bb/data_smart.py8
-rw-r--r--bitbake/lib/bb/event.py9
-rw-r--r--bitbake/lib/bb/methodpool.py10
-rw-r--r--bitbake/lib/bb/parse/ast.py36
-rw-r--r--bitbake/lib/bb/utils.py18
6 files changed, 36 insertions, 53 deletions
diff --git a/bitbake/lib/bb/build.py b/bitbake/lib/bb/build.py
index 43dbfc1363..16d69281f1 100644
--- a/bitbake/lib/bb/build.py
+++ b/bitbake/lib/bb/build.py
@@ -203,16 +203,14 @@ def exec_func_python(func, d, runfile, logfile):
203 import re, os 203 import re, os
204 204
205 bbfile = bb.data.getVar('FILE', d, 1) 205 bbfile = bb.data.getVar('FILE', d, 1)
206 tmp = "def " + func + "():\n%s" % data.getVar(func, d) 206 tmp = "def " + func + "(d):\n%s" % data.getVar(func, d)
207 tmp += '\n' + func + '()' 207 tmp += '\n' + func + '(d)'
208 208
209 f = open(runfile, "w") 209 f = open(runfile, "w")
210 f.write(tmp) 210 f.write(tmp)
211 comp = utils.better_compile(tmp, func, bbfile) 211 comp = utils.better_compile(tmp, func, bbfile)
212 g = {} # globals
213 g['d'] = d
214 try: 212 try:
215 utils.better_exec(comp, g, tmp, bbfile) 213 utils.better_exec(comp, {"d": d}, tmp, bbfile)
216 except: 214 except:
217 (t,value,tb) = sys.exc_info() 215 (t,value,tb) = sys.exc_info()
218 216
diff --git a/bitbake/lib/bb/data_smart.py b/bitbake/lib/bb/data_smart.py
index 55a6f3143c..77f1861381 100644
--- a/bitbake/lib/bb/data_smart.py
+++ b/bitbake/lib/bb/data_smart.py
@@ -50,12 +50,6 @@ class DataSmart:
50 self._seen_overrides = seen 50 self._seen_overrides = seen
51 51
52 self.expand_cache = {} 52 self.expand_cache = {}
53 self.expand_globals = {
54 "os": os,
55 "bb": bb,
56 "time": time,
57 "d": self
58 }
59 53
60 def expand(self,s, varname): 54 def expand(self,s, varname):
61 def var_sub(match): 55 def var_sub(match):
@@ -72,7 +66,7 @@ class DataSmart:
72 def python_sub(match): 66 def python_sub(match):
73 code = match.group()[3:-1] 67 code = match.group()[3:-1]
74 codeobj = compile(code.strip(), varname or "<expansion>", "eval") 68 codeobj = compile(code.strip(), varname or "<expansion>", "eval")
75 s = eval(codeobj, self.expand_globals, {}) 69 s = utils.better_eval(codeobj, {"d": self})
76 if type(s) == types.IntType: s = str(s) 70 if type(s) == types.IntType: s = str(s)
77 return s 71 return s
78 72
diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py
index afd5bf57c1..8559858f04 100644
--- a/bitbake/lib/bb/event.py
+++ b/bitbake/lib/bb/event.py
@@ -48,13 +48,18 @@ _handlers = {}
48_ui_handlers = {} 48_ui_handlers = {}
49_ui_handler_seq = 0 49_ui_handler_seq = 0
50 50
51# For compatibility
52bb.utils._context["NotHandled"] = NotHandled
53bb.utils._context["Handled"] = Handled
54
51def fire_class_handlers(event, d): 55def fire_class_handlers(event, d):
52 for handler in _handlers: 56 for handler in _handlers:
53 h = _handlers[handler] 57 h = _handlers[handler]
54 event.data = d 58 event.data = d
55 if type(h).__name__ == "code": 59 if type(h).__name__ == "code":
56 exec(h) 60 locals = {"e": event}
57 tmpHandler(event) 61 exec h in bb.utils._context, locals
62 bb.utils.better_eval("tmpHandler(e)", locals)
58 else: 63 else:
59 h(event) 64 h(event)
60 del event.data 65 del event.data
diff --git a/bitbake/lib/bb/methodpool.py b/bitbake/lib/bb/methodpool.py
index f43c4a0580..1485b1357d 100644
--- a/bitbake/lib/bb/methodpool.py
+++ b/bitbake/lib/bb/methodpool.py
@@ -27,7 +27,7 @@
27 a method pool to do this task. 27 a method pool to do this task.
28 28
29 This pool will be used to compile and execute the functions. It 29 This pool will be used to compile and execute the functions. It
30 will be smart enough to 30 will be smart enough to
31""" 31"""
32 32
33from bb.utils import better_compile, better_exec 33from bb.utils import better_compile, better_exec
@@ -43,8 +43,8 @@ def insert_method(modulename, code, fn):
43 Add code of a module should be added. The methods 43 Add code of a module should be added. The methods
44 will be simply added, no checking will be done 44 will be simply added, no checking will be done
45 """ 45 """
46 comp = better_compile(code, "<bb>", fn ) 46 comp = better_compile(code, modulename, fn )
47 better_exec(comp, __builtins__, code, fn) 47 better_exec(comp, None, code, fn)
48 48
49 # now some instrumentation 49 # now some instrumentation
50 code = comp.co_names 50 code = comp.co_names
@@ -59,7 +59,7 @@ def insert_method(modulename, code, fn):
59def check_insert_method(modulename, code, fn): 59def check_insert_method(modulename, code, fn):
60 """ 60 """
61 Add the code if it wasnt added before. The module 61 Add the code if it wasnt added before. The module
62 name will be used for that 62 name will be used for that
63 63
64 Variables: 64 Variables:
65 @modulename a short name e.g. base.bbclass 65 @modulename a short name e.g. base.bbclass
@@ -81,4 +81,4 @@ def get_parsed_dict():
81 """ 81 """
82 shortcut 82 shortcut
83 """ 83 """
84 return _parsed_methods 84 return _parsed_methods
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py
index 59aa44bee0..d2ae09a4a4 100644
--- a/bitbake/lib/bb/parse/ast.py
+++ b/bitbake/lib/bb/parse/ast.py
@@ -122,12 +122,8 @@ class MethodNode:
122 122
123 def eval(self, data): 123 def eval(self, data):
124 if self.func_name == "__anonymous": 124 if self.func_name == "__anonymous":
125 funcname = ("__anon_%s_%s" % (self.lineno, self.fn.translate(string.maketrans('/.+-', '____'))))
126 if not funcname in bb.methodpool._parsed_fns:
127 text = "def %s(d):\n" % (funcname) + '\n'.join(self.body)
128 bb.methodpool.insert_method(funcname, text, self.fn)
129 anonfuncs = bb.data.getVar('__BBANONFUNCS', data) or [] 125 anonfuncs = bb.data.getVar('__BBANONFUNCS', data) or []
130 anonfuncs.append(funcname) 126 anonfuncs.append((self.fn, "\n".join(self.body)))
131 bb.data.setVar('__BBANONFUNCS', anonfuncs, data) 127 bb.data.setVar('__BBANONFUNCS', anonfuncs, data)
132 else: 128 else:
133 bb.data.setVarFlag(self.func_name, "func", 1, data) 129 bb.data.setVarFlag(self.func_name, "func", 1, data)
@@ -143,7 +139,7 @@ class PythonMethodNode(AstNode):
143 # Note we will add root to parsedmethods after having parse 139 # Note we will add root to parsedmethods after having parse
144 # 'this' file. This means we will not parse methods from 140 # 'this' file. This means we will not parse methods from
145 # bb classes twice 141 # bb classes twice
146 if not self.root in __parsed_methods__: 142 if not bb.methodpool.parsed_module(self.root):
147 text = '\n'.join(self.body) 143 text = '\n'.join(self.body)
148 bb.methodpool.insert_method(self.root, text, self.fn) 144 bb.methodpool.insert_method(self.root, text, self.fn)
149 145
@@ -301,32 +297,12 @@ def finalise(fn, d):
301 297
302 bb.data.expandKeys(d) 298 bb.data.expandKeys(d)
303 bb.data.update_data(d) 299 bb.data.update_data(d)
304 anonqueue = bb.data.getVar("__anonqueue", d, 1) or [] 300 for fn, func in bb.data.getVar("__BBANONFUNCS", d) or []:
305 body = [x['content'] for x in anonqueue] 301 funcdef = "def __anonfunc(d):\n%s\n__anonfunc(d)" % func.rstrip()
306 flag = { 'python' : 1, 'func' : 1 } 302 bb.utils.better_exec(funcdef, {"d": d}, funcdef, fn)
307 bb.data.setVar("__anonfunc", "\n".join(body), d)
308 bb.data.setVarFlags("__anonfunc", flag, d)
309 from bb import build
310 try:
311 t = bb.data.getVar('T', d)
312 bb.data.setVar('T', '${TMPDIR}/anonfunc/', d)
313 anonfuncs = bb.data.getVar('__BBANONFUNCS', d) or []
314 code = ""
315 for f in anonfuncs:
316 code = code + " %s(d)\n" % f
317 bb.data.setVar("__anonfunc", code, d)
318 build.exec_func("__anonfunc", d)
319 bb.data.delVar('T', d)
320 if t:
321 bb.data.setVar('T', t, d)
322 except Exception, e:
323 bb.msg.debug(1, bb.msg.domain.Parsing, "Exception when executing anonymous function: %s" % e)
324 raise
325 bb.data.delVar("__anonqueue", d)
326 bb.data.delVar("__anonfunc", d)
327 bb.data.update_data(d) 303 bb.data.update_data(d)
328 304
329 all_handlers = {} 305 all_handlers = {}
330 for var in bb.data.getVar('__BBHANDLERS', d) or []: 306 for var in bb.data.getVar('__BBHANDLERS', d) or []:
331 # try to add the handler 307 # try to add the handler
332 handler = bb.data.getVar(var,d) 308 handler = bb.data.getVar(var,d)
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 86b9c724ed..50e9402a2b 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -21,9 +21,16 @@ BitBake Utility Functions
21 21
22separators = ".-" 22separators = ".-"
23 23
24import re, fcntl, os, types, bb, string, stat, shutil 24import re, fcntl, os, types, bb, string, stat, shutil, time
25from commands import getstatusoutput 25from commands import getstatusoutput
26 26
27# Context used in better_exec, eval
28_context = {
29 "os": os,
30 "bb": bb,
31 "time": time,
32}
33
27def explode_version(s): 34def explode_version(s):
28 r = [] 35 r = []
29 alpha_regexp = re.compile('^([a-zA-Z]+)(.*)$') 36 alpha_regexp = re.compile('^([a-zA-Z]+)(.*)$')
@@ -164,13 +171,13 @@ def _print_trace(body, line):
164 bb.msg.error(bb.msg.domain.Util, "\t%.4d:%s" % (i, body[i-1]) ) 171 bb.msg.error(bb.msg.domain.Util, "\t%.4d:%s" % (i, body[i-1]) )
165 172
166 173
167def better_compile(text, file, realfile): 174def better_compile(text, file, realfile, mode = "exec"):
168 """ 175 """
169 A better compile method. This method 176 A better compile method. This method
170 will print the offending lines. 177 will print the offending lines.
171 """ 178 """
172 try: 179 try:
173 return compile(text, file, "exec") 180 return compile(text, file, mode)
174 except Exception, e: 181 except Exception, e:
175 import bb,sys 182 import bb,sys
176 183
@@ -193,7 +200,7 @@ def better_exec(code, context, text, realfile):
193 """ 200 """
194 import bb,sys 201 import bb,sys
195 try: 202 try:
196 exec code in context 203 exec code in _context, context
197 except: 204 except:
198 (t,value,tb) = sys.exc_info() 205 (t,value,tb) = sys.exc_info()
199 206
@@ -215,6 +222,9 @@ def better_exec(code, context, text, realfile):
215 222
216 raise 223 raise
217 224
225def better_eval(source, locals):
226 return eval(source, _context, locals)
227
218def Enum(*names): 228def Enum(*names):
219 """ 229 """
220 A simple class to give Enum support 230 A simple class to give Enum support