bitbake/utils: 'Fix' bb.utils.contains() behaviour
PATCH 1/1 bitbake/utils: 'Fix' bb.utils.contains() behaviour
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.
---
lib/bb/utils.py +6 -7
@@ -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
Quoted 8 lines · Richard Purdie
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.
Quoted 4 lines
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 <[email protected]>
Quoted 31 lines
---
lib/bb/utils.py +6
-7@@ -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
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/bitbake-devel
Signature · 3 lines
Joshua Lock
Yocto Project "Johannes factotum"
Intel Open Source Technology Centre