blob: 713c892fb431325b0f556363964646623fcaa658 [file] [log] [blame]
Brad Bishop93fb5352015-09-09 03:59:20 +00001# Helper functions for checking feature variables.
2
3inherit utils
4
Brad Bishop01fecbf2016-07-10 19:44:42 -04005
Brad Bishopb943d912017-01-31 10:37:13 -05006def df_enabled(d, feature, truevalue, falsevalue=""):
7 return base_contains("DISTRO_FEATURES", feature, truevalue, falsevalue, d)
Brad Bishop01fecbf2016-07-10 19:44:42 -04008
Brad Bishop93fb5352015-09-09 03:59:20 +00009
Brad Bishopb943d912017-01-31 10:37:13 -050010def mf_enabled(d, feature, truevalue, falsevalue=""):
11 return base_contains("MACHINE_FEATURES", feature, truevalue, falsevalue, d)
Brad Bishop01fecbf2016-07-10 19:44:42 -040012
Brad Bishop93fb5352015-09-09 03:59:20 +000013
Brad Bishopb943d912017-01-31 10:37:13 -050014def cf_enabled(d, feature, truevalue, falsevalue=""):
15 return truevalue if df_enabled(d, feature, truevalue) \
16 and mf_enabled(d, feature, truevalue) \
17 else falsevalue
Brad Bishopbfef6ff2016-07-07 15:56:02 -040018
19
20def set_append(d, var, val, sep=' '):
21 values = (d.getVar(var, True) or '').split(sep)
22 if filter(bool, values):
23 d.appendVar(var, '%s%s' %(sep, val))
24 else:
25 d.setVar(var, val)
26
27
28def listvar_to_list(d, list_var, sep=' '):
29 return filter(bool, (d.getVar(list_var, True) or '').split(sep))
Brad Bishop1c7de872016-08-24 14:08:35 -040030
31
32def compose_list(d, fmtvar, *listvars, **kw):
33 import itertools
34 fmt = d.getVar(fmtvar, True)
35 lists = [listvar_to_list(d, x) for x in listvars]
36 lst = [fmt.format(*x) for x in itertools.product(*lists)]
37 return (kw.get('sep') or ' ').join(lst)
38
39
40def compose_list_zip(d, fmtvar, *listvars, **kw):
41 fmt = d.getVar(fmtvar, True)
42 lists = [listvar_to_list(d, x) for x in listvars]
43 lst = [fmt.format(*x) for x in zip(*lists)]
44 return (kw.get('sep') or ' ').join(lst)