blob: 04db8bcd016c2cc4ce4956494e4683487d0e0a9a [file] [log] [blame]
Brad Bishop93fb5352015-09-09 03:59:20 +00001# Helper functions for checking feature variables.
2
Brad Bishop961df762017-01-31 10:37:13 -05003def df_enabled(d, feature, truevalue, falsevalue=""):
Saqib Khan46fd3712017-03-07 07:20:20 -06004 return bb.utils.contains("DISTRO_FEATURES", feature, truevalue, falsevalue, d)
Brad Bishop6ba6a512016-07-10 19:44:42 -04005
Brad Bishop93fb5352015-09-09 03:59:20 +00006
Brad Bishop961df762017-01-31 10:37:13 -05007def mf_enabled(d, feature, truevalue, falsevalue=""):
Saqib Khan46fd3712017-03-07 07:20:20 -06008 return bb.utils.contains("MACHINE_FEATURES", feature, truevalue, falsevalue, d)
Brad Bishop6ba6a512016-07-10 19:44:42 -04009
Brad Bishop93fb5352015-09-09 03:59:20 +000010
Brad Bishop961df762017-01-31 10:37:13 -050011def 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 Bishop9dc56712016-07-07 15:56:02 -040015
16
17def 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
25def listvar_to_list(d, list_var, sep=' '):
Saqib Khandc2090d2017-03-07 07:05:56 -060026 return list(filter(bool, (d.getVar(list_var, True) or '').split(sep)))
Brad Bishop167aaae2016-08-24 14:08:35 -040027
28
29def 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
37def 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 Joseph1562bbcb2017-02-20 12:01:43 +053042
43
44def append_suffix(val, suffix):
45 words = val.split(' ')
46 newval = []
47 for w in words:
48 newval.append(w + suffix)
Saqib Khandc2090d2017-03-07 07:05:56 -060049 return ' '.join(newval)