summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/utils.py
diff options
context:
space:
mode:
authorPeter Kjellerstedt <peter.kjellerstedt@axis.com>2017-02-21 16:18:59 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-03-01 11:16:07 +0000
commit3004f57a25514926a0c688d333ea6e6ae3486acc (patch)
treec6817d03061319dc68c2404fa7091b5ca5693b49 /bitbake/lib/bb/utils.py
parent8dd99c15af88a1c52b28347c85d443ae6b1f678d (diff)
downloadpoky-3004f57a25514926a0c688d333ea6e6ae3486acc.tar.gz
bitbake: lib/bb/utils: Add filter()
The bb.utils.filter() function can be used to filter a variable containing whitespace separated words based on another set of words. It has been modeled after the bb.utils.contains_any() function. A typical example of how it can be used is to simplify constructs for PACKAGECONFIG that depend on DISTRO_FEATURES: -PACKAGECONFIG ?= "\ - ${@bb.utils.contains('DISTRO_FEATURES', 'acl', 'acl', '', d)} \ - ${@bb.utils.contains('DISTRO_FEATURES', 'selinux', 'selinux', '', d)} \ -" +PACKAGECONFIG ?= "${@bb.utils.filter('DISTRO_FEATURES', 'acl selinux', d)}" (Bitbake rev: 03ae490366d2046f5b5c185fe4ec2adf1b0a902e) Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/utils.py')
-rw-r--r--bitbake/lib/bb/utils.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/bitbake/lib/bb/utils.py b/bitbake/lib/bb/utils.py
index 2845126293..d6bcfa37e8 100644
--- a/bitbake/lib/bb/utils.py
+++ b/bitbake/lib/bb/utils.py
@@ -979,6 +979,30 @@ def contains_any(variable, checkvalues, truevalue, falsevalue, d):
979 return truevalue 979 return truevalue
980 return falsevalue 980 return falsevalue
981 981
982def filter(variable, checkvalues, d):
983 """Return all words in the variable that are present in the checkvalues.
984
985 Arguments:
986
987 variable -- the variable name. This will be fetched and expanded (using
988 d.getVar(variable)) and then split into a set().
989
990 checkvalues -- if this is a string it is split on whitespace into a set(),
991 otherwise coerced directly into a set().
992
993 d -- the data store.
994 """
995
996 val = d.getVar(variable)
997 if not val:
998 return ''
999 val = set(val.split())
1000 if isinstance(checkvalues, str):
1001 checkvalues = set(checkvalues.split())
1002 else:
1003 checkvalues = set(checkvalues)
1004 return ' '.join(sorted(checkvalues & val))
1005
982def cpu_count(): 1006def cpu_count():
983 return multiprocessing.cpu_count() 1007 return multiprocessing.cpu_count()
984 1008