diff options
author | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
commit | 972dcfcdbfe75dcfeb777150c136576cf1a71e99 (patch) | |
tree | 97a61cd7e293d7ae9d56ef7ed0f81253365bb026 /bitbake/lib/bb/cookerdata.py | |
download | poky-972dcfcdbfe75dcfeb777150c136576cf1a71e99.tar.gz |
initial commit for Enea Linux 5.0 arm
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'bitbake/lib/bb/cookerdata.py')
-rw-r--r-- | bitbake/lib/bb/cookerdata.py | 320 |
1 files changed, 320 insertions, 0 deletions
diff --git a/bitbake/lib/bb/cookerdata.py b/bitbake/lib/bb/cookerdata.py new file mode 100644 index 0000000000..2ceed2d867 --- /dev/null +++ b/bitbake/lib/bb/cookerdata.py | |||
@@ -0,0 +1,320 @@ | |||
1 | #!/usr/bin/env python | ||
2 | # ex:ts=4:sw=4:sts=4:et | ||
3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
4 | # | ||
5 | # Copyright (C) 2003, 2004 Chris Larson | ||
6 | # Copyright (C) 2003, 2004 Phil Blundell | ||
7 | # Copyright (C) 2003 - 2005 Michael 'Mickey' Lauer | ||
8 | # Copyright (C) 2005 Holger Hans Peter Freyther | ||
9 | # Copyright (C) 2005 ROAD GmbH | ||
10 | # Copyright (C) 2006 Richard Purdie | ||
11 | # | ||
12 | # This program is free software; you can redistribute it and/or modify | ||
13 | # it under the terms of the GNU General Public License version 2 as | ||
14 | # published by the Free Software Foundation. | ||
15 | # | ||
16 | # This program is distributed in the hope that it will be useful, | ||
17 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | # GNU General Public License for more details. | ||
20 | # | ||
21 | # You should have received a copy of the GNU General Public License along | ||
22 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
23 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
24 | |||
25 | import os, sys | ||
26 | from functools import wraps | ||
27 | import logging | ||
28 | import bb | ||
29 | from bb import data | ||
30 | import bb.parse | ||
31 | |||
32 | logger = logging.getLogger("BitBake") | ||
33 | parselog = logging.getLogger("BitBake.Parsing") | ||
34 | |||
35 | class ConfigParameters(object): | ||
36 | def __init__(self): | ||
37 | self.options, targets = self.parseCommandLine() | ||
38 | self.environment = self.parseEnvironment() | ||
39 | |||
40 | self.options.pkgs_to_build = targets or [] | ||
41 | |||
42 | self.options.tracking = False | ||
43 | if hasattr(self.options, "show_environment") and self.options.show_environment: | ||
44 | self.options.tracking = True | ||
45 | |||
46 | for key, val in self.options.__dict__.items(): | ||
47 | setattr(self, key, val) | ||
48 | |||
49 | def parseCommandLine(self): | ||
50 | raise Exception("Caller must implement commandline option parsing") | ||
51 | |||
52 | def parseEnvironment(self): | ||
53 | return os.environ.copy() | ||
54 | |||
55 | def updateFromServer(self, server): | ||
56 | if not self.options.cmd: | ||
57 | defaulttask, error = server.runCommand(["getVariable", "BB_DEFAULT_TASK"]) | ||
58 | if error: | ||
59 | raise Exception("Unable to get the value of BB_DEFAULT_TASK from the server: %s" % error) | ||
60 | self.options.cmd = defaulttask or "build" | ||
61 | _, error = server.runCommand(["setConfig", "cmd", self.options.cmd]) | ||
62 | if error: | ||
63 | raise Exception("Unable to set configuration option 'cmd' on the server: %s" % error) | ||
64 | |||
65 | if not self.options.pkgs_to_build: | ||
66 | bbpkgs, error = server.runCommand(["getVariable", "BBPKGS"]) | ||
67 | if error: | ||
68 | raise Exception("Unable to get the value of BBPKGS from the server: %s" % error) | ||
69 | if bbpkgs: | ||
70 | self.options.pkgs_to_build.extend(bbpkgs.split()) | ||
71 | |||
72 | def updateToServer(self, server): | ||
73 | options = {} | ||
74 | for o in ["abort", "tryaltconfigs", "force", "invalidate_stamp", | ||
75 | "verbose", "debug", "dry_run", "dump_signatures", | ||
76 | "debug_domains", "extra_assume_provided", "profile"]: | ||
77 | options[o] = getattr(self.options, o) | ||
78 | |||
79 | ret, error = server.runCommand(["updateConfig", options]) | ||
80 | if error: | ||
81 | raise Exception("Unable to update the server configuration with local parameters: %s" % error) | ||
82 | |||
83 | def parseActions(self): | ||
84 | # Parse any commandline into actions | ||
85 | action = {'action':None, 'msg':None} | ||
86 | if self.options.show_environment: | ||
87 | if 'world' in self.options.pkgs_to_build: | ||
88 | action['msg'] = "'world' is not a valid target for --environment." | ||
89 | elif 'universe' in self.options.pkgs_to_build: | ||
90 | action['msg'] = "'universe' is not a valid target for --environment." | ||
91 | elif len(self.options.pkgs_to_build) > 1: | ||
92 | action['msg'] = "Only one target can be used with the --environment option." | ||
93 | elif self.options.buildfile and len(self.options.pkgs_to_build) > 0: | ||
94 | action['msg'] = "No target should be used with the --environment and --buildfile options." | ||
95 | elif len(self.options.pkgs_to_build) > 0: | ||
96 | action['action'] = ["showEnvironmentTarget", self.options.pkgs_to_build] | ||
97 | else: | ||
98 | action['action'] = ["showEnvironment", self.options.buildfile] | ||
99 | elif self.options.buildfile is not None: | ||
100 | action['action'] = ["buildFile", self.options.buildfile, self.options.cmd] | ||
101 | elif self.options.revisions_changed: | ||
102 | action['action'] = ["compareRevisions"] | ||
103 | elif self.options.show_versions: | ||
104 | action['action'] = ["showVersions"] | ||
105 | elif self.options.parse_only: | ||
106 | action['action'] = ["parseFiles"] | ||
107 | elif self.options.dot_graph: | ||
108 | if self.options.pkgs_to_build: | ||
109 | action['action'] = ["generateDotGraph", self.options.pkgs_to_build, self.options.cmd] | ||
110 | else: | ||
111 | action['msg'] = "Please specify a package name for dependency graph generation." | ||
112 | else: | ||
113 | if self.options.pkgs_to_build: | ||
114 | action['action'] = ["buildTargets", self.options.pkgs_to_build, self.options.cmd] | ||
115 | else: | ||
116 | #action['msg'] = "Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information." | ||
117 | action = None | ||
118 | self.options.initialaction = action | ||
119 | return action | ||
120 | |||
121 | class CookerConfiguration(object): | ||
122 | """ | ||
123 | Manages build options and configurations for one run | ||
124 | """ | ||
125 | |||
126 | def __init__(self): | ||
127 | self.debug_domains = [] | ||
128 | self.extra_assume_provided = [] | ||
129 | self.prefile = [] | ||
130 | self.postfile = [] | ||
131 | self.debug = 0 | ||
132 | self.cmd = None | ||
133 | self.abort = True | ||
134 | self.force = False | ||
135 | self.profile = False | ||
136 | self.nosetscene = False | ||
137 | self.invalidate_stamp = False | ||
138 | self.dump_signatures = [] | ||
139 | self.dry_run = False | ||
140 | self.tracking = False | ||
141 | self.interface = [] | ||
142 | self.writeeventlog = False | ||
143 | |||
144 | self.env = {} | ||
145 | |||
146 | def setConfigParameters(self, parameters): | ||
147 | for key in self.__dict__.keys(): | ||
148 | if key in parameters.options.__dict__: | ||
149 | setattr(self, key, parameters.options.__dict__[key]) | ||
150 | self.env = parameters.environment.copy() | ||
151 | self.tracking = parameters.tracking | ||
152 | |||
153 | def setServerRegIdleCallback(self, srcb): | ||
154 | self.server_register_idlecallback = srcb | ||
155 | |||
156 | def __getstate__(self): | ||
157 | state = {} | ||
158 | for key in self.__dict__.keys(): | ||
159 | if key == "server_register_idlecallback": | ||
160 | state[key] = None | ||
161 | else: | ||
162 | state[key] = getattr(self, key) | ||
163 | return state | ||
164 | |||
165 | def __setstate__(self,state): | ||
166 | for k in state: | ||
167 | setattr(self, k, state[k]) | ||
168 | |||
169 | |||
170 | def catch_parse_error(func): | ||
171 | """Exception handling bits for our parsing""" | ||
172 | @wraps(func) | ||
173 | def wrapped(fn, *args): | ||
174 | try: | ||
175 | return func(fn, *args) | ||
176 | except (IOError, bb.parse.ParseError, bb.data_smart.ExpansionError) as exc: | ||
177 | import traceback | ||
178 | parselog.critical( traceback.format_exc()) | ||
179 | parselog.critical("Unable to parse %s: %s" % (fn, exc)) | ||
180 | sys.exit(1) | ||
181 | return wrapped | ||
182 | |||
183 | @catch_parse_error | ||
184 | def parse_config_file(fn, data, include=True): | ||
185 | return bb.parse.handle(fn, data, include) | ||
186 | |||
187 | @catch_parse_error | ||
188 | def _inherit(bbclass, data): | ||
189 | bb.parse.BBHandler.inherit(bbclass, "configuration INHERITs", 0, data) | ||
190 | return data | ||
191 | |||
192 | def findConfigFile(configfile, data): | ||
193 | search = [] | ||
194 | bbpath = data.getVar("BBPATH", True) | ||
195 | if bbpath: | ||
196 | for i in bbpath.split(":"): | ||
197 | search.append(os.path.join(i, "conf", configfile)) | ||
198 | path = os.getcwd() | ||
199 | while path != "/": | ||
200 | search.append(os.path.join(path, "conf", configfile)) | ||
201 | path, _ = os.path.split(path) | ||
202 | |||
203 | for i in search: | ||
204 | if os.path.exists(i): | ||
205 | return i | ||
206 | |||
207 | return None | ||
208 | |||
209 | class CookerDataBuilder(object): | ||
210 | |||
211 | def __init__(self, cookercfg, worker = False): | ||
212 | |||
213 | self.prefiles = cookercfg.prefile | ||
214 | self.postfiles = cookercfg.postfile | ||
215 | self.tracking = cookercfg.tracking | ||
216 | |||
217 | bb.utils.set_context(bb.utils.clean_context()) | ||
218 | bb.event.set_class_handlers(bb.event.clean_class_handlers()) | ||
219 | self.data = bb.data.init() | ||
220 | if self.tracking: | ||
221 | self.data.enableTracking() | ||
222 | |||
223 | # Keep a datastore of the initial environment variables and their | ||
224 | # values from when BitBake was launched to enable child processes | ||
225 | # to use environment variables which have been cleaned from the | ||
226 | # BitBake processes env | ||
227 | self.savedenv = bb.data.init() | ||
228 | for k in cookercfg.env: | ||
229 | self.savedenv.setVar(k, cookercfg.env[k]) | ||
230 | |||
231 | filtered_keys = bb.utils.approved_variables() | ||
232 | bb.data.inheritFromOS(self.data, self.savedenv, filtered_keys) | ||
233 | self.data.setVar("BB_ORIGENV", self.savedenv) | ||
234 | |||
235 | if worker: | ||
236 | self.data.setVar("BB_WORKERCONTEXT", "1") | ||
237 | |||
238 | def parseBaseConfiguration(self): | ||
239 | try: | ||
240 | self.parseConfigurationFiles(self.prefiles, self.postfiles) | ||
241 | except SyntaxError: | ||
242 | raise bb.BBHandledException | ||
243 | except bb.data_smart.ExpansionError as e: | ||
244 | logger.error(str(e)) | ||
245 | raise bb.BBHandledException | ||
246 | except Exception: | ||
247 | logger.exception("Error parsing configuration files") | ||
248 | raise bb.BBHandledException | ||
249 | |||
250 | def _findLayerConf(self, data): | ||
251 | return findConfigFile("bblayers.conf", data) | ||
252 | |||
253 | def parseConfigurationFiles(self, prefiles, postfiles): | ||
254 | data = self.data | ||
255 | bb.parse.init_parser(data) | ||
256 | |||
257 | # Parse files for loading *before* bitbake.conf and any includes | ||
258 | for f in prefiles: | ||
259 | data = parse_config_file(f, data) | ||
260 | |||
261 | layerconf = self._findLayerConf(data) | ||
262 | if layerconf: | ||
263 | parselog.debug(2, "Found bblayers.conf (%s)", layerconf) | ||
264 | # By definition bblayers.conf is in conf/ of TOPDIR. | ||
265 | # We may have been called with cwd somewhere else so reset TOPDIR | ||
266 | data.setVar("TOPDIR", os.path.dirname(os.path.dirname(layerconf))) | ||
267 | data = parse_config_file(layerconf, data) | ||
268 | |||
269 | layers = (data.getVar('BBLAYERS', True) or "").split() | ||
270 | |||
271 | data = bb.data.createCopy(data) | ||
272 | for layer in layers: | ||
273 | parselog.debug(2, "Adding layer %s", layer) | ||
274 | data.setVar('LAYERDIR', layer) | ||
275 | data = parse_config_file(os.path.join(layer, "conf", "layer.conf"), data) | ||
276 | data.expandVarref('LAYERDIR') | ||
277 | |||
278 | data.delVar('LAYERDIR') | ||
279 | |||
280 | if not data.getVar("BBPATH", True): | ||
281 | msg = "The BBPATH variable is not set" | ||
282 | if not layerconf: | ||
283 | msg += (" and bitbake did not find a conf/bblayers.conf file in" | ||
284 | " the expected location.\nMaybe you accidentally" | ||
285 | " invoked bitbake from the wrong directory?") | ||
286 | raise SystemExit(msg) | ||
287 | |||
288 | data = parse_config_file(os.path.join("conf", "bitbake.conf"), data) | ||
289 | |||
290 | # Parse files for loading *after* bitbake.conf and any includes | ||
291 | for p in postfiles: | ||
292 | data = parse_config_file(p, data) | ||
293 | |||
294 | # Handle any INHERITs and inherit the base class | ||
295 | bbclasses = ["base"] + (data.getVar('INHERIT', True) or "").split() | ||
296 | for bbclass in bbclasses: | ||
297 | data = _inherit(bbclass, data) | ||
298 | |||
299 | # Nomally we only register event handlers at the end of parsing .bb files | ||
300 | # We register any handlers we've found so far here... | ||
301 | for var in data.getVar('__BBHANDLERS') or []: | ||
302 | bb.event.register(var, data.getVar(var), (data.getVarFlag(var, "eventmask", True) or "").split()) | ||
303 | |||
304 | if data.getVar("BB_WORKERCONTEXT", False) is None: | ||
305 | bb.fetch.fetcher_init(data) | ||
306 | bb.codeparser.parser_cache_init(data) | ||
307 | bb.event.fire(bb.event.ConfigParsed(), data) | ||
308 | |||
309 | if data.getVar("BB_INVALIDCONF") is True: | ||
310 | data.setVar("BB_INVALIDCONF", False) | ||
311 | self.parseConfigurationFiles(self.prefiles, self.postfiles) | ||
312 | return | ||
313 | |||
314 | bb.parse.init_parser(data) | ||
315 | data.setVar('BBINCLUDED',bb.parse.get_file_depends(data)) | ||
316 | self.data = data | ||
317 | self.data_hash = data.get_hash() | ||
318 | |||
319 | |||
320 | |||