diff mbox series

[v2,4/6] oeqa/utils/commands: support variable flags in get_bb_vars

Message ID 20261025181847.784113-5-adrian.freihofer@siemens.com
State New
Headers show
Series kernel-fit-image: add FIT_LOADABLE_* variables to do_compile vardeps | expand

Commit Message

AdrianF Oct. 25, 2026, 6:18 p.m. UTC
From: Adrian Freihofer <adrian.freihofer@siemens.com>

Tests can not query variable flags with get_bb_vars. They either need
another bitbake invocation per flag or the metadata needs to copy the
flags into variable values just to make them visible to the tests.

Allow requesting variable flags with the VAR[flag] syntax. They are read
in the same tinfoil session as the variables. Unset or empty flags are
returned as None, consistent with the variables. For example:

    bb_vars = get_bb_vars(['FIT_LOADABLES',
                           'FIT_LOADABLE_FILENAME[loadable1]'],
                          'linux-yocto-fitimage')
    filename = bb_vars['FIT_LOADABLE_FILENAME[loadable1]']

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

Patch

diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py
index 1ccc107aed..f4876ca6c9 100644
--- a/meta/lib/oeqa/utils/commands.py
+++ b/meta/lib/oeqa/utils/commands.py
@@ -254,10 +254,11 @@  def get_bb_env(target=None, postconfig=None):
         return bitbake("-e", postconfig=postconfig).output
 
 def get_bb_vars(variables=None, target=None, postconfig=None):
-    """Get values of multiple bitbake variables
+    """Get values of multiple bitbake variables or variable flags
 
-    All values are read with a single tinfoil session. If variables is None,
-    all variables are returned. Unset or empty values are returned as None.
+    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.
     """
     import bb.tinfoil
 
@@ -282,8 +283,13 @@  def get_bb_vars(variables=None, target=None, postconfig=None):
                     values[var] = str(val)
             return values
 
+        flag_re = re.compile(r'^(?P<var>[^\[]+)\[(?P<flag>[^\]]+)\]$')
         for var in variables:
-            val = d.getVar(var)
+            match = flag_re.match(var)
+            if match:
+                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
     return values