blob: ee48950a823379999e8e060452ee23f77358a030 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001import oe.maketype
2
3def typed_value(key, d):
4 """Construct a value for the specified metadata variable, using its flags
5 to determine the type and parameters for construction."""
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05006 var_type = d.getVarFlag(key, 'type', True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007 flags = d.getVarFlags(key)
8 if flags is not None:
9 flags = dict((flag, d.expand(value))
Patrick Williamsc0f7c042017-02-23 20:41:17 -060010 for flag, value in list(flags.items()))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011 else:
12 flags = {}
13
14 try:
15 return oe.maketype.create(d.getVar(key, True) or '', var_type, **flags)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060016 except (TypeError, ValueError) as exc:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050017 bb.msg.fatal("Data", "%s: %s" % (key, str(exc)))