diff options
author | Peter Kjellerstedt <peter.kjellerstedt@axis.com> | 2017-02-21 16:18:59 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-02-24 13:13:59 -0800 |
commit | 03ae490366d2046f5b5c185fe4ec2adf1b0a902e (patch) | |
tree | c50a13a44c1c6ce09341bd41573f992a0bc5a91b /lib/bb/utils.py | |
parent | c55e09fbd2b64a2b909d9992350b6b2e26e5e86d (diff) | |
download | bitbake-03ae490366d2046f5b5c185fe4ec2adf1b0a902e.tar.gz |
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)}"
Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/utils.py')
-rw-r--r-- | lib/bb/utils.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/bb/utils.py b/lib/bb/utils.py index 284512629..d6bcfa37e 100644 --- a/lib/bb/utils.py +++ b/lib/bb/utils.py @@ -979,6 +979,30 @@ def contains_any(variable, checkvalues, truevalue, falsevalue, d): return truevalue return falsevalue +def filter(variable, checkvalues, d): + """Return all words in the variable that are present in the checkvalues. + + Arguments: + + variable -- the variable name. This will be fetched and expanded (using + d.getVar(variable)) and then split into a set(). + + checkvalues -- if this is a string it is split on whitespace into a set(), + otherwise coerced directly into a set(). + + d -- the data store. + """ + + val = d.getVar(variable) + if not val: + return '' + val = set(val.split()) + if isinstance(checkvalues, str): + checkvalues = set(checkvalues.split()) + else: + checkvalues = set(checkvalues) + return ' '.join(sorted(checkvalues & val)) + def cpu_count(): return multiprocessing.cpu_count() |