build/data: Don't expand python functions before execution [API change]
PATCH 1/1 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.
bitbake/lib/bb/build.py +1 -1
@@ -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)
bitbake/lib/bb/data.py +1 -1
@@ -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()
Quoted 5 lines · Richard Purdie
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.
As someone who has had to write classes that do "$" + "{FOO}", this gets a massive +1 from me.
Ross
Quoted 11 lines · Ross
Quoted 5 lines · Richard Purdie
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.
As someone who has had to write classes that do "$" + "{FOO}", this gets a massive +1 from me.
Indeed, it's a very welcome change from my point of view! +1
Signature · 1 line
olofjn
Quoted 24 lines · Richard Purdie
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.
Quoted 8 lines
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 <[email protected]<javascript:;>>
I absolutely support this. It should reduce confusion with no loss of functionality.
Signature · 5 lines
Christopher Larson kergoth at gmail dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Senior Software Engineer, Mentor Graphics
Quoted 23 lines · Richard Purdie
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).
Quoted 8 lines
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.
I support this too. Additionally, it will be a nice to document this if it has not been done thus far.
Quoted 36 lines
Signed-off-by Richard Purdie <[email protected]>bitbake/lib/bb/build.py +1
-1@@ -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)bitbake/lib/bb/data.py +1
-2@@ -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() --_______________________________________________
bitbake-devel mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/bitbake-devel