utils: add compose list utilities
Utilities for generating lists from an arbitrary number of other lists.
LIST1 = "0 1"
LIST2 = "x y"
FORMAT = "str{0}-fmt{1}"
LIST3="${@compose_list(d, 'FORMAT', 'LIST1', 'LIST2')}"
results in after expansion:
LIST3="str0-fmtx str0-fmty str1-fmtx str1-fmty"
LIST1 = "0 1 2"
LIST2 = "a b c"
LIST3 = "x y z""
FORMAT = "python{0}-str{1}-fmt{2}"
LIST3="${@compose_list_zip(d, 'FORMAT', 'LIST1', 'LIST2', 'LIST3')}"
results in after expansion:
LIST3="python0-stra-fmtx python1-strb-fmty python2-strc-fmtz"
Change-Id: Ibcdbd579fa628803a279c65042303dd8336edcaf
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/meta-phosphor/classes/obmc-phosphor-utils.bbclass b/meta-phosphor/classes/obmc-phosphor-utils.bbclass
index 036af9b..b5073a6 100644
--- a/meta-phosphor/classes/obmc-phosphor-utils.bbclass
+++ b/meta-phosphor/classes/obmc-phosphor-utils.bbclass
@@ -27,3 +27,18 @@
def listvar_to_list(d, list_var, sep=' '):
return filter(bool, (d.getVar(list_var, True) or '').split(sep))
+
+
+def compose_list(d, fmtvar, *listvars, **kw):
+ import itertools
+ fmt = d.getVar(fmtvar, True)
+ lists = [listvar_to_list(d, x) for x in listvars]
+ lst = [fmt.format(*x) for x in itertools.product(*lists)]
+ return (kw.get('sep') or ' ').join(lst)
+
+
+def compose_list_zip(d, fmtvar, *listvars, **kw):
+ fmt = d.getVar(fmtvar, True)
+ lists = [listvar_to_list(d, x) for x in listvars]
+ lst = [fmt.format(*x) for x in zip(*lists)]
+ return (kw.get('sep') or ' ').join(lst)