bb.codeparser: track variable flag references
PATCH 1/1 bb.codeparser: track variable flag references
From: Christopher Larson <[email protected]>
Previously we only tracked the flags (minus excluded) of variables we depend on, but not the flags we use explicitly.
--- lib/bb/codeparser.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
lib/bb/codeparser.py +9 -3
@@ -191,6 +191,7 @@ class BufferedLogger(Logger): class PythonParser(): getvars = (".getVar", ".appendVar", ".prependVar") + getvarflags = (".getVarFlag", ".appendVarFlag", ".prependVarFlag") containsfuncs = ("bb.utils.contains", "base_contains", "bb.utils.contains_any") execfuncs = ("bb.build.exec_func", "bb.build.exec_task")
@@ -210,15 +211,20 @@ class PythonParser(): def visit_Call(self, node): name = self.called_node_name(node.func) - if name and name.endswith(self.getvars) or name in self.containsfuncs: + if name and (name.endswith(self.getvars) or name.endswith(self.getvarflags) or name in self.containsfuncs): if isinstance(node.args[0], ast.Str): varname = node.args[0].s if name in self.containsfuncs and isinstance(node.args[1], ast.Str): if varname not in self.contains: self.contains[varname] = set() self.contains[varname].add(node.args[1].s) - else: - self.references.add(node.args[0].s) + elif name.endswith(self.getvarflags): + if isinstance(node.args[1], ast.Str): + self.references.add('%s[%s]' % (varname, node.args[1].s)) + else: + self.warn(node.func, node.args[1]) + else: + self.references.add(varname) else: self.warn(node.func, node.args[0]) elif name and name.endswith(".expand"):
Signature · 1 line
2.8.0
PATCH 1/1 bb.cooker: show limited traceback for parsing ExpansionError
From: Christopher Larson <[email protected]>
It's useful to see tracebacks for ExpansionErrors, but only if we skip the leading bitbake-internal elements, otherwise we see elements of the expansion process.
As one example:
Before:
ERROR: ExpansionError during parsing /scratch/yocto-new/external-as-needed/poky/meta/recipes-core/glibc/glibc-locale_2.23.bb: Failure expanding variable PV[:=], expression was ${@get_external_libc_version(d)} which triggered exception AttributeError: 'module' object has no attribute 'external'After:
ERROR: ExpansionError during parsing /scratch/yocto-new/external-as-needed/poky/meta/recipes-core/glibc/glibc-locale_2.23.bb
Traceback (most recent call last):
File "PV[:=]", line 1, in <module>
File "/scratch/yocto-new/external-as-needed/meta-sourcery/recipes-external/glibc/glibc-external-version.inc", line 3, in get_external_libc_version(d=<bb.data_smart.DataSmart
object at 0x7f05d2566950>):
sopattern = os.path.join(d.getVar('base_libdir', True), 'libc-*.so')
> found_paths = oe.external.find_sysroot_files([sopattern], d)
if found_paths:
ExpansionError: Failure expanding variable PV[:=], expression was ${@get_external_libc_version(d)} which triggered exception AttributeError: 'module' object has no attribute 'external'
--- lib/bb/cooker.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
lib/bb/cooker.py +5 -2
@@ -2153,8 +2153,11 @@ class CookerParser(object): return False except bb.data_smart.ExpansionError as exc: self.error += 1 - _, value, _ = sys.exc_info() - logger.error('ExpansionError during parsing %s: %s', value.recipe, str(exc)) + bbdir = os.path.dirname(__file__) + os.sep + etype, value, _ = sys.exc_info() + tb = list(itertools.dropwhile(lambda e: e.filename.startswith(bbdir), exc.traceback)) + logger.error('ExpansionError during parsing %s', value.recipe, + exc_info=(etype, value, tb)) self.shutdown(clean=False) return False except Exception as exc:
Signature · 1 line
2.8.0
PATCH 1/1 bb.cooker: only emit a var as python if 'func' is set
In reply to Christopher LarsonFrom: Christopher Larson <[email protected]>
This avoids a common issue where PACKAGECONFIG is emitted as a function in bitbake -e when the 'python' flag exists. It isn't a python function unless both 'func' and 'python' are set. This aligns with the behavior of emit_func_python.
--- lib/bb/cooker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/cooker.py +1 -1
@@ -656,7 +656,7 @@ class BBCooker: # emit the metadata which isnt valid shell data.expandKeys(envdata) for e in envdata.keys(): - if data.getVarFlag( e, 'python', envdata ): + 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.8.0
PATCH 1/1 Implement support for per-task exports
In reply to Christopher LarsonFrom: Christopher Larson <[email protected]>
--- bin/bitbake-worker | 10 ++++++++++ lib/bb/data.py | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-)
bin/bitbake-worker +10 -0
@@ -207,14 +207,24 @@ def fork_off_task(cfg, data, workerdata, fn, task, taskname, appends, taskdepdat # exported_vars() returns a generator which *cannot* be passed to os.environ.update() # successfully. We also need to unset anything from the environment which shouldn't be there exports = bb.data.exported_vars(the_data) + bb.utils.empty_environment() for e, v in exports: os.environ[e] = v + for e in fakeenv: os.environ[e] = fakeenv[e] the_data.setVar(e, fakeenv[e]) the_data.setVarFlag(e, 'export', "1") + task_exports = the_data.getVarFlag(taskname, 'exports', True) + if task_exports: + for e in task_exports.split(): + the_data.setVarFlag(e, 'export', '1') + v = the_data.getVar(e, True) + if v is not None: + os.environ[e] = v + if quieterrors: the_data.setVarFlag(taskname, "quieterrors", "1")
lib/bb/data.py +3 -1
@@ -339,7 +339,7 @@ def build_dependencies(key, keys, shelldeps, varflagsexcl, d): deps |= parser.references deps = deps | (keys & parser.execs) return deps, value - varflags = d.getVarFlags(key, ["vardeps", "vardepvalue", "vardepsexclude", "vardepvalueexclude", "postfuncs", "prefuncs", "lineno", "filename"]) or {} + varflags = d.getVarFlags(key, ["vardeps", "vardepvalue", "vardepsexclude", "vardepvalueexclude", "exports", "postfuncs", "prefuncs", "lineno", "filename"]) or {} vardeps = varflags.get("vardeps") value = d.getVar(key, False)
@@ -383,6 +383,8 @@ def build_dependencies(key, keys, shelldeps, varflagsexcl, d): deps = deps | set(varflags["prefuncs"].split()) if "postfuncs" in varflags: deps = deps | set(varflags["postfuncs"].split()) + if "exports" in varflags: + deps = deps | set(varflags["exports"].split()) else: parser = d.expandWithRefs(value, key) deps |= parser.references
Signature · 1 line
2.8.0
PATCH 1/1 Provide LAYERDIR_RE for layer.conf
In reply to Christopher LarsonFrom: Christopher Larson <[email protected]>
This variable is a regex-escaped version of LAYERDIR, for safer use in BBFILE_PATTERN, so as to avoid issues with regex special characters in the layer path.
[YOCTO #8402]
--- doc/bitbake-user-manual/bitbake-user-manual-hello.xml | 2 +- doc/bitbake-user-manual/bitbake-user-manual-ref-variables.xml | 11 +++++++++++ lib/bb/cookerdata.py | 9 +++++++-- 3 files changed, 19 insertions(+), 3 deletions(-)
doc/bitbake-user-manual/bitbake-user-manual-hello.xml +1 -1
@@ -399,7 +399,7 @@ ERROR: Unable to parse base: ParseError in configuration INHERITs: Could not inh <link linkend='var-BBFILES'>BBFILES</link> += "${LAYERDIR}/*.bb" <link linkend='var-BBFILE_COLLECTIONS'>BBFILE_COLLECTIONS</link> += "mylayer" - <link linkend='var-BBFILE_PATTERN'>BBFILE_PATTERN_mylayer</link> := "^${LAYERDIR}/" + <link linkend='var-BBFILE_PATTERN'>BBFILE_PATTERN_mylayer</link> := "^${LAYERDIR_RE}/" </literallayout> For information on these variables, click the links to go to the definitions in the glossary.</para>
doc/bitbake-user-manual/bitbake-user-manual-ref-variables.xml +11 -0
@@ -1636,6 +1636,17 @@ </glossdef> </glossentry> + <glossentry id='var-LAYERDIR_RE'><glossterm>LAYERDIR_RE</glossterm> + <glossdef> + <para>When used inside the <filename>layer.conf</filename> configuration + file, this variable provides the path of the current layer, + escaped for use in a regular expression + (<link linkend='var-BBFILE_PATTERN'><filename>BBFILE_PATTERN</filename></link>). + This variable is not available outside of <filename>layer.conf</filename> + and references are expanded immediately when parsing of the file completes.</para> + </glossdef> + </glossentry> + <glossentry id='var-LAYERVERSION'><glossterm>LAYERVERSION</glossterm> <glossdef> <para>Optionally specifies the version of a layer as a single number.
lib/bb/cookerdata.py +7 -2
@@ -22,9 +22,11 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -import os, sys -from functools import wraps import logging +import os +import re +import sys +from functools import wraps import bb from bb import data import bb.parse
@@ -295,9 +297,12 @@ class CookerDataBuilder(object): if layer.endswith('/'): layer = layer.rstrip('/') data.setVar('LAYERDIR', layer) + data.setVar('LAYERDIR_RE', re.escape(layer)) data = parse_config_file(os.path.join(layer, "conf", "layer.conf"), data) data.expandVarref('LAYERDIR') + data.expandVarref('LAYERDIR_RE') + data.delVar('LAYERDIR_RE') data.delVar('LAYERDIR') if not data.getVar("BBPATH", True):
Signature · 1 line
2.8.0
Re: [master][PATCH] bb.cooker: only emit a var as python if 'func' is set
In reply to Christopher LarsonQuoted 8 lines · Christopher Larson
From: Christopher Larson <[email protected]>
This avoids a common issue where PACKAGECONFIG is emitted as a function in bitbake -e when the 'python' flag exists. It isn't a python function unless both 'func' and 'python' are set. This aligns with the behavior of
emit_func_python.Signed-off-by Christopher Larson <[email protected]>
Don't apply this yet, v2 forthcoming.
Signature · 5 lines
Christopher Larson kergoth at gmail dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Senior Software Engineer, Mentor Graphics
Re: [master][PATCH] bb.cooker: only emit a var as python if 'func' is set
Quoted 11 lines · Christopher Larson
Quoted 8 lines · Christopher Larson
From: Christopher Larson <[email protected]>
This avoids a common issue where PACKAGECONFIG is emitted as a function in bitbake -e when the 'python' flag exists. It isn't a python function unless
both 'func' and 'python' are set. This aligns with the behavior ofemit_func_python.
Quoted 5 lines
Quoted 1 line
Signed-off-by Christopher Larson <[email protected]>Don't apply this yet, v2 forthcoming.
Superceded by '[master][PATCH] bb.{cooker,data}: only emit a var as python if 'func'
is set'.
Signature · 5 lines
Christopher Larson kergoth at gmail dot com Founder - BitBake, OpenEmbedded, OpenZaurus Maintainer - Tslib Senior Software Engineer, Mentor Graphics