diff options
author | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
commit | c527fd1f14c27855a37f2e8ac5346ce8d940ced2 (patch) | |
tree | bb002c1fdf011c41dbd2f0927bed23ecb5f83c97 /bitbake/bin/bitbake | |
download | poky-daisy-140929.tar.gz |
initial commit for Enea Linux 4.0-140929daisy-140929
Migrated from the internal git server on the daisy-enea-point-release branch
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'bitbake/bin/bitbake')
-rwxr-xr-x | bitbake/bin/bitbake | 362 |
1 files changed, 362 insertions, 0 deletions
diff --git a/bitbake/bin/bitbake b/bitbake/bin/bitbake new file mode 100755 index 0000000000..846d059319 --- /dev/null +++ b/bitbake/bin/bitbake | |||
@@ -0,0 +1,362 @@ | |||
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 | ||
26 | import sys, logging | ||
27 | sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), | ||
28 | 'lib')) | ||
29 | |||
30 | import optparse | ||
31 | import warnings | ||
32 | from traceback import format_exception | ||
33 | try: | ||
34 | import bb | ||
35 | except RuntimeError as exc: | ||
36 | sys.exit(str(exc)) | ||
37 | from bb import event | ||
38 | import bb.msg | ||
39 | from bb import cooker | ||
40 | from bb import ui | ||
41 | from bb import server | ||
42 | from bb import cookerdata | ||
43 | |||
44 | __version__ = "1.23.0" | ||
45 | logger = logging.getLogger("BitBake") | ||
46 | |||
47 | # Python multiprocessing requires /dev/shm | ||
48 | if not os.access('/dev/shm', os.W_OK | os.X_OK): | ||
49 | sys.exit("FATAL: /dev/shm does not exist or is not writable") | ||
50 | |||
51 | # Unbuffer stdout to avoid log truncation in the event | ||
52 | # of an unorderly exit as well as to provide timely | ||
53 | # updates to log files for use with tail | ||
54 | try: | ||
55 | if sys.stdout.name == '<stdout>': | ||
56 | sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) | ||
57 | except: | ||
58 | pass | ||
59 | |||
60 | |||
61 | def get_ui(config): | ||
62 | if not config.ui: | ||
63 | # modify 'ui' attribute because it is also read by cooker | ||
64 | config.ui = os.environ.get('BITBAKE_UI', 'knotty') | ||
65 | |||
66 | interface = config.ui | ||
67 | |||
68 | try: | ||
69 | # Dynamically load the UI based on the ui name. Although we | ||
70 | # suggest a fixed set this allows you to have flexibility in which | ||
71 | # ones are available. | ||
72 | module = __import__("bb.ui", fromlist = [interface]) | ||
73 | return getattr(module, interface) | ||
74 | except AttributeError: | ||
75 | sys.exit("FATAL: Invalid user interface '%s' specified.\n" | ||
76 | "Valid interfaces: depexp, goggle, ncurses, hob, knotty [default]." % interface) | ||
77 | |||
78 | |||
79 | # Display bitbake/OE warnings via the BitBake.Warnings logger, ignoring others""" | ||
80 | warnlog = logging.getLogger("BitBake.Warnings") | ||
81 | _warnings_showwarning = warnings.showwarning | ||
82 | def _showwarning(message, category, filename, lineno, file=None, line=None): | ||
83 | if file is not None: | ||
84 | if _warnings_showwarning is not None: | ||
85 | _warnings_showwarning(message, category, filename, lineno, file, line) | ||
86 | else: | ||
87 | s = warnings.formatwarning(message, category, filename, lineno) | ||
88 | warnlog.warn(s) | ||
89 | |||
90 | warnings.showwarning = _showwarning | ||
91 | warnings.filterwarnings("ignore") | ||
92 | warnings.filterwarnings("default", module="(<string>$|(oe|bb)\.)") | ||
93 | warnings.filterwarnings("ignore", category=PendingDeprecationWarning) | ||
94 | warnings.filterwarnings("ignore", category=ImportWarning) | ||
95 | warnings.filterwarnings("ignore", category=DeprecationWarning, module="<string>$") | ||
96 | warnings.filterwarnings("ignore", message="With-statements now directly support multiple context managers") | ||
97 | |||
98 | class BitBakeConfigParameters(cookerdata.ConfigParameters): | ||
99 | |||
100 | def parseCommandLine(self): | ||
101 | parser = optparse.OptionParser( | ||
102 | version = "BitBake Build Tool Core version %s, %%prog version %s" % (bb.__version__, __version__), | ||
103 | usage = """%prog [options] [recipename/target ...] | ||
104 | |||
105 | Executes the specified task (default is 'build') for a given set of target recipes (.bb files). | ||
106 | It is assumed there is a conf/bblayers.conf available in cwd or in BBPATH which | ||
107 | will provide the layer, BBFILES and other configuration information.""") | ||
108 | |||
109 | parser.add_option("-b", "--buildfile", help = "Execute tasks from a specific .bb recipe directly. WARNING: Does not handle any dependencies from other recipes.", | ||
110 | action = "store", dest = "buildfile", default = None) | ||
111 | |||
112 | parser.add_option("-k", "--continue", help = "Continue as much as possible after an error. While the target that failed and anything depending on it cannot be built, as much as possible will be built before stopping.", | ||
113 | action = "store_false", dest = "abort", default = True) | ||
114 | |||
115 | parser.add_option("-a", "--tryaltconfigs", help = "Continue with builds by trying to use alternative providers where possible.", | ||
116 | action = "store_true", dest = "tryaltconfigs", default = False) | ||
117 | |||
118 | parser.add_option("-f", "--force", help = "Force the specified targets/task to run (invalidating any existing stamp file).", | ||
119 | action = "store_true", dest = "force", default = False) | ||
120 | |||
121 | parser.add_option("-c", "--cmd", help = "Specify the task to execute. The exact options available depend on the metadata. Some examples might be 'compile' or 'populate_sysroot' or 'listtasks' may give a list of the tasks available.", | ||
122 | action = "store", dest = "cmd") | ||
123 | |||
124 | parser.add_option("-C", "--clear-stamp", help = "Invalidate the stamp for the specified task such as 'compile' and then run the default task for the specified target(s).", | ||
125 | action = "store", dest = "invalidate_stamp") | ||
126 | |||
127 | parser.add_option("-r", "--read", help = "Read the specified file before bitbake.conf.", | ||
128 | action = "append", dest = "prefile", default = []) | ||
129 | |||
130 | parser.add_option("-R", "--postread", help = "Read the specified file after bitbake.conf.", | ||
131 | action = "append", dest = "postfile", default = []) | ||
132 | |||
133 | parser.add_option("-v", "--verbose", help = "Output more log message data to the terminal.", | ||
134 | action = "store_true", dest = "verbose", default = False) | ||
135 | |||
136 | parser.add_option("-D", "--debug", help = "Increase the debug level. You can specify this more than once.", | ||
137 | action = "count", dest="debug", default = 0) | ||
138 | |||
139 | parser.add_option("-n", "--dry-run", help = "Don't execute, just go through the motions.", | ||
140 | action = "store_true", dest = "dry_run", default = False) | ||
141 | |||
142 | parser.add_option("-S", "--dump-signatures", help = "Dump out the signature construction information, with no task execution. Parameters are passed to the signature handling code, use 'none' if no specific handler is required.", | ||
143 | action = "append", dest = "dump_signatures", default = []) | ||
144 | |||
145 | parser.add_option("-p", "--parse-only", help = "Quit after parsing the BB recipes.", | ||
146 | action = "store_true", dest = "parse_only", default = False) | ||
147 | |||
148 | parser.add_option("-s", "--show-versions", help = "Show current and preferred versions of all recipes.", | ||
149 | action = "store_true", dest = "show_versions", default = False) | ||
150 | |||
151 | parser.add_option("-e", "--environment", help = "Show the global or per-package environment complete with information about where variables were set/changed.", | ||
152 | action = "store_true", dest = "show_environment", default = False) | ||
153 | |||
154 | parser.add_option("-g", "--graphviz", help = "Save dependency tree information for the specified targets in the dot syntax.", | ||
155 | action = "store_true", dest = "dot_graph", default = False) | ||
156 | |||
157 | parser.add_option("-I", "--ignore-deps", help = """Assume these dependencies don't exist and are already provided (equivalent to ASSUME_PROVIDED). Useful to make dependency graphs more appealing""", | ||
158 | action = "append", dest = "extra_assume_provided", default = []) | ||
159 | |||
160 | parser.add_option("-l", "--log-domains", help = """Show debug logging for the specified logging domains""", | ||
161 | action = "append", dest = "debug_domains", default = []) | ||
162 | |||
163 | parser.add_option("-P", "--profile", help = "Profile the command and save reports.", | ||
164 | action = "store_true", dest = "profile", default = False) | ||
165 | |||
166 | parser.add_option("-u", "--ui", help = "The user interface to use (e.g. knotty, hob, depexp).", | ||
167 | action = "store", dest = "ui") | ||
168 | |||
169 | parser.add_option("-t", "--servertype", help = "Choose which server to use, process or xmlrpc.", | ||
170 | action = "store", dest = "servertype") | ||
171 | |||
172 | parser.add_option("", "--revisions-changed", help = "Set the exit code depending on whether upstream floating revisions have changed or not.", | ||
173 | action = "store_true", dest = "revisions_changed", default = False) | ||
174 | |||
175 | parser.add_option("", "--server-only", help = "Run bitbake without a UI, only starting a server (cooker) process.", | ||
176 | action = "store_true", dest = "server_only", default = False) | ||
177 | |||
178 | parser.add_option("-B", "--bind", help = "The name/address for the bitbake server to bind to.", | ||
179 | action = "store", dest = "bind", default = False) | ||
180 | |||
181 | parser.add_option("", "--no-setscene", help = "Do not run any setscene tasks. sstate will be ignored and everything needed, built.", | ||
182 | action = "store_true", dest = "nosetscene", default = False) | ||
183 | |||
184 | parser.add_option("", "--remote-server", help = "Connect to the specified server.", | ||
185 | action = "store", dest = "remote_server", default = False) | ||
186 | |||
187 | parser.add_option("-m", "--kill-server", help = "Terminate the remote server.", | ||
188 | action = "store_true", dest = "kill_server", default = False) | ||
189 | |||
190 | parser.add_option("", "--observe-only", help = "Connect to a server as an observing-only client.", | ||
191 | action = "store_true", dest = "observe_only", default = False) | ||
192 | |||
193 | parser.add_option("", "--status-only", help = "Check the status of the remote bitbake server.", | ||
194 | action = "store_true", dest = "status_only", default = False) | ||
195 | |||
196 | options, targets = parser.parse_args(sys.argv) | ||
197 | |||
198 | # some environmental variables set also configuration options | ||
199 | if "BBSERVER" in os.environ: | ||
200 | options.servertype = "xmlrpc" | ||
201 | options.remote_server = os.environ["BBSERVER"] | ||
202 | |||
203 | return options, targets[1:] | ||
204 | |||
205 | |||
206 | def start_server(servermodule, configParams, configuration, features): | ||
207 | server = servermodule.BitBakeServer() | ||
208 | if configParams.bind: | ||
209 | (host, port) = configParams.bind.split(':') | ||
210 | server.initServer((host, int(port))) | ||
211 | configuration.interface = [ server.serverImpl.host, server.serverImpl.port ] | ||
212 | else: | ||
213 | server.initServer() | ||
214 | configuration.interface = [] | ||
215 | |||
216 | try: | ||
217 | configuration.setServerRegIdleCallback(server.getServerIdleCB()) | ||
218 | |||
219 | cooker = bb.cooker.BBCooker(configuration, features) | ||
220 | |||
221 | server.addcooker(cooker) | ||
222 | server.saveConnectionDetails() | ||
223 | except Exception as e: | ||
224 | exc_info = sys.exc_info() | ||
225 | while hasattr(server, "event_queue"): | ||
226 | try: | ||
227 | import queue | ||
228 | except ImportError: | ||
229 | import Queue as queue | ||
230 | try: | ||
231 | event = server.event_queue.get(block=False) | ||
232 | except (queue.Empty, IOError): | ||
233 | break | ||
234 | if isinstance(event, logging.LogRecord): | ||
235 | logger.handle(event) | ||
236 | raise exc_info[1], None, exc_info[2] | ||
237 | server.detach() | ||
238 | return server | ||
239 | |||
240 | |||
241 | |||
242 | def main(): | ||
243 | |||
244 | configParams = BitBakeConfigParameters() | ||
245 | configuration = cookerdata.CookerConfiguration() | ||
246 | configuration.setConfigParameters(configParams) | ||
247 | |||
248 | ui_module = get_ui(configParams) | ||
249 | |||
250 | # Server type can be xmlrpc or process currently, if nothing is specified, | ||
251 | # the default server is process | ||
252 | if configParams.servertype: | ||
253 | server_type = configParams.servertype | ||
254 | else: | ||
255 | server_type = 'process' | ||
256 | |||
257 | try: | ||
258 | module = __import__("bb.server", fromlist = [server_type]) | ||
259 | servermodule = getattr(module, server_type) | ||
260 | except AttributeError: | ||
261 | sys.exit("FATAL: Invalid server type '%s' specified.\n" | ||
262 | "Valid interfaces: xmlrpc, process [default]." % server_type) | ||
263 | |||
264 | if configParams.server_only: | ||
265 | if configParams.servertype != "xmlrpc": | ||
266 | sys.exit("FATAL: If '--server-only' is defined, we must set the servertype as 'xmlrpc'.\n") | ||
267 | if not configParams.bind: | ||
268 | sys.exit("FATAL: The '--server-only' option requires a name/address to bind to with the -B option.\n") | ||
269 | if configParams.remote_server: | ||
270 | sys.exit("FATAL: The '--server-only' option conflicts with %s.\n" % | ||
271 | ("the BBSERVER environment variable" if "BBSERVER" in os.environ else "the '--remote-server' option" )) | ||
272 | |||
273 | if configParams.bind and configParams.servertype != "xmlrpc": | ||
274 | sys.exit("FATAL: If '-B' or '--bind' is defined, we must set the servertype as 'xmlrpc'.\n") | ||
275 | |||
276 | if configParams.remote_server and configParams.servertype != "xmlrpc": | ||
277 | sys.exit("FATAL: If '--remote-server' is defined, we must set the servertype as 'xmlrpc'.\n") | ||
278 | |||
279 | if configParams.observe_only and (not configParams.remote_server or configParams.bind): | ||
280 | sys.exit("FATAL: '--observe-only' can only be used by UI clients connecting to a server.\n") | ||
281 | |||
282 | if "BBDEBUG" in os.environ: | ||
283 | level = int(os.environ["BBDEBUG"]) | ||
284 | if level > configuration.debug: | ||
285 | configuration.debug = level | ||
286 | |||
287 | bb.msg.init_msgconfig(configParams.verbose, configuration.debug, | ||
288 | configuration.debug_domains) | ||
289 | |||
290 | # Ensure logging messages get sent to the UI as events | ||
291 | handler = bb.event.LogHandler() | ||
292 | if not configParams.status_only: | ||
293 | # In status only mode there are no logs and no UI | ||
294 | logger.addHandler(handler) | ||
295 | |||
296 | # Clear away any spurious environment variables while we stoke up the cooker | ||
297 | cleanedvars = bb.utils.clean_environment() | ||
298 | |||
299 | featureset = [] | ||
300 | if not configParams.server_only: | ||
301 | # Collect the feature set for the UI | ||
302 | featureset = getattr(ui_module, "featureSet", []) | ||
303 | |||
304 | if not configParams.remote_server: | ||
305 | # we start a server with a given configuration | ||
306 | server = start_server(servermodule, configParams, configuration, featureset) | ||
307 | bb.event.ui_queue = [] | ||
308 | else: | ||
309 | # we start a stub server that is actually a XMLRPClient that connects to a real server | ||
310 | server = servermodule.BitBakeXMLRPCClient(configParams.observe_only) | ||
311 | server.saveConnectionDetails(configParams.remote_server) | ||
312 | server.saveConnectionConfigParams(configParams) | ||
313 | |||
314 | if not configParams.server_only: | ||
315 | if configParams.status_only: | ||
316 | try: | ||
317 | server_connection = server.establishConnection(featureset) | ||
318 | except: | ||
319 | sys.exit(1) | ||
320 | if not server_connection: | ||
321 | sys.exit(1) | ||
322 | server_connection.terminate() | ||
323 | sys.exit(0) | ||
324 | |||
325 | # Setup a connection to the server (cooker) | ||
326 | server_connection = server.establishConnection(featureset) | ||
327 | if not server_connection: | ||
328 | if configParams.kill_server: | ||
329 | bb.fatal("Server already killed") | ||
330 | configParams.bind = configParams.remote_server | ||
331 | start_server(servermodule, configParams, configuration, featureset) | ||
332 | bb.event.ui_queue = [] | ||
333 | server_connection = server.establishConnection(featureset) | ||
334 | |||
335 | # Restore the environment in case the UI needs it | ||
336 | for k in cleanedvars: | ||
337 | os.environ[k] = cleanedvars[k] | ||
338 | |||
339 | logger.removeHandler(handler) | ||
340 | |||
341 | try: | ||
342 | return ui_module.main(server_connection.connection, server_connection.events, configParams) | ||
343 | finally: | ||
344 | bb.event.ui_queue = [] | ||
345 | server_connection.terminate() | ||
346 | else: | ||
347 | print("server address: %s, server port: %s" % (server.serverImpl.host, server.serverImpl.port)) | ||
348 | return 0 | ||
349 | |||
350 | return 1 | ||
351 | |||
352 | if __name__ == "__main__": | ||
353 | try: | ||
354 | ret = main() | ||
355 | except bb.BBHandledException: | ||
356 | ret = 1 | ||
357 | except Exception: | ||
358 | ret = 1 | ||
359 | import traceback | ||
360 | traceback.print_exc() | ||
361 | sys.exit(ret) | ||
362 | |||