diff options
author | Chris Larson <chris_larson@mentor.com> | 2010-03-30 20:06:07 -0700 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-07-02 15:41:31 +0100 |
commit | 94b60d1247be4ce42eaefafe13e73169bd978bd7 (patch) | |
tree | 3a8ed098cc96b5ee63c6652c8d49cda6c99a5524 /bitbake/lib/bb/parse | |
parent | eb167737041d8754988d153e0495268f03b6e809 (diff) | |
download | poky-94b60d1247be4ce42eaefafe13e73169bd978bd7.tar.gz |
Consolidate the exec/eval bits, switch anonfunc to better_exec, etc
The methodpool, ${@} expansions, anonymous python functions, event handlers
now all run with the same global context, ensuring a consistent environment
for them. Added a bb.utils.better_eval function which does an eval() with the
same globals as better_exec.
(Bitbake rev: 424d7e267b009cc19b8503eadab782736d9597d0)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib/bb/parse')
-rw-r--r-- | bitbake/lib/bb/parse/ast.py | 36 |
1 files changed, 6 insertions, 30 deletions
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) |