summaryrefslogtreecommitdiff
path: root/scripts/lib/wic/utils
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2015-06-26 21:27:31 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-07-02 23:01:17 +0100
commit3abe23bd217315246ec2d98dc9c390b85cfe6a92 (patch)
tree088fc8e061b3008d9ceab7b52175148243e259c2 /scripts/lib/wic/utils
parent8becfc2281282a2e63b3bf511936df36315c9cb1 (diff)
downloadopenembedded-core-3abe23bd217315246ec2d98dc9c390b85cfe6a92.tar.gz
openembedded-core-3abe23bd217315246ec2d98dc9c390b85cfe6a92.tar.bz2
openembedded-core-3abe23bd217315246ec2d98dc9c390b85cfe6a92.zip
wic: Refactor getting bitbake variables
Wic gets bitbake variables by parsing output of 'bitbake -e' command. This implementation improves this procedure as it runs 'bitbake -e' only when API is called and does it only once, i.e. in a "lazy" way. As parsing results are cached 'bitbake -e' is run only once and results are parsed only once per requested set of variables. get_bitbake_var became the only API call. It replaces find_artifacts, find_artifact, find_bitbake_env_lines, get_bitbake_env_lines, set_bitbake_env_lines and get_line_val calls making API much more clear. Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Diffstat (limited to 'scripts/lib/wic/utils')
-rw-r--r--scripts/lib/wic/utils/oe/misc.py82
1 files changed, 30 insertions, 52 deletions
diff --git a/scripts/lib/wic/utils/oe/misc.py b/scripts/lib/wic/utils/oe/misc.py
index 2f916ddf45..1de6f46a38 100644
--- a/scripts/lib/wic/utils/oe/misc.py
+++ b/scripts/lib/wic/utils/oe/misc.py
@@ -25,6 +25,8 @@
# Tom Zanussi <tom.zanussi (at] linux.intel.com>
#
+from collections import defaultdict
+
from wic import msger
from wic.utils import runner
@@ -108,62 +110,38 @@ def add_wks_var(key, val):
BOOTDD_EXTRA_SPACE = 16384
-__bitbake_env_lines = ""
-
-def set_bitbake_env_lines(bitbake_env_lines):
- global __bitbake_env_lines
- __bitbake_env_lines = bitbake_env_lines
+_BITBAKE_VARS = defaultdict(dict)
-def get_bitbake_env_lines():
- return __bitbake_env_lines
-
-def find_bitbake_env_lines(image_name):
- """
- If image_name is empty, plugins might still be able to use the
- environment, so set it regardless.
+def get_bitbake_var(var, image=None):
"""
- if image_name:
- bitbake_env_cmd = "bitbake -e %s" % image_name
- else:
- bitbake_env_cmd = "bitbake -e"
- rc, bitbake_env_lines = __exec_cmd(bitbake_env_cmd)
- if rc != 0:
- print "Couldn't get '%s' output." % bitbake_env_cmd
- print "Bitbake failed with error:\n%s\n" % bitbake_env_lines
- return None
-
- return bitbake_env_lines
-
-def find_artifact(bitbake_env_lines, variable):
+ Get bitbake variable value lazy way, i.e. run
+ 'bitbake -e' only when variable is requested.
"""
- Gather the build artifact for the current image (the image_name
- e.g. core-image-minimal) for the current MACHINE set in local.conf
- """
- retval = ""
-
- for line in bitbake_env_lines.split('\n'):
- if get_line_val(line, variable):
- retval = get_line_val(line, variable)
- break
-
- return retval
+ if image not in _BITBAKE_VARS:
+ # Get bitbake -e output
+ cmd = "bitbake -e"
+ if image:
+ cmd += " %s" % image
+ rc, lines = __exec_cmd(cmd)
+ if rc:
+ 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('"')
-def get_line_val(line, key):
- """
- Extract the value from the VAR="val" string
- """
- if line.startswith(key + "="):
- stripped_line = line.split('=')[1]
- stripped_line = stripped_line.replace('\"', '')
- return stripped_line
- return None
-
-def get_bitbake_var(key):
- for line in __bitbake_env_lines.split('\n'):
- if get_line_val(line, key):
- val = get_line_val(line, key)
- return val
- return None
+ return _BITBAKE_VARS[image].get(var)
def parse_sourceparams(sourceparams):
"""