diff options
Diffstat (limited to 'bitbake/lib/bb/cookerdata.py')
-rw-r--r-- | bitbake/lib/bb/cookerdata.py | 130 |
1 files changed, 130 insertions, 0 deletions
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): | |||
126 | def setServerRegIdleCallback(self, srcb): | 126 | def setServerRegIdleCallback(self, srcb): |
127 | self.server_register_idlecallback = srcb | 127 | self.server_register_idlecallback = srcb |
128 | 128 | ||
129 | def catch_parse_error(func): | ||
130 | """Exception handling bits for our parsing""" | ||
131 | @wraps(func) | ||
132 | def wrapped(fn, *args): | ||
133 | try: | ||
134 | return func(fn, *args) | ||
135 | except (IOError, bb.parse.ParseError, bb.data_smart.ExpansionError) as exc: | ||
136 | parselog.critical("Unable to parse %s: %s" % (fn, exc)) | ||
137 | sys.exit(1) | ||
138 | return wrapped | ||
139 | |||
140 | @catch_parse_error | ||
141 | def _parse(fn, data, include=True): | ||
142 | return bb.parse.handle(fn, data, include) | ||
143 | |||
144 | @catch_parse_error | ||
145 | def _inherit(bbclass, data): | ||
146 | bb.parse.BBHandler.inherit(bbclass, "configuration INHERITs", 0, data) | ||
147 | return data | ||
148 | |||
149 | def findConfigFile(configfile): | ||
150 | path = os.getcwd() | ||
151 | while path != "/": | ||
152 | confpath = os.path.join(path, "conf", configfile) | ||
153 | if os.path.exists(confpath): | ||
154 | return confpath | ||
155 | |||
156 | path, _ = os.path.split(path) | ||
157 | return None | ||
158 | |||
159 | class CookerDataBuilder(object): | ||
160 | |||
161 | def __init__(self, params, worker = False): | ||
162 | |||
163 | self.prefiles = params.prefile | ||
164 | self.postfiles = params.postfile | ||
165 | self.tracking = params.tracking | ||
166 | |||
167 | self.data = bb.data.init() | ||
168 | if self.tracking: | ||
169 | self.data.enableTracking() | ||
170 | |||
171 | # Keep a datastore of the initial environment variables and their | ||
172 | # values from when BitBake was launched to enable child processes | ||
173 | # to use environment variables which have been cleaned from the | ||
174 | # BitBake processes env | ||
175 | self.savedenv = bb.data.init() | ||
176 | savedenv = params.environment | ||
177 | for k in savedenv: | ||
178 | self.savedenv.setVar(k, savedenv[k]) | ||
179 | |||
180 | filtered_keys = bb.utils.approved_variables() | ||
181 | bb.data.inheritFromOS(self.data, self.savedenv, filtered_keys) | ||
182 | self.data.setVar("BB_ORIGENV", self.savedenv) | ||
183 | |||
184 | if worker: | ||
185 | self.data.setVar("BB_WORKERCONTEXT", "1") | ||
186 | |||
187 | def parseBaseConfiguration(self): | ||
188 | try: | ||
189 | self.parseConfigurationFiles(self.prefiles, self.postfiles) | ||
190 | except SyntaxError: | ||
191 | sys.exit(1) | ||
192 | except Exception: | ||
193 | logger.exception("Error parsing configuration files") | ||
194 | sys.exit(1) | ||
195 | |||
196 | def _findLayerConf(self): | ||
197 | return findConfigFile("bblayers.conf") | ||
198 | |||
199 | def parseConfigurationFiles(self, prefiles, postfiles): | ||
200 | data = self.data | ||
201 | bb.parse.init_parser(data) | ||
202 | |||
203 | # Parse files for loading *before* bitbake.conf and any includes | ||
204 | for f in prefiles: | ||
205 | data = _parse(f, data) | ||
206 | |||
207 | layerconf = self._findLayerConf() | ||
208 | if layerconf: | ||
209 | parselog.debug(2, "Found bblayers.conf (%s)", layerconf) | ||
210 | data = _parse(layerconf, data) | ||
211 | |||
212 | layers = (data.getVar('BBLAYERS', True) or "").split() | ||
213 | |||
214 | data = bb.data.createCopy(data) | ||
215 | for layer in layers: | ||
216 | parselog.debug(2, "Adding layer %s", layer) | ||
217 | data.setVar('LAYERDIR', layer) | ||
218 | data = _parse(os.path.join(layer, "conf", "layer.conf"), data) | ||
219 | data.expandVarref('LAYERDIR') | ||
220 | |||
221 | data.delVar('LAYERDIR') | ||
222 | |||
223 | if not data.getVar("BBPATH", True): | ||
224 | raise SystemExit("The BBPATH variable is not set") | ||
225 | |||
226 | data = _parse(os.path.join("conf", "bitbake.conf"), data) | ||
227 | |||
228 | # Parse files for loading *after* bitbake.conf and any includes | ||
229 | for p in postfiles: | ||
230 | data = _parse(p, data) | ||
231 | |||
232 | # Handle any INHERITs and inherit the base class | ||
233 | bbclasses = ["base"] + (data.getVar('INHERIT', True) or "").split() | ||
234 | for bbclass in bbclasses: | ||
235 | data = _inherit(bbclass, data) | ||
236 | |||
237 | # Nomally we only register event handlers at the end of parsing .bb files | ||
238 | # We register any handlers we've found so far here... | ||
239 | for var in data.getVar('__BBHANDLERS') or []: | ||
240 | bb.event.register(var, data.getVar(var)) | ||
241 | |||
242 | if data.getVar("BB_WORKERCONTEXT", False) is None: | ||
243 | bb.fetch.fetcher_init(data) | ||
244 | bb.codeparser.parser_cache_init(data) | ||
245 | bb.event.fire(bb.event.ConfigParsed(), data) | ||
246 | |||
247 | if data.getVar("BB_INVALIDCONF") is True: | ||
248 | data.setVar("BB_INVALIDCONF", False) | ||
249 | self.parseConfigurationFiles(self.prefiles, self.postfiles) | ||
250 | return | ||
251 | |||
252 | bb.parse.init_parser(data) | ||
253 | data.setVar('BBINCLUDED',bb.parse.get_file_depends(data)) | ||
254 | self.data = data | ||
255 | self.data_hash = data.get_hash() | ||
256 | |||
257 | |||
258 | |||