Skip to contentSkip to conversation

parse/ast: Abstract anonymous function execution into a function

PATCH New Richard Purdie 1 participant 2 messages Mar 3, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 parse/ast: Abstract anonymous function execution into a function

This allows us to call this code from other contexts without duplicating it.

---
 lib/bb/parse/ast.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
lib/bb/parse/ast.py +7 -4
index dba4540..6690dc5 100644
@@ -335,6 +335,12 @@ def handleInherit(statements, filename, lineno, m):
     classes = m.group(1)
     statements.append(InheritNode(filename, lineno, classes))
 
+def runAnonFuncs(d):
+    code = []
+    for funcname in d.getVar("__BBANONFUNCS", False) or []:
+        code.append("%s(d)" % funcname)
+    bb.utils.better_exec("\n".join(code), {"d": d})
+
 def finalize(fn, d, variant = None):
     saved_handlers = bb.event.get_handlers().copy()
 
@@ -349,10 +355,7 @@ def finalize(fn, d, variant = None):
     bb.event.fire(bb.event.RecipePreFinalise(fn), d)
 
     bb.data.expandKeys(d)
-    code = []
-    for funcname in d.getVar("__BBANONFUNCS", False) or []:
-        code.append("%s(d)" % funcname)
-    bb.utils.better_exec("\n".join(code), {"d": d})
+    runAnonFuncs(d)
 
     tasklist = d.getVar('__BBTASKS', False) or []
     bb.event.fire(bb.event.RecipeTaskPreProcess(fn, list(tasklist)), d)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/2 cooker: Run registered anonymous python before displaying environment

The output of bitbake -e can differ from what actually is used due to anonymous python making changes to the data store. Execute any anonymous python added in the base configuration to make things more consistent.

---
 lib/bb/cooker.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/bb/cooker.py +3 -1
index af482f9..d1df711 100644
@@ -530,13 +530,15 @@ class BBCooker:
             self.data.inchistory.emit(env)
             logger.plain(env.getvalue())
 
+        data.expandKeys(envdata)
+        parse.ast.runAnonFuncs(envdata)
+
         # emit variables and shell functions
         with closing(StringIO()) as env:
             data.emit_env(env, envdata, True)
             logger.plain(env.getvalue())
 
         # emit the metadata which isnt valid shell
-        data.expandKeys(envdata)
         for e in sorted(envdata.keys()):
             if envdata.getVarFlag(e, 'func', False) and envdata.getVarFlag(e, 'python', False):
                 logger.plain("\npython %s () {\n%s}\n", e, envdata.getVar(e, False))
Signature · 1 line
2.7.4