From 26d19996a3d45e2f4b8f10516e45e10778929f6d Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Mon, 20 May 2013 23:00:31 +0100 Subject: bitbake: cooker: Split configuration parsing code into cookerdata In order to have a memory resident bitbake and to allow task execution, we need to be able to rebuild the base configuration without a cooker. This moves the code into its own class so it can be built independently. The interface is less than ideal here but I didn't want to add parsing methods a subclassed DataSmart, at least until we've experimented further with this code and are certain that makes sense. At the very least, the methods are ugly and need cleaning up. Spliting the code out seems to be the right thing to do though and should unblock various activities on BitBake so I believe this code is a step in the right direction. Based on a patch from Alexandru Damian (Bitbake rev: 22a0b3cf73d2689db0c118b37aa7492632f8b0a7) Signed-off-by: Richard Purdie --- bitbake/lib/bb/cookerdata.py | 130 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) (limited to 'bitbake/lib/bb/cookerdata.py') diff --git a/bitbake/lib/bb/cookerdata.py b/bitbake/lib/bb/cookerdata.py index 3c2469ef87..0b436b37e6 100644 --- a/bitbake/lib/bb/cookerdata.py +++ b/bitbake/lib/bb/cookerdata.py @@ -126,3 +126,133 @@ class CookerConfiguration(object): def setServerRegIdleCallback(self, srcb): self.server_register_idlecallback = srcb +def catch_parse_error(func): + """Exception handling bits for our parsing""" + @wraps(func) + def wrapped(fn, *args): + try: + return func(fn, *args) + except (IOError, bb.parse.ParseError, bb.data_smart.ExpansionError) as exc: + parselog.critical("Unable to parse %s: %s" % (fn, exc)) + sys.exit(1) + return wrapped + +@catch_parse_error +def _parse(fn, data, include=True): + return bb.parse.handle(fn, data, include) + +@catch_parse_error +def _inherit(bbclass, data): + bb.parse.BBHandler.inherit(bbclass, "configuration INHERITs", 0, data) + return data + +def findConfigFile(configfile): + path = os.getcwd() + while path != "/": + confpath = os.path.join(path, "conf", configfile) + if os.path.exists(confpath): + return confpath + + path, _ = os.path.split(path) + return None + +class CookerDataBuilder(object): + + def __init__(self, params, worker = False): + + self.prefiles = params.prefile + self.postfiles = params.postfile + self.tracking = params.tracking + + self.data = bb.data.init() + if self.tracking: + self.data.enableTracking() + + # Keep a datastore of the initial environment variables and their + # values from when BitBake was launched to enable child processes + # to use environment variables which have been cleaned from the + # BitBake processes env + self.savedenv = bb.data.init() + savedenv = params.environment + for k in savedenv: + self.savedenv.setVar(k, savedenv[k]) + + filtered_keys = bb.utils.approved_variables() + bb.data.inheritFromOS(self.data, self.savedenv, filtered_keys) + self.data.setVar("BB_ORIGENV", self.savedenv) + + if worker: + self.data.setVar("BB_WORKERCONTEXT", "1") + + def parseBaseConfiguration(self): + try: + self.parseConfigurationFiles(self.prefiles, self.postfiles) + except SyntaxError: + sys.exit(1) + except Exception: + logger.exception("Error parsing configuration files") + sys.exit(1) + + def _findLayerConf(self): + return findConfigFile("bblayers.conf") + + def parseConfigurationFiles(self, prefiles, postfiles): + data = self.data + bb.parse.init_parser(data) + + # Parse files for loading *before* bitbake.conf and any includes + for f in prefiles: + data = _parse(f, data) + + layerconf = self._findLayerConf() + if layerconf: + parselog.debug(2, "Found bblayers.conf (%s)", layerconf) + data = _parse(layerconf, data) + + layers = (data.getVar('BBLAYERS', True) or "").split() + + data = bb.data.createCopy(data) + for layer in layers: + parselog.debug(2, "Adding layer %s", layer) + data.setVar('LAYERDIR', layer) + data = _parse(os.path.join(layer, "conf", "layer.conf"), data) + data.expandVarref('LAYERDIR') + + data.delVar('LAYERDIR') + + if not data.getVar("BBPATH", True): + raise SystemExit("The BBPATH variable is not set") + + data = _parse(os.path.join("conf", "bitbake.conf"), data) + + # Parse files for loading *after* bitbake.conf and any includes + for p in postfiles: + data = _parse(p, data) + + # Handle any INHERITs and inherit the base class + bbclasses = ["base"] + (data.getVar('INHERIT', True) or "").split() + for bbclass in bbclasses: + data = _inherit(bbclass, data) + + # Nomally we only register event handlers at the end of parsing .bb files + # We register any handlers we've found so far here... + for var in data.getVar('__BBHANDLERS') or []: + bb.event.register(var, data.getVar(var)) + + if data.getVar("BB_WORKERCONTEXT", False) is None: + bb.fetch.fetcher_init(data) + bb.codeparser.parser_cache_init(data) + bb.event.fire(bb.event.ConfigParsed(), data) + + if data.getVar("BB_INVALIDCONF") is True: + data.setVar("BB_INVALIDCONF", False) + self.parseConfigurationFiles(self.prefiles, self.postfiles) + return + + bb.parse.init_parser(data) + data.setVar('BBINCLUDED',bb.parse.get_file_depends(data)) + self.data = data + self.data_hash = data.get_hash() + + + -- cgit v1.2.3-54-g00ecf