Skip to contentSkip to conversation

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

PATCH Superseded Ross Burton 3 participants 6 messages May 22, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

---
 meta/lib/oe/utils.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
meta/lib/oe/utils.py +15 -0
index b8224de..f70bd86 100644
@@ -55,6 +55,21 @@ def both_contain(variable1, variable2, checkvalue, d):
     else:
         return ""
 
+def set_union(variable1, variable2, d):
+    """
+    Expand both variables, interpret them as lists of strings, and return the
+    union as a flattened string.
+
+    For example:
+    s1 = "a b c"
+    s2 = "b c d"
+    s3 = set_union(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 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 union 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..88b004f 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_union('DISTRO_FEATURES', 'MACHINE_FEATURES', d)}"
 COMBINED_FEATURES[vardeps] += "DISTRO_FEATURES MACHINE_FEATURES"
 
 SERIAL_CONSOLE ??= ""
Signature · 1 line
2.1.4
#4 lore raw
In reply to Ross Burton
Quoted 10 lines · Ross Burton
---
 meta/lib/oe/utils.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
meta/lib/oe/utils.py +0 -0
index b8224de..f70bd86 100644

meta/lib/oe/utils.py def both_contain(variable1, variable2, checkvalue, d): · line 61

Quoted 7 lines
meta/lib/oe/utils.py +4 -0
@@ -55,6 +55,21 @@ def both_contain(variable1, variable2, checkvalue, d):
     else:
         return ""
 
+def set_union(variable1, variable2, d):
+    """
+    Expand both variables, interpret them as lists of strings, and return the
+    union as a flattened string.

This function is returning the intersection of the two sets, not the union. Maybe change the name and the comment here?

Quoted 17 lines
meta/lib/oe/utils.py +11 -0
+
+    For example:
+    s1 = "a b c"
+    s2 = "b c d"
+    s3 = set_union(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

-Matt

#2 lore raw

Re: [PATCH 2/2] bitbake.conf: programatically generate COMBINED_FEATURES

In reply to Ross Burton
Quoted 5 lines · Ross Burton

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

Wouldn't this be a intersect?

Signature · 3 lines
Otavio Salvador                             O.S. Systems
http://www.ossystems.com.br        http://code.ossystems.com.br
Mobile: +55 (53) 9981-7854            Mobile: +1 (347) 903-9750
#3 lore raw

Re: [PATCH 2/2] bitbake.conf: programatically generate COMBINED_FEATURES

Quoted 2 lines · Otavio Salvador

Wouldn't this be a intersect?

Erm, yes. :)

Ross

#5 lore raw
In reply to Matt Madison
Quoted 3 lines · Matt Madison

This function is returning the intersection of the two sets, not the union. Maybe change the name and the comment here?

Union, intersection, what's the difference really. ;) V2 sent.

Ross