summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2015-08-30 20:47:04 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-08-30 21:38:22 +0100
commit5856f8ff968a7c7688c340881d56cfb2bf3869e3 (patch)
tree7cf8f054f34d9bbd1f2064501c154cbfc642f980 /scripts
parentd80ad239e338f025a30ba2910bf58800761f234d (diff)
downloadpoky-5856f8ff968a7c7688c340881d56cfb2bf3869e3.tar.gz
wic: implement getting variables from .env files
Added functionality of getting variables from <image>.env files to BitbakeVars class. env files will be parsed if the directory with env files is known, i.e. when vars_dir attribute is set. Otherwise 'bitbake -e' output will be parsed. (From OE-Core rev: d21e4c1e56cab750ed4f6031d7f3dc5775a2c2cc) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/wic/utils/oe/misc.py59
1 files changed, 37 insertions, 22 deletions
diff --git a/scripts/lib/wic/utils/oe/misc.py b/scripts/lib/wic/utils/oe/misc.py
index 040176d486..0a8f3f120e 100644
--- a/scripts/lib/wic/utils/oe/misc.py
+++ b/scripts/lib/wic/utils/oe/misc.py
@@ -26,6 +26,7 @@
26# 26#
27"""Miscellaneous functions.""" 27"""Miscellaneous functions."""
28 28
29import os
29from collections import defaultdict 30from collections import defaultdict
30 31
31from wic import msger 32from wic import msger
@@ -131,12 +132,13 @@ class BitbakeVars(defaultdict):
131 def __init__(self): 132 def __init__(self):
132 defaultdict.__init__(self, dict) 133 defaultdict.__init__(self, dict)
133 134
134 # default_image attribute should be set from outside 135 # default_image and vars_dir attributes should be set from outside
135 self.default_image = None 136 self.default_image = None
137 self.vars_dir = None
136 138
137 def _parse_line(self, line, image): 139 def _parse_line(self, line, image):
138 """ 140 """
139 Parse one line from bitbake -e output. 141 Parse one line from bitbake -e output or from .env file.
140 Put result key-value pair into the storage. 142 Put result key-value pair into the storage.
141 """ 143 """
142 if "=" not in line: 144 if "=" not in line:
@@ -152,31 +154,44 @@ class BitbakeVars(defaultdict):
152 154
153 def get_var(self, var, image=None): 155 def get_var(self, var, image=None):
154 """ 156 """
155 Get bitbake variable value lazy way, i.e. run 157 Get bitbake variable from 'bitbake -e' output or from .env file.
156 'bitbake -e' only when variable is requested. 158 This is a lazy method, i.e. it runs bitbake or parses file only when
159 only when variable is requested. It also caches results.
157 """ 160 """
158 if not image: 161 if not image:
159 image = self.default_image 162 image = self.default_image
160 163
161 if image not in self: 164 if image not in self:
162 # Get bitbake -e output 165 if image and self.vars_dir:
163 cmd = "bitbake -e" 166 fname = os.path.join(self.vars_dir, image + '.env')
164 if image: 167 if os.path.isfile(fname):
165 cmd += " %s" % image 168 # parse .env file
166 169 with open(fname) as varsfile:
167 log_level = msger.get_loglevel() 170 for line in varsfile:
168 msger.set_loglevel('normal') 171 self._parse_line(line, image)
169 ret, lines = _exec_cmd(cmd) 172 else:
170 msger.set_loglevel(log_level) 173 print "Couldn't get bitbake variable from %s." % fname
171 174 print "File %s doesn't exist." % fname
172 if ret: 175 return
173 print "Couldn't get '%s' output." % cmd 176 else:
174 print "Bitbake failed with error:\n%s\n" % lines 177 # Get bitbake -e output
175 return 178 cmd = "bitbake -e"
176 179 if image:
177 # Parse bitbake -e output 180 cmd += " %s" % image
178 for line in lines.split('\n'): 181
179 self._parse_line(line, image) 182 log_level = msger.get_loglevel()
183 msger.set_loglevel('normal')
184 ret, lines = _exec_cmd(cmd)
185 msger.set_loglevel(log_level)
186
187 if ret:
188 print "Couldn't get '%s' output." % cmd
189 print "Bitbake failed with error:\n%s\n" % lines
190 return
191
192 # Parse bitbake -e output
193 for line in lines.split('\n'):
194 self._parse_line(line, image)
180 195
181 # Make first image a default set of variables 196 # Make first image a default set of variables
182 images = [key for key in self if key] 197 images = [key for key in self if key]