From f0aef9953d3504e673c8572f1ae64cefdf678b0f Mon Sep 17 00:00:00 2001 From: Cristiana Voicu Date: Fri, 25 Jan 2013 16:10:12 +0200 Subject: bitbake: bitbake & hob: implement functions to assure consistency for configuration files Added a new command in bitbake to save a variable in a file; added a function in cooker which is called by this command. Added new command in bitbake to enable/disable data tracking. The function saveConfigurationVar from cooker.py saves a variable in the file that is received by argument. It checks all the operations made on that variable, using the history. If it's the first time when it does some changes on a variable,it comments the lines where an operation is made on it, and it sets it in a line to the end of file. If it's not the first time(it has a comment before), it replaces the line. Made some changes in hob to save the variables from bblayers.conf and local.conf using the bitbake command. [YOCTO #2934] (Bitbake rev: 55b814ccfa413d461d12956896364ab63eed70a8) Signed-off-by: Cristiana Voicu Signed-off-by: Richard Purdie --- bitbake/lib/bb/cooker.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) (limited to 'bitbake/lib/bb/cooker.py') 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: filtered_keys = bb.utils.approved_variables() bb.data.inheritFromOS(self.configuration.data, self.savedenv, filtered_keys) + def enableDataTracking(self): + self.configuration.data.enableTracking() + + def disableDataTracking(self): + self.configuration.data.disableTracking() + def loadConfigurationData(self): self.initConfigurationData() @@ -201,6 +207,89 @@ class BBCooker: if not self.configuration.cmd: self.configuration.cmd = self.configuration.data.getVar("BB_DEFAULT_TASK", True) or "build" + def saveConfigurationVar(self, var, val, default_file): + + replaced = False + #do not save if nothing changed + if str(val) == self.configuration.data.getVar(var): + return + + conf_files = self.configuration.data.varhistory.get_variable_files(var) + + #format the value when it is a list + if isinstance(val, list): + listval = "" + for value in val: + listval += "%s " % value + val = listval + + topdir = self.configuration.data.getVar("TOPDIR") + + #comment or replace operations made on var + for conf_file in conf_files: + if topdir in conf_file: + with open(conf_file, 'r') as f: + contents = f.readlines() + f.close() + + lines = self.configuration.data.varhistory.get_variable_lines(var, conf_file) + for line in lines: + total = "" + i = 0 + for c in contents: + total += c + i = i + 1 + if i==int(line): + end_index = len(total) + index = total.rfind(var, 0, end_index) + + begin_line = total.count("\n",0,index) + end_line = int(line) + + #check if the variable was saved before in the same way + #if true it replace the place where the variable was declared + #else it comments it + if contents[begin_line-1]== "#added by bitbake\n": + contents[begin_line] = "%s = \"%s\"\n" % (var, val) + replaced = True + else: + for ii in range(begin_line, end_line): + contents[ii] = "#" + contents[ii] + + total = "" + for c in contents: + total += c + with open(conf_file, 'w') as f: + f.write(total) + f.close() + + if replaced == False: + #remove var from history + self.configuration.data.varhistory.del_var_history(var) + + #add var to the end of default_file + default_file = self._findConfigFile(default_file) + + with open(default_file, 'r') as f: + contents = f.readlines() + f.close() + + total = "" + for c in contents: + total += c + + #add the variable on a single line, to be easy to replace the second time + total += "#added by bitbake" + total += "\n%s = \"%s\"\n" % (var, val) + + with open(default_file, 'w') as f: + f.write(total) + f.close() + + #add to history + loginfo = {"op":set, "file":default_file, "line":total.count("\n")} + self.configuration.data.setVar(var, val, **loginfo) + def parseConfiguration(self): # Set log file verbosity -- cgit v1.2.3-54-g00ecf