1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-30 00:20:08 +00:00

wic: add BitbakeVars class

Moved code of getting bitbake variables into separate class.

Created singleton object of this class in the module namespace.

Preserved existing API get_bitbake_var.

(From OE-Core rev: 3229d37993e315c9ca1902849746b9f50f35845c)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ed Bartosh
2015-08-30 20:47:00 +03:00
committed by Richard Purdie
parent 92c3f03b79
commit 58c393022f
+53 -38
View File
@@ -124,48 +124,63 @@ def exec_native_cmd(cmd_and_args, native_sysroot, catch=3):
BOOTDD_EXTRA_SPACE = 16384
_BITBAKE_VARS = defaultdict(dict)
class BitbakeVars(defaultdict):
"""
Container for Bitbake variables.
"""
def __init__(self):
defaultdict.__init__(self, dict)
def get_var(self, var, image=None):
"""
Get bitbake variable value lazy way, i.e. run
'bitbake -e' only when variable is requested.
"""
if image not in self:
# Get bitbake -e output
cmd = "bitbake -e"
if image:
cmd += " %s" % image
log_level = msger.get_loglevel()
msger.set_loglevel('normal')
ret, lines = _exec_cmd(cmd)
msger.set_loglevel(log_level)
if ret:
print "Couldn't get '%s' output." % cmd
print "Bitbake failed with error:\n%s\n" % lines
return
# Parse bitbake -e output
for line in lines.split('\n'):
if "=" not in line:
continue
try:
key, val = line.split("=")
except ValueError:
continue
key = key.strip()
val = val.strip()
if key.replace('_', '').isalnum():
self[image][key] = val.strip('"')
# Make first image a default set of variables
images = [key for key in self if key]
if len(images) == 1:
self[None] = self[image]
return self[image].get(var)
# Create BB_VARS singleton
BB_VARS = BitbakeVars()
def get_bitbake_var(var, image=None):
"""
Get bitbake variable value lazy way, i.e. run
'bitbake -e' only when variable is requested.
Provide old get_bitbake_var API by wrapping
get_var method of BB_VARS singleton.
"""
if image not in _BITBAKE_VARS:
# Get bitbake -e output
cmd = "bitbake -e"
if image:
cmd += " %s" % image
log_level = msger.get_loglevel()
msger.set_loglevel('normal')
ret, lines = _exec_cmd(cmd)
msger.set_loglevel(log_level)
if ret:
print "Couldn't get '%s' output." % cmd
print "Bitbake failed with error:\n%s\n" % lines
return
# Parse bitbake -e output
for line in lines.split('\n'):
if "=" not in line:
continue
try:
key, val = line.split("=")
except ValueError:
continue
key = key.strip()
val = val.strip()
if key.replace('_', '').isalnum():
_BITBAKE_VARS[image][key] = val.strip('"')
# Make first image a default set of variables
images = [key for key in _BITBAKE_VARS if key]
if len(images) == 1:
_BITBAKE_VARS[None] = _BITBAKE_VARS[image]
return _BITBAKE_VARS[image].get(var)
return BB_VARS.get_var(var, image)
def parse_sourceparams(sourceparams):
"""