Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Richard Purdie <richard.purdie@linuxfoundation.org>
To: openembedded-core <openembedded-core@lists.openembedded.org>
Subject: [PATCH] lib/oe/utils: 'Fix' oe.utils.contains() behaviour
Date: Mon, 25 Jul 2011 19:19:11 +0100	[thread overview]
Message-ID: <1311617951.2344.193.camel@rex> (raw)

Currently oe.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/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
index 4287eee..b3473d3 100644
--- a/meta/lib/oe/utils.py
+++ b/meta/lib/oe/utils.py
@@ -35,16 +35,15 @@ def version_less_or_equal(variable, checkvalue, truevalue, falsevalue, d):
         return falsevalue
 
 def contains(variable, checkvalues, truevalue, falsevalue, d):
-    val = bb.data.getVar(variable,d,1)
+    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
 





                 reply	other threads:[~2011-07-25 18:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1311617951.2344.193.camel@rex \
    --to=richard.purdie@linuxfoundation.org \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox