blob: 948f52769dd1a53352c8ca40670b8e967610beb4 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001#
2# BitBake (No)TTY UI Implementation
3#
4# Handling output to TTYs or files (no TTY)
5#
6# Copyright (C) 2006-2012 Richard Purdie
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License version 2 as
10# published by the Free Software Foundation.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License along
18# with this program; if not, write to the Free Software Foundation, Inc.,
19# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21from __future__ import division
22
23import os
24import sys
Patrick Williamsc0f7c042017-02-23 20:41:17 -060025import xmlrpc.client as xmlrpclib
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026import logging
27import progressbar
28import signal
29import bb.msg
30import time
31import fcntl
32import struct
33import copy
34import atexit
Patrick Williamsc0f7c042017-02-23 20:41:17 -060035
Patrick Williamsc124f4f2015-09-15 14:41:29 -050036from bb.ui import uihelper
37
38featureSet = [bb.cooker.CookerFeatures.SEND_SANITYEVENTS]
39
40logger = logging.getLogger("BitBake")
41interactive = sys.stdout.isatty()
42
43class BBProgress(progressbar.ProgressBar):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060044 def __init__(self, msg, maxval, widgets=None, extrapos=-1, resize_handler=None):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045 self.msg = msg
Patrick Williamsc0f7c042017-02-23 20:41:17 -060046 self.extrapos = extrapos
47 if not widgets:
48 widgets = [progressbar.Percentage(), ' ', progressbar.Bar(), ' ',
49 progressbar.ETA()]
50 self.extrapos = 4
Patrick Williamsc124f4f2015-09-15 14:41:29 -050051
Patrick Williamsc0f7c042017-02-23 20:41:17 -060052 if resize_handler:
53 self._resize_default = resize_handler
54 else:
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055 self._resize_default = signal.getsignal(signal.SIGWINCH)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056 progressbar.ProgressBar.__init__(self, maxval, [self.msg + ": "] + widgets, fd=sys.stdout)
57
Patrick Williamsc0f7c042017-02-23 20:41:17 -060058 def _handle_resize(self, signum=None, frame=None):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059 progressbar.ProgressBar._handle_resize(self, signum, frame)
60 if self._resize_default:
61 self._resize_default(signum, frame)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060062
Patrick Williamsc124f4f2015-09-15 14:41:29 -050063 def finish(self):
64 progressbar.ProgressBar.finish(self)
65 if self._resize_default:
66 signal.signal(signal.SIGWINCH, self._resize_default)
67
Patrick Williamsc0f7c042017-02-23 20:41:17 -060068 def setmessage(self, msg):
69 self.msg = msg
70 self.widgets[0] = msg
71
72 def setextra(self, extra):
73 if self.extrapos > -1:
74 if extra:
75 extrastr = str(extra)
76 if extrastr[0] != ' ':
77 extrastr = ' ' + extrastr
78 if extrastr[-1] != ' ':
79 extrastr += ' '
80 else:
81 extrastr = ' '
82 self.widgets[self.extrapos] = extrastr
83
84 def _need_update(self):
85 # We always want the bar to print when update() is called
86 return True
87
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088class NonInteractiveProgress(object):
89 fobj = sys.stdout
90
91 def __init__(self, msg, maxval):
92 self.msg = msg
93 self.maxval = maxval
Patrick Williamsc0f7c042017-02-23 20:41:17 -060094 self.finished = False
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095
Patrick Williamsc0f7c042017-02-23 20:41:17 -060096 def start(self, update=True):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050097 self.fobj.write("%s..." % self.msg)
98 self.fobj.flush()
99 return self
100
101 def update(self, value):
102 pass
103
104 def finish(self):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600105 if self.finished:
106 return
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107 self.fobj.write("done.\n")
108 self.fobj.flush()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600109 self.finished = True
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500110
111def new_progress(msg, maxval):
112 if interactive:
113 return BBProgress(msg, maxval)
114 else:
115 return NonInteractiveProgress(msg, maxval)
116
117def pluralise(singular, plural, qty):
118 if(qty == 1):
119 return singular % qty
120 else:
121 return plural % qty
122
123
124class InteractConsoleLogFilter(logging.Filter):
125 def __init__(self, tf, format):
126 self.tf = tf
127 self.format = format
128
129 def filter(self, record):
130 if record.levelno == self.format.NOTE and (record.msg.startswith("Running") or record.msg.startswith("recipe ")):
131 return False
132 self.tf.clearFooter()
133 return True
134
135class TerminalFilter(object):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500136 rows = 25
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500137 columns = 80
138
139 def sigwinch_handle(self, signum, frame):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500140 self.rows, self.columns = self.getTerminalColumns()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500141 if self._sigwinch_default:
142 self._sigwinch_default(signum, frame)
143
144 def getTerminalColumns(self):
145 def ioctl_GWINSZ(fd):
146 try:
147 cr = struct.unpack('hh', fcntl.ioctl(fd, self.termios.TIOCGWINSZ, '1234'))
148 except:
149 return None
150 return cr
151 cr = ioctl_GWINSZ(sys.stdout.fileno())
152 if not cr:
153 try:
154 fd = os.open(os.ctermid(), os.O_RDONLY)
155 cr = ioctl_GWINSZ(fd)
156 os.close(fd)
157 except:
158 pass
159 if not cr:
160 try:
161 cr = (env['LINES'], env['COLUMNS'])
162 except:
163 cr = (25, 80)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500164 return cr
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500165
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600166 def __init__(self, main, helper, console, errconsole, format, quiet):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500167 self.main = main
168 self.helper = helper
169 self.cuu = None
170 self.stdinbackup = None
171 self.interactive = sys.stdout.isatty()
172 self.footer_present = False
173 self.lastpids = []
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600174 self.lasttime = None
175 self.quiet = quiet
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500176
177 if not self.interactive:
178 return
179
180 try:
181 import curses
182 except ImportError:
183 sys.exit("FATAL: The knotty ui could not load the required curses python module.")
184
185 import termios
186 self.curses = curses
187 self.termios = termios
188 try:
189 fd = sys.stdin.fileno()
190 self.stdinbackup = termios.tcgetattr(fd)
191 new = copy.deepcopy(self.stdinbackup)
192 new[3] = new[3] & ~termios.ECHO
193 termios.tcsetattr(fd, termios.TCSADRAIN, new)
194 curses.setupterm()
195 if curses.tigetnum("colors") > 2:
196 format.enable_color()
197 self.ed = curses.tigetstr("ed")
198 if self.ed:
199 self.cuu = curses.tigetstr("cuu")
200 try:
201 self._sigwinch_default = signal.getsignal(signal.SIGWINCH)
202 signal.signal(signal.SIGWINCH, self.sigwinch_handle)
203 except:
204 pass
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500205 self.rows, self.columns = self.getTerminalColumns()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500206 except:
207 self.cuu = None
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500208 if not self.cuu:
209 self.interactive = False
210 bb.note("Unable to use interactive mode for this terminal, using fallback")
211 return
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500212 console.addFilter(InteractConsoleLogFilter(self, format))
213 errconsole.addFilter(InteractConsoleLogFilter(self, format))
214
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600215 self.main_progress = None
216
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500217 def clearFooter(self):
218 if self.footer_present:
219 lines = self.footer_present
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600220 sys.stdout.buffer.write(self.curses.tparm(self.cuu, lines))
221 sys.stdout.buffer.write(self.curses.tparm(self.ed))
222 sys.stdout.flush()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500223 self.footer_present = False
224
225 def updateFooter(self):
226 if not self.cuu:
227 return
228 activetasks = self.helper.running_tasks
229 failedtasks = self.helper.failed_tasks
230 runningpids = self.helper.running_pids
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600231 currenttime = time.time()
232 if not self.lasttime or (currenttime - self.lasttime > 5):
233 self.helper.needUpdate = True
234 self.lasttime = currenttime
235 if self.footer_present and not self.helper.needUpdate:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500236 return
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600237 self.helper.needUpdate = False
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500238 if self.footer_present:
239 self.clearFooter()
240 if (not self.helper.tasknumber_total or self.helper.tasknumber_current == self.helper.tasknumber_total) and not len(activetasks):
241 return
242 tasks = []
243 for t in runningpids:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600244 progress = activetasks[t].get("progress", None)
245 if progress is not None:
246 pbar = activetasks[t].get("progressbar", None)
247 rate = activetasks[t].get("rate", None)
248 start_time = activetasks[t].get("starttime", None)
249 if not pbar or pbar.bouncing != (progress < 0):
250 if progress < 0:
251 pbar = BBProgress("0: %s (pid %s) " % (activetasks[t]["title"], t), 100, widgets=[progressbar.BouncingSlider(), ''], extrapos=2, resize_handler=self.sigwinch_handle)
252 pbar.bouncing = True
253 else:
254 pbar = BBProgress("0: %s (pid %s) " % (activetasks[t]["title"], t), 100, widgets=[progressbar.Percentage(), ' ', progressbar.Bar(), ''], extrapos=4, resize_handler=self.sigwinch_handle)
255 pbar.bouncing = False
256 activetasks[t]["progressbar"] = pbar
257 tasks.append((pbar, progress, rate, start_time))
258 else:
259 start_time = activetasks[t].get("starttime", None)
260 if start_time:
261 tasks.append("%s - %ds (pid %s)" % (activetasks[t]["title"], currenttime - start_time, t))
262 else:
263 tasks.append("%s (pid %s)" % (activetasks[t]["title"], t))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500264
265 if self.main.shutdown:
266 content = "Waiting for %s running tasks to finish:" % len(activetasks)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500267 print(content)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600268 else:
269 if self.quiet:
270 content = "Running tasks (%s of %s)" % (self.helper.tasknumber_current, self.helper.tasknumber_total)
271 elif not len(activetasks):
272 content = "No currently running tasks (%s of %s)" % (self.helper.tasknumber_current, self.helper.tasknumber_total)
273 else:
274 content = "Currently %2s running tasks (%s of %s)" % (len(activetasks), self.helper.tasknumber_current, self.helper.tasknumber_total)
275 maxtask = self.helper.tasknumber_total
276 if not self.main_progress or self.main_progress.maxval != maxtask:
277 widgets = [' ', progressbar.Percentage(), ' ', progressbar.Bar()]
278 self.main_progress = BBProgress("Running tasks", maxtask, widgets=widgets, resize_handler=self.sigwinch_handle)
279 self.main_progress.start(False)
280 self.main_progress.setmessage(content)
281 progress = self.helper.tasknumber_current - 1
282 if progress < 0:
283 progress = 0
284 content = self.main_progress.update(progress)
285 print('')
286 lines = 1 + int(len(content) / (self.columns + 1))
287 if not self.quiet:
288 for tasknum, task in enumerate(tasks[:(self.rows - 2)]):
289 if isinstance(task, tuple):
290 pbar, progress, rate, start_time = task
291 if not pbar.start_time:
292 pbar.start(False)
293 if start_time:
294 pbar.start_time = start_time
295 pbar.setmessage('%s:%s' % (tasknum, pbar.msg.split(':', 1)[1]))
296 if progress > -1:
297 pbar.setextra(rate)
298 content = pbar.update(progress)
299 else:
300 content = pbar.update(1)
301 print('')
302 else:
303 content = "%s: %s" % (tasknum, task)
304 print(content)
305 lines = lines + 1 + int(len(content) / (self.columns + 1))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500306 self.footer_present = lines
307 self.lastpids = runningpids[:]
308 self.lastcount = self.helper.tasknumber_current
309
310 def finish(self):
311 if self.stdinbackup:
312 fd = sys.stdin.fileno()
313 self.termios.tcsetattr(fd, self.termios.TCSADRAIN, self.stdinbackup)
314
315def _log_settings_from_server(server):
316 # Get values of variables which control our output
317 includelogs, error = server.runCommand(["getVariable", "BBINCLUDELOGS"])
318 if error:
319 logger.error("Unable to get the value of BBINCLUDELOGS variable: %s" % error)
320 raise BaseException(error)
321 loglines, error = server.runCommand(["getVariable", "BBINCLUDELOGS_LINES"])
322 if error:
323 logger.error("Unable to get the value of BBINCLUDELOGS_LINES variable: %s" % error)
324 raise BaseException(error)
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500325 consolelogfile, error = server.runCommand(["getSetVariable", "BB_CONSOLELOG"])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500326 if error:
327 logger.error("Unable to get the value of BB_CONSOLELOG variable: %s" % error)
328 raise BaseException(error)
329 return includelogs, loglines, consolelogfile
330
331_evt_list = [ "bb.runqueue.runQueueExitWait", "bb.event.LogExecTTY", "logging.LogRecord",
332 "bb.build.TaskFailed", "bb.build.TaskBase", "bb.event.ParseStarted",
333 "bb.event.ParseProgress", "bb.event.ParseCompleted", "bb.event.CacheLoadStarted",
334 "bb.event.CacheLoadProgress", "bb.event.CacheLoadCompleted", "bb.command.CommandFailed",
335 "bb.command.CommandExit", "bb.command.CommandCompleted", "bb.cooker.CookerExit",
336 "bb.event.MultipleProviders", "bb.event.NoProvider", "bb.runqueue.sceneQueueTaskStarted",
337 "bb.runqueue.runQueueTaskStarted", "bb.runqueue.runQueueTaskFailed", "bb.runqueue.sceneQueueTaskFailed",
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600338 "bb.event.BuildBase", "bb.build.TaskStarted", "bb.build.TaskSucceeded", "bb.build.TaskFailedSilent",
339 "bb.build.TaskProgress", "bb.event.ProcessStarted", "bb.event.ProcessProgress", "bb.event.ProcessFinished"]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500340
341def main(server, eventHandler, params, tf = TerminalFilter):
342
343 includelogs, loglines, consolelogfile = _log_settings_from_server(server)
344
345 if sys.stdin.isatty() and sys.stdout.isatty():
346 log_exec_tty = True
347 else:
348 log_exec_tty = False
349
350 helper = uihelper.BBUIHelper()
351
352 console = logging.StreamHandler(sys.stdout)
353 errconsole = logging.StreamHandler(sys.stderr)
354 format_str = "%(levelname)s: %(message)s"
355 format = bb.msg.BBLogFormatter(format_str)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600356 if params.options.quiet:
357 bb.msg.addDefaultlogFilter(console, bb.msg.BBLogFilterStdOut, bb.msg.BBLogFormatter.WARNING)
358 else:
359 bb.msg.addDefaultlogFilter(console, bb.msg.BBLogFilterStdOut)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500360 bb.msg.addDefaultlogFilter(errconsole, bb.msg.BBLogFilterStdErr)
361 console.setFormatter(format)
362 errconsole.setFormatter(format)
363 logger.addHandler(console)
364 logger.addHandler(errconsole)
365
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500366 bb.utils.set_process_name("KnottyUI")
367
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500368 if params.options.remote_server and params.options.kill_server:
369 server.terminateServer()
370 return
371
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600372 consolelog = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500373 if consolelogfile and not params.options.show_environment and not params.options.show_versions:
374 bb.utils.mkdirhier(os.path.dirname(consolelogfile))
375 conlogformat = bb.msg.BBLogFormatter(format_str)
376 consolelog = logging.FileHandler(consolelogfile)
377 bb.msg.addDefaultlogFilter(consolelog)
378 consolelog.setFormatter(conlogformat)
379 logger.addHandler(consolelog)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600380 loglink = os.path.join(os.path.dirname(consolelogfile), 'console-latest.log')
381 bb.utils.remove(loglink)
382 try:
383 os.symlink(os.path.basename(consolelogfile), loglink)
384 except OSError:
385 pass
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500386
387 llevel, debug_domains = bb.msg.constructLogOptions()
388 server.runCommand(["setEventMask", server.getEventHandle(), llevel, debug_domains, _evt_list])
389
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500390 universe = False
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500391 if not params.observe_only:
392 params.updateFromServer(server)
393 params.updateToServer(server, os.environ.copy())
394 cmdline = params.parseActions()
395 if not cmdline:
396 print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.")
397 return 1
398 if 'msg' in cmdline and cmdline['msg']:
399 logger.error(cmdline['msg'])
400 return 1
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500401 if cmdline['action'][0] == "buildTargets" and "universe" in cmdline['action'][1]:
402 universe = True
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500403
404 ret, error = server.runCommand(cmdline['action'])
405 if error:
406 logger.error("Command '%s' failed: %s" % (cmdline, error))
407 return 1
408 elif ret != True:
409 logger.error("Command '%s' failed: returned %s" % (cmdline, ret))
410 return 1
411
412
413 parseprogress = None
414 cacheprogress = None
415 main.shutdown = 0
416 interrupted = False
417 return_value = 0
418 errors = 0
419 warnings = 0
420 taskfailures = []
421
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600422 termfilter = tf(main, helper, console, errconsole, format, params.options.quiet)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500423 atexit.register(termfilter.finish)
424
425 while True:
426 try:
427 event = eventHandler.waitEvent(0)
428 if event is None:
429 if main.shutdown > 1:
430 break
431 termfilter.updateFooter()
432 event = eventHandler.waitEvent(0.25)
433 if event is None:
434 continue
435 helper.eventHandler(event)
436 if isinstance(event, bb.runqueue.runQueueExitWait):
437 if not main.shutdown:
438 main.shutdown = 1
439 continue
440 if isinstance(event, bb.event.LogExecTTY):
441 if log_exec_tty:
442 tries = event.retries
443 while tries:
444 print("Trying to run: %s" % event.prog)
445 if os.system(event.prog) == 0:
446 break
447 time.sleep(event.sleep_delay)
448 tries -= 1
449 if tries:
450 continue
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600451 logger.warning(event.msg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500452 continue
453
454 if isinstance(event, logging.LogRecord):
455 if event.levelno >= format.ERROR:
456 errors = errors + 1
457 return_value = 1
458 elif event.levelno == format.WARNING:
459 warnings = warnings + 1
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500460
461 if event.taskpid != 0:
462 # For "normal" logging conditions, don't show note logs from tasks
463 # but do show them if the user has changed the default log level to
464 # include verbose/debug messages
465 if event.levelno <= format.NOTE and (event.levelno < llevel or (event.levelno == format.NOTE and llevel != format.VERBOSE)):
466 continue
467
468 # Prefix task messages with recipe/task
469 if event.taskpid in helper.running_tasks:
470 taskinfo = helper.running_tasks[event.taskpid]
471 event.msg = taskinfo['title'] + ': ' + event.msg
472 if hasattr(event, 'fn'):
473 event.msg = event.fn + ': ' + event.msg
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500474 logger.handle(event)
475 continue
476
477 if isinstance(event, bb.build.TaskFailedSilent):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600478 logger.warning("Logfile for failed setscene task is %s" % event.logfile)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500479 continue
480 if isinstance(event, bb.build.TaskFailed):
481 return_value = 1
482 logfile = event.logfile
483 if logfile and os.path.exists(logfile):
484 termfilter.clearFooter()
485 bb.error("Logfile of failure stored in: %s" % logfile)
486 if includelogs and not event.errprinted:
487 print("Log data follows:")
488 f = open(logfile, "r")
489 lines = []
490 while True:
491 l = f.readline()
492 if l == '':
493 break
494 l = l.rstrip()
495 if loglines:
496 lines.append(' | %s' % l)
497 if len(lines) > int(loglines):
498 lines.pop(0)
499 else:
500 print('| %s' % l)
501 f.close()
502 if lines:
503 for line in lines:
504 print(line)
505 if isinstance(event, bb.build.TaskBase):
506 logger.info(event._message)
507 continue
508 if isinstance(event, bb.event.ParseStarted):
509 if event.total == 0:
510 continue
511 parseprogress = new_progress("Parsing recipes", event.total).start()
512 continue
513 if isinstance(event, bb.event.ParseProgress):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600514 if parseprogress:
515 parseprogress.update(event.current)
516 else:
517 bb.warn("Got ParseProgress event for parsing that never started?")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500518 continue
519 if isinstance(event, bb.event.ParseCompleted):
520 if not parseprogress:
521 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500522 parseprogress.finish()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600523 pasreprogress = None
524 if not params.options.quiet:
525 print(("Parsing of %d .bb files complete (%d cached, %d parsed). %d targets, %d skipped, %d masked, %d errors."
526 % ( event.total, event.cached, event.parsed, event.virtuals, event.skipped, event.masked, event.errors)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500527 continue
528
529 if isinstance(event, bb.event.CacheLoadStarted):
530 cacheprogress = new_progress("Loading cache", event.total).start()
531 continue
532 if isinstance(event, bb.event.CacheLoadProgress):
533 cacheprogress.update(event.current)
534 continue
535 if isinstance(event, bb.event.CacheLoadCompleted):
536 cacheprogress.finish()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600537 if not params.options.quiet:
538 print("Loaded %d entries from dependency cache." % event.num_entries)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500539 continue
540
541 if isinstance(event, bb.command.CommandFailed):
542 return_value = event.exitcode
543 if event.error:
544 errors = errors + 1
545 logger.error("Command execution failed: %s", event.error)
546 main.shutdown = 2
547 continue
548 if isinstance(event, bb.command.CommandExit):
549 if not return_value:
550 return_value = event.exitcode
551 continue
552 if isinstance(event, (bb.command.CommandCompleted, bb.cooker.CookerExit)):
553 main.shutdown = 2
554 continue
555 if isinstance(event, bb.event.MultipleProviders):
556 logger.info("multiple providers are available for %s%s (%s)", event._is_runtime and "runtime " or "",
557 event._item,
558 ", ".join(event._candidates))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500559 rtime = ""
560 if event._is_runtime:
561 rtime = "R"
562 logger.info("consider defining a PREFERRED_%sPROVIDER entry to match %s" % (rtime, event._item))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500563 continue
564 if isinstance(event, bb.event.NoProvider):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500565 if event._runtime:
566 r = "R"
567 else:
568 r = ""
569
570 extra = ''
571 if not event._reasons:
572 if event._close_matches:
573 extra = ". Close matches:\n %s" % '\n '.join(event._close_matches)
574
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500575 # For universe builds, only show these as warnings, not errors
576 h = logger.warning
577 if not universe:
578 return_value = 1
579 errors = errors + 1
580 h = logger.error
581
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500582 if event._dependees:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500583 h("Nothing %sPROVIDES '%s' (but %s %sDEPENDS on or otherwise requires it)%s", r, event._item, ", ".join(event._dependees), r, extra)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500584 else:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500585 h("Nothing %sPROVIDES '%s'%s", r, event._item, extra)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500586 if event._reasons:
587 for reason in event._reasons:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500588 h("%s", reason)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500589 continue
590
591 if isinstance(event, bb.runqueue.sceneQueueTaskStarted):
592 logger.info("Running setscene task %d of %d (%s)" % (event.stats.completed + event.stats.active + event.stats.failed + 1, event.stats.total, event.taskstring))
593 continue
594
595 if isinstance(event, bb.runqueue.runQueueTaskStarted):
596 if event.noexec:
597 tasktype = 'noexec task'
598 else:
599 tasktype = 'task'
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600600 logger.info("Running %s %d of %d (%s)",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500601 tasktype,
602 event.stats.completed + event.stats.active +
603 event.stats.failed + 1,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600604 event.stats.total, event.taskstring)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500605 continue
606
607 if isinstance(event, bb.runqueue.runQueueTaskFailed):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500608 return_value = 1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500609 taskfailures.append(event.taskstring)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600610 logger.error("Task (%s) failed with exit code '%s'",
611 event.taskstring, event.exitcode)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500612 continue
613
614 if isinstance(event, bb.runqueue.sceneQueueTaskFailed):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600615 logger.warning("Setscene task (%s) failed with exit code '%s' - real task will be run instead",
616 event.taskstring, event.exitcode)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500617 continue
618
619 if isinstance(event, bb.event.DepTreeGenerated):
620 continue
621
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600622 if isinstance(event, bb.event.ProcessStarted):
623 parseprogress = new_progress(event.processname, event.total)
624 parseprogress.start(False)
625 continue
626 if isinstance(event, bb.event.ProcessProgress):
627 if parseprogress:
628 parseprogress.update(event.progress)
629 else:
630 bb.warn("Got ProcessProgress event for someting that never started?")
631 continue
632 if isinstance(event, bb.event.ProcessFinished):
633 if parseprogress:
634 parseprogress.finish()
635 parseprogress = None
636 continue
637
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500638 # ignore
639 if isinstance(event, (bb.event.BuildBase,
640 bb.event.MetadataEvent,
641 bb.event.StampUpdate,
642 bb.event.ConfigParsed,
643 bb.event.RecipeParsed,
644 bb.event.RecipePreFinalise,
645 bb.runqueue.runQueueEvent,
646 bb.event.OperationStarted,
647 bb.event.OperationCompleted,
648 bb.event.OperationProgress,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600649 bb.event.DiskFull,
650 bb.build.TaskProgress)):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500651 continue
652
653 logger.error("Unknown event: %s", event)
654
655 except EnvironmentError as ioerror:
656 termfilter.clearFooter()
657 # ignore interrupted io
658 if ioerror.args[0] == 4:
659 continue
660 sys.stderr.write(str(ioerror))
661 if not params.observe_only:
662 _, error = server.runCommand(["stateForceShutdown"])
663 main.shutdown = 2
664 except KeyboardInterrupt:
665 termfilter.clearFooter()
666 if params.observe_only:
667 print("\nKeyboard Interrupt, exiting observer...")
668 main.shutdown = 2
669 if not params.observe_only and main.shutdown == 1:
670 print("\nSecond Keyboard Interrupt, stopping...\n")
671 _, error = server.runCommand(["stateForceShutdown"])
672 if error:
673 logger.error("Unable to cleanly stop: %s" % error)
674 if not params.observe_only and main.shutdown == 0:
675 print("\nKeyboard Interrupt, closing down...\n")
676 interrupted = True
677 _, error = server.runCommand(["stateShutdown"])
678 if error:
679 logger.error("Unable to cleanly shutdown: %s" % error)
680 main.shutdown = main.shutdown + 1
681 pass
682 except Exception as e:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500683 import traceback
684 sys.stderr.write(traceback.format_exc())
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500685 if not params.observe_only:
686 _, error = server.runCommand(["stateForceShutdown"])
687 main.shutdown = 2
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500688 return_value = 1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500689 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600690 termfilter.clearFooter()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500691 summary = ""
692 if taskfailures:
693 summary += pluralise("\nSummary: %s task failed:",
694 "\nSummary: %s tasks failed:", len(taskfailures))
695 for failure in taskfailures:
696 summary += "\n %s" % failure
697 if warnings:
698 summary += pluralise("\nSummary: There was %s WARNING message shown.",
699 "\nSummary: There were %s WARNING messages shown.", warnings)
700 if return_value and errors:
701 summary += pluralise("\nSummary: There was %s ERROR message shown, returning a non-zero exit code.",
702 "\nSummary: There were %s ERROR messages shown, returning a non-zero exit code.", errors)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600703 if summary and not params.options.quiet:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500704 print(summary)
705
706 if interrupted:
707 print("Execution was interrupted, returning a non-zero exit code.")
708 if return_value == 0:
709 return_value = 1
710 except IOError as e:
711 import errno
712 if e.errno == errno.EPIPE:
713 pass
714
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600715 if consolelog:
716 logger.removeHandler(consolelog)
717 consolelog.close()
718
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500719 return return_value