diff options
author | Chris Larson <chris_larson@mentor.com> | 2010-03-30 20:06:07 -0700 |
---|---|---|
committer | Chris Larson <chris_larson@mentor.com> | 2010-03-30 20:06:09 -0700 |
commit | 424d7e267b009cc19b8503eadab782736d9597d0 (patch) | |
tree | aeba768adb121e1f562bd6b39e6c7e2897d701e5 /lib/bb/parse | |
parent | 97da0cebbaf4dd1b46e58bd2e80cab6c007ae7c9 (diff) | |
download | bitbake-424d7e267b009cc19b8503eadab782736d9597d0.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.
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'lib/bb/parse')
-rw-r--r-- | lib/bb/parse/ast.py | 36 |
1 files changed, 6 insertions, 30 deletions
diff --git a/lib/bb/parse/ast.py b/lib/bb/parse/ast.py index 59aa44bee..d2ae09a4a 100644 --- a/lib/bb/parse/ast.py +++ b/lib/bb/parse/ast.py @@ -122,12 +122,8 @@ class MethodNode: def eval(self, data): if self.func_name == "__anonymous": - funcname = ("__anon_%s_%s" % (self.lineno, self.fn.translate(string.maketrans('/.+-', '____')))) - if not funcname in bb.methodpool._parsed_fns: - text = "def %s(d):\n" % (funcname) + '\n'.join(self.body) - bb.methodpool.insert_method(funcname, text, self.fn) anonfuncs = bb.data.getVar('__BBANONFUNCS', data) or [] - anonfuncs.append(funcname) + anonfuncs.append((self.fn, "\n".join(self.body))) bb.data.setVar('__BBANONFUNCS', anonfuncs, data) else: bb.data.setVarFlag(self.func_name, "func", 1, data) @@ -143,7 +139,7 @@ class PythonMethodNode(AstNode): # Note we will add root to parsedmethods after having parse # 'this' file. This means we will not parse methods from # bb classes twice - if not self.root in __parsed_methods__: + if not bb.methodpool.parsed_module(self.root): text = '\n'.join(self.body) bb.methodpool.insert_method(self.root, text, self.fn) @@ -301,32 +297,12 @@ def finalise(fn, d): bb.data.expandKeys(d) bb.data.update_data(d) - anonqueue = bb.data.getVar("__anonqueue", d, 1) or [] - body = [x['content'] for x in anonqueue] - flag = { 'python' : 1, 'func' : 1 } - bb.data.setVar("__anonfunc", "\n".join(body), d) - bb.data.setVarFlags("__anonfunc", flag, d) - from bb import build - try: - t = bb.data.getVar('T', d) - bb.data.setVar('T', '${TMPDIR}/anonfunc/', d) - anonfuncs = bb.data.getVar('__BBANONFUNCS', d) or [] - code = "" - for f in anonfuncs: - code = code + " %s(d)\n" % f - bb.data.setVar("__anonfunc", code, d) - build.exec_func("__anonfunc", d) - bb.data.delVar('T', d) - if t: - bb.data.setVar('T', t, d) - except Exception, e: - bb.msg.debug(1, bb.msg.domain.Parsing, "Exception when executing anonymous function: %s" % e) - raise - bb.data.delVar("__anonqueue", d) - bb.data.delVar("__anonfunc", d) + for fn, func in bb.data.getVar("__BBANONFUNCS", d) or []: + funcdef = "def __anonfunc(d):\n%s\n__anonfunc(d)" % func.rstrip() + bb.utils.better_exec(funcdef, {"d": d}, funcdef, fn) bb.data.update_data(d) - all_handlers = {} + all_handlers = {} for var in bb.data.getVar('__BBHANDLERS', d) or []: # try to add the handler handler = bb.data.getVar(var,d) |