summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/utils/oe/misc.py
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:08:36 +0100
commitaa470a1fcd09abbc570d3d885aff460603ef9925 (patch)
treef04cc1fe57fa3a1310ce8c7cab3cd213d5b7c6a1 /scripts/lib/wic/utils/oe/misc.py
parent673343414f4c9db32e3e0c58f07c59954bab734c (diff)
downloadpoky-aa470a1fcd09abbc570d3d885aff460603ef9925.tar.gz
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. (From OE-Core rev: 3abe23bd217315246ec2d98dc9c390b85cfe6a92) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/wic/utils/oe/misc.py')
-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 @@
25# Tom Zanussi <tom.zanussi (at] linux.intel.com> 25# Tom Zanussi <tom.zanussi (at] linux.intel.com>
26# 26#
27 27
28from collections import defaultdict
29
28from wic import msger 30from wic import msger
29from wic.utils import runner 31from wic.utils import runner
30 32
@@ -108,62 +110,38 @@ def add_wks_var(key, val):
108 110
109BOOTDD_EXTRA_SPACE = 16384 111BOOTDD_EXTRA_SPACE = 16384
110 112
111__bitbake_env_lines = "" 113_BITBAKE_VARS = defaultdict(dict)
112
113def set_bitbake_env_lines(bitbake_env_lines):
114 global __bitbake_env_lines
115 __bitbake_env_lines = bitbake_env_lines
116 114
117def get_bitbake_env_lines(): 115def get_bitbake_var(var, image=None):
118 return __bitbake_env_lines
119
120def find_bitbake_env_lines(image_name):
121 """
122 If image_name is empty, plugins might still be able to use the
123 environment, so set it regardless.
124 """ 116 """
125 if image_name: 117 Get bitbake variable value lazy way, i.e. run
126 bitbake_env_cmd = "bitbake -e %s" % image_name 118 'bitbake -e' only when variable is requested.
127 else:
128 bitbake_env_cmd = "bitbake -e"
129 rc, bitbake_env_lines = __exec_cmd(bitbake_env_cmd)
130 if rc != 0:
131 print "Couldn't get '%s' output." % bitbake_env_cmd
132 print "Bitbake failed with error:\n%s\n" % bitbake_env_lines
133 return None
134
135 return bitbake_env_lines
136
137def find_artifact(bitbake_env_lines, variable):
138 """ 119 """
139 Gather the build artifact for the current image (the image_name 120 if image not in _BITBAKE_VARS:
140 e.g. core-image-minimal) for the current MACHINE set in local.conf 121 # Get bitbake -e output
141 """ 122 cmd = "bitbake -e"
142 retval = "" 123 if image:
143 124 cmd += " %s" % image
144 for line in bitbake_env_lines.split('\n'): 125 rc, lines = __exec_cmd(cmd)
145 if get_line_val(line, variable): 126 if rc:
146 retval = get_line_val(line, variable) 127 print "Couldn't get '%s' output." % cmd
147 break 128 print "Bitbake failed with error:\n%s\n" % lines
148 129 return
149 return retval 130
131 # Parse bitbake -e output
132 for line in lines.split('\n'):
133 if "=" not in line:
134 continue
135 try:
136 key, val = line.split("=")
137 except ValueError:
138 continue
139 key = key.strip()
140 val = val.strip()
141 if key.replace('_', '').isalnum():
142 _BITBAKE_VARS[image][key] = val.strip('"')
150 143
151def get_line_val(line, key): 144 return _BITBAKE_VARS[image].get(var)
152 """
153 Extract the value from the VAR="val" string
154 """
155 if line.startswith(key + "="):
156 stripped_line = line.split('=')[1]
157 stripped_line = stripped_line.replace('\"', '')
158 return stripped_line
159 return None
160
161def get_bitbake_var(key):
162 for line in __bitbake_env_lines.split('\n'):
163 if get_line_val(line, key):
164 val = get_line_val(line, key)
165 return val
166 return None
167 145
168def parse_sourceparams(sourceparams): 146def parse_sourceparams(sourceparams):
169 """ 147 """