Patchwork [bitbake-devel,2/2] bb.utils, bb.codeparser: Add bb.utils.contains_any

login
register
mail settings
Submitter Otavio Salvador
Date April 25, 2014, 9:21 p.m.
Message ID <1398460884-26033-2-git-send-email-otavio@ossystems.com.br>
Download mbox | patch
Permalink /patch/70993/
State New
Headers show

Comments

Otavio Salvador - April 25, 2014, 9:21 p.m.
This includes contains_any in the special handling code for sstate. It
does not take into account the equivalence of the values. In current
code, considering 'bb.utils.contains_any("A", "foo bar", ...)':

A = "foo"
A = "bar"
A = "foo bar"

All those will get different signatures.

Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
---
 lib/bb/codeparser.py |  3 ++-
 lib/bb/utils.py      | 13 +++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

Patch

diff --git a/lib/bb/codeparser.py b/lib/bb/codeparser.py
index b4b1013..58e0016 100644
--- a/lib/bb/codeparser.py
+++ b/lib/bb/codeparser.py
@@ -103,7 +103,8 @@  class BufferedLogger(Logger):
 
 class PythonParser():
     getvars = ("d.getVar", "bb.data.getVar", "data.getVar", "d.appendVar", "d.prependVar")
-    containsfuncs = ("bb.utils.contains", "base_contains")
+    containsfuncs = ("bb.utils.contains", "base_contains",
+                     "bb.utils.contains_any", "base_contains_any")
     execfuncs = ("bb.build.exec_func", "bb.build.exec_task")
 
     def warn(self, func, arg):
diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 0be45e1..1be1874 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -845,6 +845,19 @@  def contains(variable, checkvalues, truevalue, falsevalue, d):
         return truevalue
     return falsevalue
 
+def contains_any(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 cpu_count():
     return multiprocessing.cpu_count()