Brad Bishop | 93fb535 | 2015-09-09 03:59:20 +0000 | [diff] [blame] | 1 | # Helper functions for checking feature variables. |
| 2 | |
Brad Bishop | 961df76 | 2017-01-31 10:37:13 -0500 | [diff] [blame] | 3 | def df_enabled(d, feature, truevalue, falsevalue=""): |
Saqib Khan | 46fd371 | 2017-03-07 07:20:20 -0600 | [diff] [blame] | 4 | return bb.utils.contains("DISTRO_FEATURES", feature, truevalue, falsevalue, d) |
Brad Bishop | 6ba6a51 | 2016-07-10 19:44:42 -0400 | [diff] [blame] | 5 | |
Brad Bishop | 93fb535 | 2015-09-09 03:59:20 +0000 | [diff] [blame] | 6 | |
Brad Bishop | 961df76 | 2017-01-31 10:37:13 -0500 | [diff] [blame] | 7 | def mf_enabled(d, feature, truevalue, falsevalue=""): |
Saqib Khan | 46fd371 | 2017-03-07 07:20:20 -0600 | [diff] [blame] | 8 | return bb.utils.contains("MACHINE_FEATURES", feature, truevalue, falsevalue, d) |
Brad Bishop | 6ba6a51 | 2016-07-10 19:44:42 -0400 | [diff] [blame] | 9 | |
Brad Bishop | 93fb535 | 2015-09-09 03:59:20 +0000 | [diff] [blame] | 10 | |
Brad Bishop | 961df76 | 2017-01-31 10:37:13 -0500 | [diff] [blame] | 11 | def cf_enabled(d, feature, truevalue, falsevalue=""): |
| 12 | return truevalue if df_enabled(d, feature, truevalue) \ |
| 13 | and mf_enabled(d, feature, truevalue) \ |
| 14 | else falsevalue |
Brad Bishop | 9dc5671 | 2016-07-07 15:56:02 -0400 | [diff] [blame] | 15 | |
| 16 | |
| 17 | def set_append(d, var, val, sep=' '): |
| 18 | values = (d.getVar(var, True) or '').split(sep) |
| 19 | if filter(bool, values): |
| 20 | d.appendVar(var, '%s%s' %(sep, val)) |
| 21 | else: |
| 22 | d.setVar(var, val) |
| 23 | |
| 24 | |
| 25 | def listvar_to_list(d, list_var, sep=' '): |
Saqib Khan | dc2090d | 2017-03-07 07:05:56 -0600 | [diff] [blame] | 26 | return list(filter(bool, (d.getVar(list_var, True) or '').split(sep))) |
Brad Bishop | 167aaae | 2016-08-24 14:08:35 -0400 | [diff] [blame] | 27 | |
| 28 | |
| 29 | def compose_list(d, fmtvar, *listvars, **kw): |
| 30 | import itertools |
| 31 | fmt = d.getVar(fmtvar, True) |
| 32 | lists = [listvar_to_list(d, x) for x in listvars] |
| 33 | lst = [fmt.format(*x) for x in itertools.product(*lists)] |
| 34 | return (kw.get('sep') or ' ').join(lst) |
| 35 | |
| 36 | |
| 37 | def compose_list_zip(d, fmtvar, *listvars, **kw): |
| 38 | fmt = d.getVar(fmtvar, True) |
| 39 | lists = [listvar_to_list(d, x) for x in listvars] |
| 40 | lst = [fmt.format(*x) for x in zip(*lists)] |
| 41 | return (kw.get('sep') or ' ').join(lst) |
Tom Joseph | 1562bbc | 2017-02-20 12:01:43 +0530 | [diff] [blame] | 42 | |
| 43 | |
| 44 | def append_suffix(val, suffix): |
| 45 | words = val.split(' ') |
| 46 | newval = [] |
| 47 | for w in words: |
| 48 | newval.append(w + suffix) |
Saqib Khan | dc2090d | 2017-03-07 07:05:56 -0600 | [diff] [blame] | 49 | return ' '.join(newval) |