mirror of
https://git.yoctoproject.org/poky
synced 2026-06-01 13:09:50 +00:00
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>
This commit is contained in:
committed by
Richard Purdie
parent
eb16773704
commit
94b60d1247
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user