diff mbox series

[2/3] oeqa/utils/commands: use get_bb_vars_flags in get_bb_var

Message ID 20261028211203.3081460-3-adrian.freihofer@siemens.com
State New
Headers show
Series oeqa/utils/commands: add get_bb_vars_flags and build get_bb_var(s) on it | expand

Commit Message

AdrianF Oct. 28, 2026, 9:11 p.m. UTC
From: Adrian Freihofer <adrian.freihofer@siemens.com>

Replace the bitbake-getvar subprocess of get_bb_var with
get_bb_vars_flags. The return values do not change: unset variables are
returned as None, empty ones as an empty string and values are stripped.

This also fixes get_bb_var with a postconfig file. It ran "bitbake -e"
and returned its whole output instead of the value of the variable. Without
a target it even failed, because "-e %s" % target or "" evaluated to
"-e None". It went unnoticed because no caller in oe-core passes a
postconfig.

One behavior change: a recipe which does not exist now raises
bb.providers.NoProvider. bitbake-getvar exited with status 1 in this case
and get_bb_var returned None.

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 meta/lib/oeqa/utils/commands.py | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py
index 7486a39dc5..3473ffb74b 100644
--- a/meta/lib/oeqa/utils/commands.py
+++ b/meta/lib/oeqa/utils/commands.py
@@ -317,20 +317,13 @@  def get_bb_vars(variables=None, target=None, postconfig=None):
     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
+
+    Unset variables are returned as None, empty values as an empty string.
+    """
+    values, _ = get_bb_vars_flags([var], None, target, postconfig)
+    val = values[var]
+    return val.strip() if val is not None else None
 
 def get_test_layer(bblayers=None):
     if bblayers is None: