summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/ui/crumbs/configurator.py
diff options
context:
space:
mode:
authorJoshua Lock <josh@linux.intel.com>2011-09-01 20:38:10 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-09-05 20:25:41 +0100
commitcffbab5c0671005072db3e8f577fa3ffb1e2cd68 (patch)
tree4cda95ea411c1904ef0f2e6c4fa7f2140be9b590 /bitbake/lib/bb/ui/crumbs/configurator.py
parentba91445de50ed4a4a947948631fdd36a0e3e145d (diff)
downloadpoky-cffbab5c0671005072db3e8f577fa3ffb1e2cd68.tar.gz
hob: use both pre and post files for hob configuration
We need to set various variables *before* parse begins, the simplest way to ensure this is to use a pre configuration file for the relevant configuration entries. This series adapts hob to use both pre and post files to store its configuration. Any variables which affect initial parse are set in the pre file and all others in the post file. Unfortunately this requires hob related code to have even more hard-coded data as to what is relevant but this is the simplest way to solve issues with variables and parse order at this time. Addresses [YOCTO #1281] (Bitbake rev: 02ab0e11d8dd42f5ca440b3d8d2073e23f55113a) Signed-off-by: Joshua Lock <josh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/ui/crumbs/configurator.py')
-rw-r--r--bitbake/lib/bb/ui/crumbs/configurator.py94
1 files changed, 63 insertions, 31 deletions
diff --git a/bitbake/lib/bb/ui/crumbs/configurator.py b/bitbake/lib/bb/ui/crumbs/configurator.py
index c37e9175ea..458e05626d 100644
--- a/bitbake/lib/bb/ui/crumbs/configurator.py
+++ b/bitbake/lib/bb/ui/crumbs/configurator.py
@@ -40,12 +40,13 @@ class Configurator(gobject.GObject):
40 40
41 def __init__(self): 41 def __init__(self):
42 gobject.GObject.__init__(self) 42 gobject.GObject.__init__(self)
43 self.local = None
44 self.bblayers = None 43 self.bblayers = None
45 self.enabled_layers = {} 44 self.enabled_layers = {}
46 self.loaded_layers = {} 45 self.loaded_layers = {}
47 self.config = {} 46 self.config = {}
48 self.orig_config = {} 47 self.orig_config = {}
48 self.preconf = None
49 self.postconf = None
49 50
50 # NOTE: cribbed from the cooker... 51 # NOTE: cribbed from the cooker...
51 def _parse(self, f, data, include=False): 52 def _parse(self, f, data, include=False):
@@ -55,18 +56,16 @@ class Configurator(gobject.GObject):
55 parselog.critical("Unable to parse %s: %s" % (f, exc)) 56 parselog.critical("Unable to parse %s: %s" % (f, exc))
56 sys.exit(1) 57 sys.exit(1)
57 58
58 def _loadLocalConf(self, path): 59 def _loadConf(self, path):
59 def getString(var): 60 def getString(var):
60 return bb.data.getVar(var, data, True) or "" 61 return bb.data.getVar(var, data, True) or ""
61 62
62 self.local = path
63
64 if self.orig_config: 63 if self.orig_config:
65 del self.orig_config 64 del self.orig_config
66 self.orig_config = {} 65 self.orig_config = {}
67 66
68 data = bb.data.init() 67 data = bb.data.init()
69 data = self._parse(self.local, data) 68 data = self._parse(path, data)
70 69
71 # We only need to care about certain variables 70 # We only need to care about certain variables
72 mach = getString('MACHINE') 71 mach = getString('MACHINE')
@@ -76,6 +75,8 @@ class Configurator(gobject.GObject):
76 if sdkmach and sdkmach != self.config.get('SDKMACHINE', ''): 75 if sdkmach and sdkmach != self.config.get('SDKMACHINE', ''):
77 self.config['SDKMACHINE'] = sdkmach 76 self.config['SDKMACHINE'] = sdkmach
78 distro = getString('DISTRO') 77 distro = getString('DISTRO')
78 if not distro:
79 distro = "defaultsetup"
79 if distro and distro != self.config.get('DISTRO', ''): 80 if distro and distro != self.config.get('DISTRO', ''):
80 self.config['DISTRO'] = distro 81 self.config['DISTRO'] = distro
81 bbnum = getString('BB_NUMBER_THREADS') 82 bbnum = getString('BB_NUMBER_THREADS')
@@ -109,10 +110,10 @@ class Configurator(gobject.GObject):
109 110
110 self.orig_config = copy.deepcopy(self.config) 111 self.orig_config = copy.deepcopy(self.config)
111 112
112 def setLocalConfVar(self, var, val): 113 def setConfVar(self, var, val):
113 self.config[var] = val 114 self.config[var] = val
114 115
115 def getLocalConfVar(self, var): 116 def getConfVar(self, var):
116 if var in self.config: 117 if var in self.config:
117 return self.config[var] 118 return self.config[var]
118 else: 119 else:
@@ -135,9 +136,17 @@ class Configurator(gobject.GObject):
135 self.emit("layers-loaded") 136 self.emit("layers-loaded")
136 137
137 def _addConfigFile(self, path): 138 def _addConfigFile(self, path):
139 conffiles = ["local.conf", "hob-pre.conf", "hob-post.conf"]
138 pref, sep, filename = path.rpartition("/") 140 pref, sep, filename = path.rpartition("/")
139 if filename == "local.conf" or filename == "hob.local.conf": 141
140 self._loadLocalConf(path) 142 if filename == "hob-pre.conf":
143 self.preconf = path
144
145 if filename == "hob-post.conf":
146 self.postconf = path
147
148 if filename in conffiles:
149 self._loadConf(path)
141 elif filename == "bblayers.conf": 150 elif filename == "bblayers.conf":
142 self._loadLayerConf(path) 151 self._loadLayerConf(path)
143 152
@@ -220,22 +229,8 @@ class Configurator(gobject.GObject):
220 with open(conffile, "w") as new: 229 with open(conffile, "w") as new:
221 new.write("".join(contents)) 230 new.write("".join(contents))
222 231
223 def writeLocalConf(self): 232 def updateConf(self, orig_lines, changed_values):
224 # Dictionary containing only new or modified variables 233 new_config_lines = []
225 changed_values = {}
226 for var in self.config:
227 val = self.config[var]
228 if self.orig_config.get(var, None) != val:
229 changed_values[var] = val
230
231 if not len(changed_values):
232 return
233
234 # read the original conf into a list
235 with open(self.local, 'r') as config:
236 config_lines = config.readlines()
237
238 new_config_lines = ["\n"]
239 for var in changed_values: 234 for var in changed_values:
240 # Convenience function for re.subn(). If the pattern matches 235 # Convenience function for re.subn(). If the pattern matches
241 # return a string which contains an assignment using the same 236 # return a string which contains an assignment using the same
@@ -254,10 +249,10 @@ class Configurator(gobject.GObject):
254 # Iterate over the local.conf lines and if they are a match 249 # Iterate over the local.conf lines and if they are a match
255 # for the pattern comment out the line and append a new line 250 # for the pattern comment out the line and append a new line
256 # with the new VAR op "value" entry 251 # with the new VAR op "value" entry
257 for line in config_lines: 252 for line in orig_lines:
258 new_line, replacements = p.subn(replace_val, line) 253 new_line, replacements = p.subn(replace_val, line)
259 if replacements: 254 if replacements:
260 config_lines[cnt] = "#%s" % line 255 orig_lines[cnt] = "#%s" % line
261 new_config_lines.append(new_line) 256 new_config_lines.append(new_line)
262 replaced = True 257 replaced = True
263 cnt = cnt + 1 258 cnt = cnt + 1
@@ -266,16 +261,53 @@ class Configurator(gobject.GObject):
266 new_config_lines.append("%s = \"%s\"\n" % (var, changed_values[var])) 261 new_config_lines.append("%s = \"%s\"\n" % (var, changed_values[var]))
267 262
268 # Add the modified variables 263 # Add the modified variables
269 config_lines.extend(new_config_lines) 264 orig_lines.extend(new_config_lines)
265 return orig_lines
266
267 def writeConf(self):
268 pre_vars = ["MACHINE", "SDKMACHINE", "DISTRO",
269 "INCOMPATIBLE_LICENSE"]
270 post_vars = ["BB_NUMBER_THREADS", "PARALLEL_MAKE", "PACKAGE_CLASSES",
271 "IMAGE_FSTYPES", "HOB_BUILD_TOOLCHAIN",
272 "HOB_BUILD_TOOLCHAIN_HEADERS"]
273 pre_values = {}
274 post_values = {}
275 changed_values = {}
276 pre_lines = None
277 post_lines = None
270 278
271 self.writeConfFile(self.local, config_lines) 279 for var in self.config:
280 val = self.config[var]
281 if self.orig_config.get(var, None) != val:
282 changed_values[var] = val
283
284 if not len(changed_values):
285 return
286
287 for var in changed_values:
288 if var in pre_vars:
289 pre_values[var] = changed_values[var]
290 elif var in post_vars:
291 post_values[var] = changed_values[var]
292
293 with open(self.preconf, 'r') as pre:
294 pre_lines = pre.readlines()
295 pre_lines = self.updateConf(pre_lines, pre_values)
296 if len(pre_lines):
297 self.writeConfFile(self.preconf, pre_lines)
298
299 with open(self.postconf, 'r') as post:
300 post_lines = post.readlines()
301 post_lines = self.updateConf(post_lines, post_values)
302 if len(post_lines):
303 self.writeConfFile(self.postconf, post_lines)
272 304
273 del self.orig_config 305 del self.orig_config
274 self.orig_config = copy.deepcopy(self.config) 306 self.orig_config = copy.deepcopy(self.config)
275 307
276 def insertTempBBPath(self, bbpath, bbfiles): 308 def insertTempBBPath(self, bbpath, bbfiles):
277 # read the original conf into a list 309 # read the original conf into a list
278 with open(self.local, 'r') as config: 310 with open(self.postconf, 'r') as config:
279 config_lines = config.readlines() 311 config_lines = config.readlines()
280 312
281 if bbpath: 313 if bbpath:
@@ -283,7 +315,7 @@ class Configurator(gobject.GObject):
283 if bbfiles: 315 if bbfiles:
284 config_lines.append("BBFILES := \"${BBFILES} %s\"\n" % bbfiles) 316 config_lines.append("BBFILES := \"${BBFILES} %s\"\n" % bbfiles)
285 317
286 self.writeConfFile(self.local, config_lines) 318 self.writeConfFile(self.postconf, config_lines)
287 319
288 def writeLayerConf(self): 320 def writeLayerConf(self):
289 # If we've not added/removed new layers don't write 321 # If we've not added/removed new layers don't write