From: Adrian Freihofer <[email protected]> Move the tinfoil code of get_bb_vars into a helper and use it in get_bb_var instead of bitbake-getvar. get_bb_var can now query variable flags with the VAR[flag] syntax. The return values do not change.
This also fixes get_bb_var with a postconfig file, which returned the whole "bitbake -e" output instead of the value. It went unnoticed because no caller in oe-core passes a postconfig. Signed-off-by: Adrian Freihofer <[email protected]> --- meta/lib/oeqa/utils/commands.py | 48 ++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py index f4876ca6c9..10422fea24 100644 --- a/meta/lib/oeqa/utils/commands.py +++ b/meta/lib/oeqa/utils/commands.py @@ -253,12 +253,13 @@ def get_bb_env(target=None, postconfig=None): else: return bitbake("-e", postconfig=postconfig).output -def get_bb_vars(variables=None, target=None, postconfig=None): - """Get values of multiple bitbake variables or variable flags +def _get_bb_values(variables=None, target=None, postconfig=None): + """Read bitbake variables or variable flags with a single tinfoil session - All values are read with a single tinfoil session. Variable flags can be - requested with the VAR[flag] syntax. If variables is None, all variables - are returned. Unset or empty values are returned as None. + Variable flags can be requested with the VAR[flag] syntax. If variables + is None, all variables are returned. Values which are not strings are + converted with str() as bitbake -e does, unset variables or flags are + returned as None. """ import bb.tinfoil @@ -279,7 +280,7 @@ def get_bb_vars(variables=None, target=None, postconfig=None): if var.startswith('__') or d.getVarFlag(var, 'func'): continue val = d.getVar(var) - if val is not None and val != '': + if val is not None: values[var] = str(val) return values @@ -290,24 +291,29 @@ def get_bb_vars(variables=None, target=None, postconfig=None): val = d.getVarFlag(match.group('var'), match.group('flag')) else: val = d.getVar(var) - values[var] = str(val) if val is not None and val != '' else None + values[var] = str(val) if val is not None else None return values +def get_bb_vars(variables=None, target=None, postconfig=None): + """Get values of multiple bitbake variables or variable flags + + All values are read with a single tinfoil session. Variable flags can be + requested with the VAR[flag] syntax. If variables is None, all variables + are returned. Unset or empty values are returned as None. + """ + values = _get_bb_values(variables, target, postconfig) + if variables is None: + return {var: val for var, val in values.items() if val} + return {var: val or None for var, val in values.items()} + def get_bb_var(var, target=None, postconfig=None): - if postconfig: - return bitbake("-e %s" % target or "", postconfig=postconfig).output - else: - # Fast-path for the non-postconfig case - cmd = ["bitbake-getvar", "--quiet", "--value", var] - if target: - cmd.extend(["--recipe", target]) - try: - return subprocess.run(cmd, check=True, text=True, stdout=subprocess.PIPE).stdout.strip() - except subprocess.CalledProcessError as e: - # We need to return None not the empty string if the variable hasn't been set. - if e.returncode == 1: - return None - raise + """Get the value of a bitbake variable or variable flag + + A variable flag can be requested with the VAR[flag] syntax. Unset values + are returned as None, empty values as an empty string. + """ + val = _get_bb_values([var], target, postconfig)[var] + return val.strip() if val is not None else None def get_test_layer(bblayers=None): if bblayers is None: -- 2.56.0
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#248614): https://lists.openembedded.org/g/openembedded-core/message/248614 Mute This Topic: https://lists.openembedded.org/mt/121930723/21656 Group Owner: [email protected] Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
