aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2016-02-02 14:07:58 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-02-10 13:33:48 +0000
commit8bf33a8e92c0e188fa392030025756196c96fcbb (patch)
tree509681b0ba903825f61d0da99970ea2433be0425
parent3f5520b4844a4bdd615046479ba08ed192bdc8cd (diff)
downloadbitbake-8bf33a8e92c0e188fa392030025756196c96fcbb.tar.gz
build/data: Don't expand python functions before execution [API change]
Right now, if you have some python code like: X = "a" def somefunction(d): d.setVar("X", "b") d.setVar("Y", "${X}") then any sane person would expect that Y = "b" at the end of the function. This is not the case, Y = "a". This is due to the python function being expanded before execution, the executed code would read d.setVar("Y", "a"). This understandably confuses people, it also makes it near impossible to write ${} in a python function without unintended things happening. I think there is general agreement we should fix this and standardise on non-expansion of python functions. We already don't expand anonymous python (mostly). I've checked OE-Core with buildhistory before and after this change and there were a small number of issues this exposed which I've sent patches for. I propose we default to not expanding python code and then deal with any consequences from that if/as/where identified. This will improve new user understanding and usability of the system, it also allows several long standing weird expansion issues to be fixed. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/bb/build.py2
-rw-r--r--lib/bb/cooker.py2
-rw-r--r--lib/bb/data.py6
3 files changed, 5 insertions, 5 deletions
diff --git a/lib/bb/build.py b/lib/bb/build.py
index f16675bde..1cd546a71 100644
--- a/lib/bb/build.py
+++ b/lib/bb/build.py
@@ -239,7 +239,7 @@ def exec_func_python(func, d, runfile, cwd=None):
"""Execute a python BB 'function'"""
bbfile = d.getVar('FILE', True)
- code = _functionfmt.format(function=func, body=d.getVar(func, True))
+ code = _functionfmt.format(function=func, body=d.getVar(func, False))
bb.utils.mkdirhier(os.path.dirname(runfile))
with open(runfile, 'w') as script:
bb.data.emit_func_python(func, script, d)
diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index d990b0587..af3d77b3a 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -653,7 +653,7 @@ class BBCooker:
data.expandKeys(envdata)
for e in envdata.keys():
if data.getVarFlag( e, 'python', envdata ):
- logger.plain("\npython %s () {\n%s}\n", e, envdata.getVar(e, True))
+ logger.plain("\npython %s () {\n%s}\n", e, envdata.getVar(e, False))
def buildTaskData(self, pkgs_to_build, task, abort, allowincomplete=False):
diff --git a/lib/bb/data.py b/lib/bb/data.py
index 137ed4e3e..dbc6dea68 100644
--- a/lib/bb/data.py
+++ b/lib/bb/data.py
@@ -298,7 +298,7 @@ def emit_func_python(func, o=sys.__stdout__, d = init()):
"""Emits all items in the data store in a format such that it can be sourced by a shell."""
def write_func(func, o, call = False):
- body = d.getVar(func, True)
+ body = d.getVar(func, False)
if not body.startswith("def"):
body = _functionfmt.format(function=func, body=body)
@@ -308,7 +308,7 @@ def emit_func_python(func, o=sys.__stdout__, d = init()):
write_func(func, o, True)
pp = bb.codeparser.PythonParser(func, logger)
- pp.parse_python(d.getVar(func, True))
+ pp.parse_python(d.getVar(func, False))
newdeps = pp.execs
newdeps |= set((d.getVarFlag(func, "vardeps", True) or "").split())
seen = set()
@@ -320,7 +320,7 @@ def emit_func_python(func, o=sys.__stdout__, d = init()):
if d.getVarFlag(dep, "func", False) and d.getVarFlag(dep, "python", False):
write_func(dep, o)
pp = bb.codeparser.PythonParser(dep, logger)
- pp.parse_python(d.getVar(dep, True))
+ pp.parse_python(d.getVar(dep, False))
newdeps |= pp.execs
newdeps |= set((d.getVarFlag(dep, "vardeps", True) or "").split())
newdeps -= seen