]> code.ossystems Code Review - openembedded-core.git/commitdiff
utils: add helper to perform the intersection of two string lists
authorRoss Burton <ross.burton@intel.com>
Fri, 22 May 2015 11:30:26 +0000 (12:30 +0100)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 23 May 2015 06:56:21 +0000 (07:56 +0100)
Useful for e.g. generating a COMBINED_FEATURES list from DISTRO_FEATURES and
MACHINE_FEATURES.

Signed-off-by: Ross Burton <ross.burton@intel.com>
meta/lib/oe/utils.py

index b8224de20b962e38b327b7813df5bd2798496406..7173e106f5b67ad00597a76908ddc51049d29ce5 100644 (file)
@@ -55,6 +55,21 @@ def both_contain(variable1, variable2, checkvalue, d):
     else:
         return ""
 
+def set_intersect(variable1, variable2, d):
+    """
+    Expand both variables, interpret them as lists of strings, and return the
+    intersection as a flattened string.
+
+    For example:
+    s1 = "a b c"
+    s2 = "b c d"
+    s3 = set_intersect(s1, s2)
+    => s3 = "b c"
+    """
+    val1 = set(d.getVar(variable1, True).split())
+    val2 = set(d.getVar(variable2, True).split())
+    return " ".join(val1 & val2)
+
 def prune_suffix(var, suffixes, d):
     # See if var ends with any of the suffixes listed and
     # remove it if found