Skip to contentSkip to conversation

utils: add helper to perform the intersection of two string lists

PATCH New Ross Burton 1 participant 2 messages May 22, 2015

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 utils: add helper to perform the intersection of two string lists

Useful for e.g. generating a COMBINED_FEATURES list from DISTRO_FEATURES and MACHINE_FEATURES.

---
 meta/lib/oe/utils.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
meta/lib/oe/utils.py +15 -0
index b8224de..7173e10 100644
@@ -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
Signature · 1 line
2.1.4
#1 lore raw

PATCH v2 2/2 bitbake.conf: programatically generate COMBINED_FEATURES

Instead of hard-coding the set of features that can be considered in COMBINED_FEATURES, simply generate the intersection of DISTRO_FEATURES and MACHINE_FEATURES.

---
 meta/conf/bitbake.conf | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
meta/conf/bitbake.conf +1 -11
index 8653a7f..9c72044 100644
@@ -735,17 +735,7 @@ IMAGE_FEATURES += "${EXTRA_IMAGE_FEATURES}"
 DISTRO_FEATURES_BACKFILL = "pulseaudio sysvinit bluez5"
 MACHINE_FEATURES_BACKFILL = "rtc"
 
-COMBINED_FEATURES = "\
-    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "alsa", d)} \
-    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "bluetooth", d)} \
-    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "ext2", d)} \
-    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "vfat", d)} \
-    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "irda", d)} \
-    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "pcmcia", d)} \
-    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "pci", d)} \
-    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "usbgadget", d)} \
-    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "usbhost", d)} \
-    ${@base_both_contain("DISTRO_FEATURES", "MACHINE_FEATURES", "wifi", d)}"
+COMBINED_FEATURES = "${@oe.utils.set_intersect('DISTRO_FEATURES', 'MACHINE_FEATURES', d)}"
 COMBINED_FEATURES[vardeps] += "DISTRO_FEATURES MACHINE_FEATURES"
 
 SERIAL_CONSOLE ??= ""
Signature · 1 line
2.1.4