diff mbox series

utils: Add filter_string function

Message ID 20260423133033.1952809-1-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit b508e646b539b7260422b2ffd38168742094ebf3
Headers show
Series utils: Add filter_string function | expand

Commit Message

Richard Purdie April 23, 2026, 1:30 p.m. UTC
There are cases where we would like the filter functionality but
don't want to read the data from a variable. Add a new function,
filter_string to allow this, basically separating filter() into
two functions.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/utils.py | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 7c5c5e8e65d..b04ff6ffc76 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -1336,21 +1336,18 @@  def contains_any(variable, checkvalues, truevalue, falsevalue, d):
         return truevalue
     return falsevalue
 
-def filter(variable, checkvalues, d):
-    """Return all words in the variable that are present in the ``checkvalues``.
+def filter_string(val, checkvalues):
+    """Return all words in the string that are present in the ``checkvalues``.
 
     Arguments:
 
-    -  ``variable``: the variable name. This will be fetched and expanded (using
-       d.getVar(variable)) and then split into a set().
+    -  ``val``: the string data to filter after being split into a set().
     -  ``checkvalues``: if this is a string it is split on whitespace into a set(),
        otherwise coerced directly into a set().
     -  ``d``: the data store.
 
     Returns a list of string.
     """
-
-    val = d.getVar(variable)
     if not val:
         return ''
     val = set(val.split())
@@ -1360,6 +1357,22 @@  def filter(variable, checkvalues, d):
         checkvalues = set(checkvalues)
     return ' '.join(sorted(checkvalues & val))
 
+def filter(variable, checkvalues, d):
+    """Return all words in the variable that are present in the ``checkvalues``.
+
+    Arguments:
+
+    -  ``variable``: the variable name. This will be fetched and expanded (using
+       d.getVar(variable)) and then split into a set().
+    -  ``checkvalues``: if this is a string it is split on whitespace into a set(),
+       otherwise coerced directly into a set().
+    -  ``d``: the data store.
+
+    Returns a list of string.
+    """
+
+    val = d.getVar(variable)
+    return filter_string(val, checkvalues)
 
 def get_referenced_vars(start_expr, d):
     """