* [PATCH] bitbake/utils: 'Fix' bb.utils.contains() behaviour
@ 2011-07-25 18:19 Richard Purdie
2011-07-26 3:20 ` Joshua Lock
0 siblings, 1 reply; 2+ messages in thread
From: Richard Purdie @ 2011-07-25 18:19 UTC (permalink / raw)
To: bitbake-devel
Currently bb.utils.contains(X, "A", true, false) will return true for substring matches,
e.g. if X = "ABC". This is not what most users expect from the function.
In the common OE use of this function there is the case of "touchscreen" and "screen" being
used as independent variables. Whilst it could be argued there isn't a problem in that
specific case (touchscreens are usually on screens), there is no substring usage of this
function is OE-Core so this patch changes the behaviour to match only full strings.
It also fixes a bug where duplicate entries would confuse multiple matches, e.g.
contains(X, ["A", "B"], ...) would match X = "A A" which is clearly wrong.
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 075ca88..4eac285 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -861,12 +861,11 @@ def contains(variable, checkvalues, truevalue, falsevalue, d):
val = d.getVar(variable, True)
if not val:
return falsevalue
- matches = 0
- if type(checkvalues).__name__ == "str":
- checkvalues = [checkvalues]
- for value in checkvalues:
- if val.find(value) != -1:
- matches = matches + 1
- if matches == len(checkvalues):
+ val = set(val.split())
+ if isinstance(checkvalues, basestring):
+ checkvalues = set(checkvalues.split())
+ else:
+ checkvalues = set(checkvalues)
+ if checkvalues.issubset(val):
return truevalue
return falsevalue
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] bitbake/utils: 'Fix' bb.utils.contains() behaviour
2011-07-25 18:19 [PATCH] bitbake/utils: 'Fix' bb.utils.contains() behaviour Richard Purdie
@ 2011-07-26 3:20 ` Joshua Lock
0 siblings, 0 replies; 2+ messages in thread
From: Joshua Lock @ 2011-07-26 3:20 UTC (permalink / raw)
To: bitbake-devel
On Mon, 2011-07-25 at 19:19 +0100, Richard Purdie wrote:
> Currently bb.utils.contains(X, "A", true, false) will return true for substring matches,
> e.g. if X = "ABC". This is not what most users expect from the function.
>
> In the common OE use of this function there is the case of "touchscreen" and "screen" being
> used as independent variables. Whilst it could be argued there isn't a problem in that
> specific case (touchscreens are usually on screens), there is no substring usage of this
> function is OE-Core so this patch changes the behaviour to match only full strings.
>
> It also fixes a bug where duplicate entries would confuse multiple matches, e.g.
> contains(X, ["A", "B"], ...) would match X = "A A" which is clearly wrong.
>
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Joshua Lock <josh@linux.intel.com>
> ---
> diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
> index 075ca88..4eac285 100644
> --- a/lib/bb/utils.py
> +++ b/lib/bb/utils.py
> @@ -861,12 +861,11 @@ def contains(variable, checkvalues, truevalue, falsevalue, d):
> val = d.getVar(variable, True)
> if not val:
> return falsevalue
> - matches = 0
> - if type(checkvalues).__name__ == "str":
> - checkvalues = [checkvalues]
> - for value in checkvalues:
> - if val.find(value) != -1:
> - matches = matches + 1
> - if matches == len(checkvalues):
> + val = set(val.split())
> + if isinstance(checkvalues, basestring):
> + checkvalues = set(checkvalues.split())
> + else:
> + checkvalues = set(checkvalues)
> + if checkvalues.issubset(val):
> return truevalue
> return falsevalue
>
>
>
> _______________________________________________
> bitbake-devel mailing list
> bitbake-devel@lists.openembedded.org
> http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/bitbake-devel
--
Joshua Lock
Yocto Project "Johannes factotum"
Intel Open Source Technology Centre
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-07-26 3:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-07-25 18:19 [PATCH] bitbake/utils: 'Fix' bb.utils.contains() behaviour Richard Purdie
2011-07-26 3:20 ` Joshua Lock
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox