diff options
Diffstat (limited to 'bitbake/lib/bb/cooker.py')
-rw-r--r-- | bitbake/lib/bb/cooker.py | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py index 80710fb97d..34fbfb0701 100644 --- a/bitbake/lib/bb/cooker.py +++ b/bitbake/lib/bb/cooker.py | |||
@@ -186,6 +186,12 @@ class BBCooker: | |||
186 | filtered_keys = bb.utils.approved_variables() | 186 | filtered_keys = bb.utils.approved_variables() |
187 | bb.data.inheritFromOS(self.configuration.data, self.savedenv, filtered_keys) | 187 | bb.data.inheritFromOS(self.configuration.data, self.savedenv, filtered_keys) |
188 | 188 | ||
189 | def enableDataTracking(self): | ||
190 | self.configuration.data.enableTracking() | ||
191 | |||
192 | def disableDataTracking(self): | ||
193 | self.configuration.data.disableTracking() | ||
194 | |||
189 | def loadConfigurationData(self): | 195 | def loadConfigurationData(self): |
190 | self.initConfigurationData() | 196 | self.initConfigurationData() |
191 | 197 | ||
@@ -201,6 +207,89 @@ class BBCooker: | |||
201 | if not self.configuration.cmd: | 207 | if not self.configuration.cmd: |
202 | self.configuration.cmd = self.configuration.data.getVar("BB_DEFAULT_TASK", True) or "build" | 208 | self.configuration.cmd = self.configuration.data.getVar("BB_DEFAULT_TASK", True) or "build" |
203 | 209 | ||
210 | def saveConfigurationVar(self, var, val, default_file): | ||
211 | |||
212 | replaced = False | ||
213 | #do not save if nothing changed | ||
214 | if str(val) == self.configuration.data.getVar(var): | ||
215 | return | ||
216 | |||
217 | conf_files = self.configuration.data.varhistory.get_variable_files(var) | ||
218 | |||
219 | #format the value when it is a list | ||
220 | if isinstance(val, list): | ||
221 | listval = "" | ||
222 | for value in val: | ||
223 | listval += "%s " % value | ||
224 | val = listval | ||
225 | |||
226 | topdir = self.configuration.data.getVar("TOPDIR") | ||
227 | |||
228 | #comment or replace operations made on var | ||
229 | for conf_file in conf_files: | ||
230 | if topdir in conf_file: | ||
231 | with open(conf_file, 'r') as f: | ||
232 | contents = f.readlines() | ||
233 | f.close() | ||
234 | |||
235 | lines = self.configuration.data.varhistory.get_variable_lines(var, conf_file) | ||
236 | for line in lines: | ||
237 | total = "" | ||
238 | i = 0 | ||
239 | for c in contents: | ||
240 | total += c | ||
241 | i = i + 1 | ||
242 | if i==int(line): | ||
243 | end_index = len(total) | ||
244 | index = total.rfind(var, 0, end_index) | ||
245 | |||
246 | begin_line = total.count("\n",0,index) | ||
247 | end_line = int(line) | ||
248 | |||
249 | #check if the variable was saved before in the same way | ||
250 | #if true it replace the place where the variable was declared | ||
251 | #else it comments it | ||
252 | if contents[begin_line-1]== "#added by bitbake\n": | ||
253 | contents[begin_line] = "%s = \"%s\"\n" % (var, val) | ||
254 | replaced = True | ||
255 | else: | ||
256 | for ii in range(begin_line, end_line): | ||
257 | contents[ii] = "#" + contents[ii] | ||
258 | |||
259 | total = "" | ||
260 | for c in contents: | ||
261 | total += c | ||
262 | with open(conf_file, 'w') as f: | ||
263 | f.write(total) | ||
264 | f.close() | ||
265 | |||
266 | if replaced == False: | ||
267 | #remove var from history | ||
268 | self.configuration.data.varhistory.del_var_history(var) | ||
269 | |||
270 | #add var to the end of default_file | ||
271 | default_file = self._findConfigFile(default_file) | ||
272 | |||
273 | with open(default_file, 'r') as f: | ||
274 | contents = f.readlines() | ||
275 | f.close() | ||
276 | |||
277 | total = "" | ||
278 | for c in contents: | ||
279 | total += c | ||
280 | |||
281 | #add the variable on a single line, to be easy to replace the second time | ||
282 | total += "#added by bitbake" | ||
283 | total += "\n%s = \"%s\"\n" % (var, val) | ||
284 | |||
285 | with open(default_file, 'w') as f: | ||
286 | f.write(total) | ||
287 | f.close() | ||
288 | |||
289 | #add to history | ||
290 | loginfo = {"op":set, "file":default_file, "line":total.count("\n")} | ||
291 | self.configuration.data.setVar(var, val, **loginfo) | ||
292 | |||
204 | def parseConfiguration(self): | 293 | def parseConfiguration(self): |
205 | 294 | ||
206 | # Set log file verbosity | 295 | # Set log file verbosity |