@@ -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: