Patchwork [1/2] oe.utils, utils.bbclass: Add any_contains and base_any_contains

login
register
mail settings
Submitter Otavio Salvador
Date April 1, 2014, 5:07 p.m.
Message ID <1396372080-27607-1-git-send-email-otavio@ossystems.com.br>
Download mbox | patch
Permalink /patch/69865/
State New
Headers show

Comments

Otavio Salvador - April 1, 2014, 5:07 p.m.
This is similar to the contains but matches any of values. This is
useful to match for example several DISTRO_FEATURES which ought to
include a PACKAGECONFIG option.

For example:

PACKAGECONFIG ??= "${@base_any_contains('DISTRO_FEATURES', 'x11 wayland', 'gtk+', '', d)}"

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
---
 meta/classes/utils.bbclass |  3 +++
 meta/lib/oe/utils.py       | 13 +++++++++++++
 2 files changed, 16 insertions(+)
Richard Purdie - April 1, 2014, 5:53 p.m.
On Tue, 2014-04-01 at 14:07 -0300, Otavio Salvador wrote:
> This is similar to the contains but matches any of values. This is
> useful to match for example several DISTRO_FEATURES which ought to
> include a PACKAGECONFIG option.
> 
> For example:
> 
> PACKAGECONFIG ??= "${@base_any_contains('DISTRO_FEATURES', 'x11 wayland', 'gtk+', '', d)}"
> 
> Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
> ---
>  meta/classes/utils.bbclass |  3 +++
>  meta/lib/oe/utils.py       | 13 +++++++++++++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/meta/classes/utils.bbclass b/meta/classes/utils.bbclass
> index 0a533af..966eda1 100644
> --- a/meta/classes/utils.bbclass
> +++ b/meta/classes/utils.bbclass
> @@ -26,6 +26,9 @@ def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
>  def base_contains(variable, checkvalues, truevalue, falsevalue, d):
>      return oe.utils.contains(variable, checkvalues, truevalue, falsevalue, d)
>  
> +def base_any_contains(variable, checkvalues, truevalue, falsevalue, d):
> +    return oe.utils.any_contains(variable, checkvalues, truevalue, falsevalue, d)
> +
>  def base_both_contain(variable1, variable2, checkvalue, d):
>      return oe.utils.both_contain(variable1, variable2, checkvalue, d)
>  
> diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
> index defa536..029d713 100644
> --- a/meta/lib/oe/utils.py
> +++ b/meta/lib/oe/utils.py
> @@ -54,6 +54,19 @@ def contains(variable, checkvalues, truevalue, falsevalue, d):
>          return truevalue
>      return falsevalue
>  
> +def any_contains(variable, checkvalues, truevalue, falsevalue, d):
> +    val = d.getVar(variable, True)
> +    if not val:
> +        return falsevalue
> +    val = set(val.split())
> +    if isinstance(checkvalues, basestring):
> +        checkvalues = set(checkvalues.split())
> +    else:
> +        checkvalues = set(checkvalues)
> +    if checkvalues in val:
> +        return truevalue
> +    return falsevalue
> +
>  def both_contain(variable1, variable2, checkvalue, d):
>      if d.getVar(variable1,1).find(checkvalue) != -1 and d.getVar(variable2,1).find(checkvalue) != -1:
>          return checkvalue

A more logical name is perhaps containsany(). 

I'd also add that bitbake has special support for contains() and
optimises sstate hashes for its use. We don't have such optimisation for
containsany(). I think this is perhaps 1.7 material at this point.

Cheers,

Richard
Otavio Salvador - April 1, 2014, 6:38 p.m.
On Tue, Apr 1, 2014 at 2:53 PM, Richard Purdie
<richard.purdie@linuxfoundation.org> wrote:
> On Tue, 2014-04-01 at 14:07 -0300, Otavio Salvador wrote:
>> This is similar to the contains but matches any of values. This is
>> useful to match for example several DISTRO_FEATURES which ought to
>> include a PACKAGECONFIG option.
>>
>> For example:
>>
>> PACKAGECONFIG ??= "${@base_any_contains('DISTRO_FEATURES', 'x11 wayland', 'gtk+', '', d)}"
>>
>> Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
>> ---
>>  meta/classes/utils.bbclass |  3 +++
>>  meta/lib/oe/utils.py       | 13 +++++++++++++
>>  2 files changed, 16 insertions(+)
>>
>> diff --git a/meta/classes/utils.bbclass b/meta/classes/utils.bbclass
>> index 0a533af..966eda1 100644
>> --- a/meta/classes/utils.bbclass
>> +++ b/meta/classes/utils.bbclass
>> @@ -26,6 +26,9 @@ def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
>>  def base_contains(variable, checkvalues, truevalue, falsevalue, d):
>>      return oe.utils.contains(variable, checkvalues, truevalue, falsevalue, d)
>>
>> +def base_any_contains(variable, checkvalues, truevalue, falsevalue, d):
>> +    return oe.utils.any_contains(variable, checkvalues, truevalue, falsevalue, d)
>> +
>>  def base_both_contain(variable1, variable2, checkvalue, d):
>>      return oe.utils.both_contain(variable1, variable2, checkvalue, d)
>>
>> diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
>> index defa536..029d713 100644
>> --- a/meta/lib/oe/utils.py
>> +++ b/meta/lib/oe/utils.py
>> @@ -54,6 +54,19 @@ def contains(variable, checkvalues, truevalue, falsevalue, d):
>>          return truevalue
>>      return falsevalue
>>
>> +def any_contains(variable, checkvalues, truevalue, falsevalue, d):
>> +    val = d.getVar(variable, True)
>> +    if not val:
>> +        return falsevalue
>> +    val = set(val.split())
>> +    if isinstance(checkvalues, basestring):
>> +        checkvalues = set(checkvalues.split())
>> +    else:
>> +        checkvalues = set(checkvalues)
>> +    if checkvalues in val:
>> +        return truevalue
>> +    return falsevalue
>> +
>>  def both_contain(variable1, variable2, checkvalue, d):
>>      if d.getVar(variable1,1).find(checkvalue) != -1 and d.getVar(variable2,1).find(checkvalue) != -1:
>>          return checkvalue
>
> A more logical name is perhaps containsany().
>
> I'd also add that bitbake has special support for contains() and
> optimises sstate hashes for its use. We don't have such optimisation for
> containsany(). I think this is perhaps 1.7 material at this point.

I'd use contains_any. Any problem with this?

I didn't find the place bitbake handles it. Can you point the
reference for me to look at it and complete this?
Richard Purdie - April 1, 2014, 7:07 p.m.
On Tue, 2014-04-01 at 15:38 -0300, Otavio Salvador wrote:
> On Tue, Apr 1, 2014 at 2:53 PM, Richard Purdie
> <richard.purdie@linuxfoundation.org> wrote:
> > On Tue, 2014-04-01 at 14:07 -0300, Otavio Salvador wrote:
> >> This is similar to the contains but matches any of values. This is
> >> useful to match for example several DISTRO_FEATURES which ought to
> >> include a PACKAGECONFIG option.
> >>
> >> For example:
> >>
> >> PACKAGECONFIG ??= "${@base_any_contains('DISTRO_FEATURES', 'x11 wayland', 'gtk+', '', d)}"
> >>
> >> Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
> >> ---
> >>  meta/classes/utils.bbclass |  3 +++
> >>  meta/lib/oe/utils.py       | 13 +++++++++++++
> >>  2 files changed, 16 insertions(+)
> >>
> >> diff --git a/meta/classes/utils.bbclass b/meta/classes/utils.bbclass
> >> index 0a533af..966eda1 100644
> >> --- a/meta/classes/utils.bbclass
> >> +++ b/meta/classes/utils.bbclass
> >> @@ -26,6 +26,9 @@ def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
> >>  def base_contains(variable, checkvalues, truevalue, falsevalue, d):
> >>      return oe.utils.contains(variable, checkvalues, truevalue, falsevalue, d)
> >>
> >> +def base_any_contains(variable, checkvalues, truevalue, falsevalue, d):
> >> +    return oe.utils.any_contains(variable, checkvalues, truevalue, falsevalue, d)
> >> +
> >>  def base_both_contain(variable1, variable2, checkvalue, d):
> >>      return oe.utils.both_contain(variable1, variable2, checkvalue, d)
> >>
> >> diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
> >> index defa536..029d713 100644
> >> --- a/meta/lib/oe/utils.py
> >> +++ b/meta/lib/oe/utils.py
> >> @@ -54,6 +54,19 @@ def contains(variable, checkvalues, truevalue, falsevalue, d):
> >>          return truevalue
> >>      return falsevalue
> >>
> >> +def any_contains(variable, checkvalues, truevalue, falsevalue, d):
> >> +    val = d.getVar(variable, True)
> >> +    if not val:
> >> +        return falsevalue
> >> +    val = set(val.split())
> >> +    if isinstance(checkvalues, basestring):
> >> +        checkvalues = set(checkvalues.split())
> >> +    else:
> >> +        checkvalues = set(checkvalues)
> >> +    if checkvalues in val:
> >> +        return truevalue
> >> +    return falsevalue
> >> +
> >>  def both_contain(variable1, variable2, checkvalue, d):
> >>      if d.getVar(variable1,1).find(checkvalue) != -1 and d.getVar(variable2,1).find(checkvalue) != -1:
> >>          return checkvalue
> >
> > A more logical name is perhaps containsany().
> >
> > I'd also add that bitbake has special support for contains() and
> > optimises sstate hashes for its use. We don't have such optimisation for
> > containsany(). I think this is perhaps 1.7 material at this point.
> 
> I'd use contains_any. Any problem with this?
> 
> I didn't find the place bitbake handles it. Can you point the
> reference for me to look at it and complete this?

It starts at lib/bb/codeparser.py:

   containsfuncs = ("bb.utils.contains", "base_contains", "oe.utils.contains")

and then that data gets passed around in various caches and so one and
is eventually used in the checksum dependencies.

Cheers,

Richard

Patch

diff --git a/meta/classes/utils.bbclass b/meta/classes/utils.bbclass
index 0a533af..966eda1 100644
--- a/meta/classes/utils.bbclass
+++ b/meta/classes/utils.bbclass
@@ -26,6 +26,9 @@  def base_version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
 def base_contains(variable, checkvalues, truevalue, falsevalue, d):
     return oe.utils.contains(variable, checkvalues, truevalue, falsevalue, d)
 
+def base_any_contains(variable, checkvalues, truevalue, falsevalue, d):
+    return oe.utils.any_contains(variable, checkvalues, truevalue, falsevalue, d)
+
 def base_both_contain(variable1, variable2, checkvalue, d):
     return oe.utils.both_contain(variable1, variable2, checkvalue, d)
 
diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
index defa536..029d713 100644
--- a/meta/lib/oe/utils.py
+++ b/meta/lib/oe/utils.py
@@ -54,6 +54,19 @@  def contains(variable, checkvalues, truevalue, falsevalue, d):
         return truevalue
     return falsevalue
 
+def any_contains(variable, checkvalues, truevalue, falsevalue, d):
+    val = d.getVar(variable, True)
+    if not val:
+        return falsevalue
+    val = set(val.split())
+    if isinstance(checkvalues, basestring):
+        checkvalues = set(checkvalues.split())
+    else:
+        checkvalues = set(checkvalues)
+    if checkvalues in val:
+        return truevalue
+    return falsevalue
+
 def both_contain(variable1, variable2, checkvalue, d):
     if d.getVar(variable1,1).find(checkvalue) != -1 and d.getVar(variable2,1).find(checkvalue) != -1:
         return checkvalue