blob: fa88e6ccdd32d93d0aeaded9c029c130aa36fa79 [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
Patrick Williamsc0f7c042017-02-23 20:41:17 -060078 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050079 extrastr = ''
Patrick Williamsc0f7c042017-02-23 20:41:17 -060080 self.widgets[self.extrapos] = extrastr
81
82 def _need_update(self):
83 # We always want the bar to print when update() is called
84 return True
85
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086class NonInteractiveProgress(object):
87 fobj = sys.stdout
88
89 def __init__(self, msg, maxval):
90 self.msg = msg
91 self.maxval = maxval
Patrick Williamsc0f7c042017-02-23 20:41:17 -060092 self.finished = False
Patrick Williamsc124f4f2015-09-15 14:41:29 -050093
Patrick Williamsc0f7c042017-02-23 20:41:17 -060094 def start(self, update=True):
Patrick Williamsc124f4f2015-09-15 14:41:29 -050095 self.fobj.write("%s..." % self.msg)
96 self.fobj.flush()
97 return self
98
99 def update(self, value):
100 pass
101
102 def finish(self):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600103 if self.finished:
104 return
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500105 self.fobj.write("done.\n")
106 self.fobj.flush()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600107 self.finished = True
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500108
109def new_progress(msg, maxval):
110 if interactive:
111 return BBProgress(msg, maxval)
112 else:
113 return NonInteractiveProgress(msg, maxval)
114
115def pluralise(singular, plural, qty):
116 if(qty == 1):
117 return singular % qty
118 else:
119 return plural % qty
120
121
122class InteractConsoleLogFilter(logging.Filter):
123 def __init__(self, tf, format):
124 self.tf = tf
125 self.format = format
126
127 def filter(self, record):
128 if record.levelno == self.format.NOTE and (record.msg.startswith("Running") or record.msg.startswith("recipe ")):
129 return False
130 self.tf.clearFooter()
131 return True
132
133class TerminalFilter(object):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500134 rows = 25
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500135 columns = 80
136
137 def sigwinch_handle(self, signum, frame):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500138 self.rows, self.columns = self.getTerminalColumns()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500139 if self._sigwinch_default:
140 self._sigwinch_default(signum, frame)
141
142 def getTerminalColumns(self):
143 def ioctl_GWINSZ(fd):
144 try:
145 cr = struct.unpack('hh', fcntl.ioctl(fd, self.termios.TIOCGWINSZ, '1234'))
146 except:
147 return None
148 return cr
149 cr = ioctl_GWINSZ(sys.stdout.fileno())
150 if not cr:
151 try:
152 fd = os.open(os.ctermid(), os.O_RDONLY)
153 cr = ioctl_GWINSZ(fd)
154 os.close(fd)
155 except:
156 pass
157 if not cr:
158 try:
159 cr = (env['LINES'], env['COLUMNS'])
160 except:
161 cr = (25, 80)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500162 return cr
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500163
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600164 def __init__(self, main, helper, console, errconsole, format, quiet):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500165 self.main = main
166 self.helper = helper
167 self.cuu = None
168 self.stdinbackup = None
169 self.interactive = sys.stdout.isatty()
170 self.footer_present = False
171 self.lastpids = []
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600172 self.lasttime = None
173 self.quiet = quiet
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500174
175 if not self.interactive:
176 return
177
178 try:
179 import curses
180 except ImportError:
181 sys.exit("FATAL: The knotty ui could not load the required curses python module.")
182
183 import termios
184 self.curses = curses
185 self.termios = termios
186 try:
187 fd = sys.stdin.fileno()
188 self.stdinbackup = termios.tcgetattr(fd)
189 new = copy.deepcopy(self.stdinbackup)
190 new[3] = new[3] & ~termios.ECHO
191 termios.tcsetattr(fd, termios.TCSADRAIN, new)
192 curses.setupterm()
193 if curses.tigetnum("colors") > 2:
194 format.enable_color()
195 self.ed = curses.tigetstr("ed")
196 if self.ed:
197 self.cuu = curses.tigetstr("cuu")
198 try:
199 self._sigwinch_default = signal.getsignal(signal.SIGWINCH)
200 signal.signal(signal.SIGWINCH, self.sigwinch_handle)
201 except:
202 pass
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500203 self.rows, self.columns = self.getTerminalColumns()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500204 except:
205 self.cuu = None
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500206 if not self.cuu:
207 self.interactive = False
208 bb.note("Unable to use interactive mode for this terminal, using fallback")
209 return
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500210 if console:
211 console.addFilter(InteractConsoleLogFilter(self, format))
212 if errconsole:
213 errconsole.addFilter(InteractConsoleLogFilter(self, format))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500214
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))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500287 if self.quiet == 0:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600288 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
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500315def print_event_log(event, includelogs, loglines, termfilter):
316 # FIXME refactor this out further
317 logfile = event.logfile
318 if logfile and os.path.exists(logfile):
319 termfilter.clearFooter()
320 bb.error("Logfile of failure stored in: %s" % logfile)
321 if includelogs and not event.errprinted:
322 print("Log data follows:")
323 f = open(logfile, "r")
324 lines = []
325 while True:
326 l = f.readline()
327 if l == '':
328 break
329 l = l.rstrip()
330 if loglines:
331 lines.append(' | %s' % l)
332 if len(lines) > int(loglines):
333 lines.pop(0)
334 else:
335 print('| %s' % l)
336 f.close()
337 if lines:
338 for line in lines:
339 print(line)
340
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500341def _log_settings_from_server(server, observe_only):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500342 # Get values of variables which control our output
343 includelogs, error = server.runCommand(["getVariable", "BBINCLUDELOGS"])
344 if error:
345 logger.error("Unable to get the value of BBINCLUDELOGS variable: %s" % error)
346 raise BaseException(error)
347 loglines, error = server.runCommand(["getVariable", "BBINCLUDELOGS_LINES"])
348 if error:
349 logger.error("Unable to get the value of BBINCLUDELOGS_LINES variable: %s" % error)
350 raise BaseException(error)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500351 if observe_only:
352 cmd = 'getVariable'
353 else:
354 cmd = 'getSetVariable'
355 consolelogfile, error = server.runCommand([cmd, "BB_CONSOLELOG"])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500356 if error:
357 logger.error("Unable to get the value of BB_CONSOLELOG variable: %s" % error)
358 raise BaseException(error)
359 return includelogs, loglines, consolelogfile
360
361_evt_list = [ "bb.runqueue.runQueueExitWait", "bb.event.LogExecTTY", "logging.LogRecord",
362 "bb.build.TaskFailed", "bb.build.TaskBase", "bb.event.ParseStarted",
363 "bb.event.ParseProgress", "bb.event.ParseCompleted", "bb.event.CacheLoadStarted",
364 "bb.event.CacheLoadProgress", "bb.event.CacheLoadCompleted", "bb.command.CommandFailed",
365 "bb.command.CommandExit", "bb.command.CommandCompleted", "bb.cooker.CookerExit",
366 "bb.event.MultipleProviders", "bb.event.NoProvider", "bb.runqueue.sceneQueueTaskStarted",
367 "bb.runqueue.runQueueTaskStarted", "bb.runqueue.runQueueTaskFailed", "bb.runqueue.sceneQueueTaskFailed",
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600368 "bb.event.BuildBase", "bb.build.TaskStarted", "bb.build.TaskSucceeded", "bb.build.TaskFailedSilent",
369 "bb.build.TaskProgress", "bb.event.ProcessStarted", "bb.event.ProcessProgress", "bb.event.ProcessFinished"]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500370
371def main(server, eventHandler, params, tf = TerminalFilter):
372
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500373 if not params.observe_only:
374 params.updateToServer(server, os.environ.copy())
375
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500376 includelogs, loglines, consolelogfile = _log_settings_from_server(server, params.observe_only)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500377
378 if sys.stdin.isatty() and sys.stdout.isatty():
379 log_exec_tty = True
380 else:
381 log_exec_tty = False
382
383 helper = uihelper.BBUIHelper()
384
385 console = logging.StreamHandler(sys.stdout)
386 errconsole = logging.StreamHandler(sys.stderr)
387 format_str = "%(levelname)s: %(message)s"
388 format = bb.msg.BBLogFormatter(format_str)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500389 if params.options.quiet == 0:
390 forcelevel = None
391 elif params.options.quiet > 2:
392 forcelevel = bb.msg.BBLogFormatter.ERROR
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600393 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500394 forcelevel = bb.msg.BBLogFormatter.WARNING
395 bb.msg.addDefaultlogFilter(console, bb.msg.BBLogFilterStdOut, forcelevel)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500396 bb.msg.addDefaultlogFilter(errconsole, bb.msg.BBLogFilterStdErr)
397 console.setFormatter(format)
398 errconsole.setFormatter(format)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500399 if not bb.msg.has_console_handler(logger):
400 logger.addHandler(console)
401 logger.addHandler(errconsole)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500402
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500403 bb.utils.set_process_name("KnottyUI")
404
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500405 if params.options.remote_server and params.options.kill_server:
406 server.terminateServer()
407 return
408
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600409 consolelog = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500410 if consolelogfile and not params.options.show_environment and not params.options.show_versions:
411 bb.utils.mkdirhier(os.path.dirname(consolelogfile))
412 conlogformat = bb.msg.BBLogFormatter(format_str)
413 consolelog = logging.FileHandler(consolelogfile)
414 bb.msg.addDefaultlogFilter(consolelog)
415 consolelog.setFormatter(conlogformat)
416 logger.addHandler(consolelog)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600417 loglink = os.path.join(os.path.dirname(consolelogfile), 'console-latest.log')
418 bb.utils.remove(loglink)
419 try:
420 os.symlink(os.path.basename(consolelogfile), loglink)
421 except OSError:
422 pass
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500423
424 llevel, debug_domains = bb.msg.constructLogOptions()
425 server.runCommand(["setEventMask", server.getEventHandle(), llevel, debug_domains, _evt_list])
426
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500427 universe = False
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500428 if not params.observe_only:
429 params.updateFromServer(server)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500430 cmdline = params.parseActions()
431 if not cmdline:
432 print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.")
433 return 1
434 if 'msg' in cmdline and cmdline['msg']:
435 logger.error(cmdline['msg'])
436 return 1
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500437 if cmdline['action'][0] == "buildTargets" and "universe" in cmdline['action'][1]:
438 universe = True
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500439
440 ret, error = server.runCommand(cmdline['action'])
441 if error:
442 logger.error("Command '%s' failed: %s" % (cmdline, error))
443 return 1
444 elif ret != True:
445 logger.error("Command '%s' failed: returned %s" % (cmdline, ret))
446 return 1
447
448
449 parseprogress = None
450 cacheprogress = None
451 main.shutdown = 0
452 interrupted = False
453 return_value = 0
454 errors = 0
455 warnings = 0
456 taskfailures = []
457
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600458 termfilter = tf(main, helper, console, errconsole, format, params.options.quiet)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500459 atexit.register(termfilter.finish)
460
461 while True:
462 try:
463 event = eventHandler.waitEvent(0)
464 if event is None:
465 if main.shutdown > 1:
466 break
467 termfilter.updateFooter()
468 event = eventHandler.waitEvent(0.25)
469 if event is None:
470 continue
471 helper.eventHandler(event)
472 if isinstance(event, bb.runqueue.runQueueExitWait):
473 if not main.shutdown:
474 main.shutdown = 1
475 continue
476 if isinstance(event, bb.event.LogExecTTY):
477 if log_exec_tty:
478 tries = event.retries
479 while tries:
480 print("Trying to run: %s" % event.prog)
481 if os.system(event.prog) == 0:
482 break
483 time.sleep(event.sleep_delay)
484 tries -= 1
485 if tries:
486 continue
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600487 logger.warning(event.msg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500488 continue
489
490 if isinstance(event, logging.LogRecord):
491 if event.levelno >= format.ERROR:
492 errors = errors + 1
493 return_value = 1
494 elif event.levelno == format.WARNING:
495 warnings = warnings + 1
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500496
497 if event.taskpid != 0:
498 # For "normal" logging conditions, don't show note logs from tasks
499 # but do show them if the user has changed the default log level to
500 # include verbose/debug messages
501 if event.levelno <= format.NOTE and (event.levelno < llevel or (event.levelno == format.NOTE and llevel != format.VERBOSE)):
502 continue
503
504 # Prefix task messages with recipe/task
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500505 if event.taskpid in helper.running_tasks and event.levelno != format.PLAIN:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500506 taskinfo = helper.running_tasks[event.taskpid]
507 event.msg = taskinfo['title'] + ': ' + event.msg
508 if hasattr(event, 'fn'):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500509 event.msg = event.fn + ': ' + event.msg
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500510 logger.handle(event)
511 continue
512
513 if isinstance(event, bb.build.TaskFailedSilent):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600514 logger.warning("Logfile for failed setscene task is %s" % event.logfile)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500515 continue
516 if isinstance(event, bb.build.TaskFailed):
517 return_value = 1
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500518 print_event_log(event, includelogs, loglines, termfilter)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500519 if isinstance(event, bb.build.TaskBase):
520 logger.info(event._message)
521 continue
522 if isinstance(event, bb.event.ParseStarted):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500523 if params.options.quiet > 1:
524 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500525 if event.total == 0:
526 continue
527 parseprogress = new_progress("Parsing recipes", event.total).start()
528 continue
529 if isinstance(event, bb.event.ParseProgress):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500530 if params.options.quiet > 1:
531 continue
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600532 if parseprogress:
533 parseprogress.update(event.current)
534 else:
535 bb.warn("Got ParseProgress event for parsing that never started?")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500536 continue
537 if isinstance(event, bb.event.ParseCompleted):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500538 if params.options.quiet > 1:
539 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500540 if not parseprogress:
541 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500542 parseprogress.finish()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600543 pasreprogress = None
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500544 if params.options.quiet == 0:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600545 print(("Parsing of %d .bb files complete (%d cached, %d parsed). %d targets, %d skipped, %d masked, %d errors."
546 % ( event.total, event.cached, event.parsed, event.virtuals, event.skipped, event.masked, event.errors)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500547 continue
548
549 if isinstance(event, bb.event.CacheLoadStarted):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500550 if params.options.quiet > 1:
551 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500552 cacheprogress = new_progress("Loading cache", event.total).start()
553 continue
554 if isinstance(event, bb.event.CacheLoadProgress):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500555 if params.options.quiet > 1:
556 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500557 cacheprogress.update(event.current)
558 continue
559 if isinstance(event, bb.event.CacheLoadCompleted):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500560 if params.options.quiet > 1:
561 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500562 cacheprogress.finish()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500563 if params.options.quiet == 0:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600564 print("Loaded %d entries from dependency cache." % event.num_entries)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500565 continue
566
567 if isinstance(event, bb.command.CommandFailed):
568 return_value = event.exitcode
569 if event.error:
570 errors = errors + 1
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500571 logger.error(str(event))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500572 main.shutdown = 2
573 continue
574 if isinstance(event, bb.command.CommandExit):
575 if not return_value:
576 return_value = event.exitcode
577 continue
578 if isinstance(event, (bb.command.CommandCompleted, bb.cooker.CookerExit)):
579 main.shutdown = 2
580 continue
581 if isinstance(event, bb.event.MultipleProviders):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500582 logger.info(str(event))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500583 continue
584 if isinstance(event, bb.event.NoProvider):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500585 # For universe builds, only show these as warnings, not errors
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500586 if not universe:
587 return_value = 1
588 errors = errors + 1
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500589 logger.error(str(event))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500590 else:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500591 logger.warning(str(event))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500592 continue
593
594 if isinstance(event, bb.runqueue.sceneQueueTaskStarted):
595 logger.info("Running setscene task %d of %d (%s)" % (event.stats.completed + event.stats.active + event.stats.failed + 1, event.stats.total, event.taskstring))
596 continue
597
598 if isinstance(event, bb.runqueue.runQueueTaskStarted):
599 if event.noexec:
600 tasktype = 'noexec task'
601 else:
602 tasktype = 'task'
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600603 logger.info("Running %s %d of %d (%s)",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500604 tasktype,
605 event.stats.completed + event.stats.active +
606 event.stats.failed + 1,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600607 event.stats.total, event.taskstring)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500608 continue
609
610 if isinstance(event, bb.runqueue.runQueueTaskFailed):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500611 return_value = 1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500612 taskfailures.append(event.taskstring)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500613 logger.error(str(event))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500614 continue
615
616 if isinstance(event, bb.runqueue.sceneQueueTaskFailed):
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500617 logger.warning(str(event))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500618 continue
619
620 if isinstance(event, bb.event.DepTreeGenerated):
621 continue
622
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600623 if isinstance(event, bb.event.ProcessStarted):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500624 if params.options.quiet > 1:
625 continue
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600626 parseprogress = new_progress(event.processname, event.total)
627 parseprogress.start(False)
628 continue
629 if isinstance(event, bb.event.ProcessProgress):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500630 if params.options.quiet > 1:
631 continue
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600632 if parseprogress:
633 parseprogress.update(event.progress)
634 else:
635 bb.warn("Got ProcessProgress event for someting that never started?")
636 continue
637 if isinstance(event, bb.event.ProcessFinished):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500638 if params.options.quiet > 1:
639 continue
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600640 if parseprogress:
641 parseprogress.finish()
642 parseprogress = None
643 continue
644
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500645 # ignore
646 if isinstance(event, (bb.event.BuildBase,
647 bb.event.MetadataEvent,
648 bb.event.StampUpdate,
649 bb.event.ConfigParsed,
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500650 bb.event.MultiConfigParsed,
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500651 bb.event.RecipeParsed,
652 bb.event.RecipePreFinalise,
653 bb.runqueue.runQueueEvent,
654 bb.event.OperationStarted,
655 bb.event.OperationCompleted,
656 bb.event.OperationProgress,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600657 bb.event.DiskFull,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500658 bb.event.HeartbeatEvent,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600659 bb.build.TaskProgress)):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500660 continue
661
662 logger.error("Unknown event: %s", event)
663
664 except EnvironmentError as ioerror:
665 termfilter.clearFooter()
666 # ignore interrupted io
667 if ioerror.args[0] == 4:
668 continue
669 sys.stderr.write(str(ioerror))
670 if not params.observe_only:
671 _, error = server.runCommand(["stateForceShutdown"])
672 main.shutdown = 2
673 except KeyboardInterrupt:
674 termfilter.clearFooter()
675 if params.observe_only:
676 print("\nKeyboard Interrupt, exiting observer...")
677 main.shutdown = 2
678 if not params.observe_only and main.shutdown == 1:
679 print("\nSecond Keyboard Interrupt, stopping...\n")
680 _, error = server.runCommand(["stateForceShutdown"])
681 if error:
682 logger.error("Unable to cleanly stop: %s" % error)
683 if not params.observe_only and main.shutdown == 0:
684 print("\nKeyboard Interrupt, closing down...\n")
685 interrupted = True
686 _, error = server.runCommand(["stateShutdown"])
687 if error:
688 logger.error("Unable to cleanly shutdown: %s" % error)
689 main.shutdown = main.shutdown + 1
690 pass
691 except Exception as e:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500692 import traceback
693 sys.stderr.write(traceback.format_exc())
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500694 if not params.observe_only:
695 _, error = server.runCommand(["stateForceShutdown"])
696 main.shutdown = 2
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500697 return_value = 1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500698 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600699 termfilter.clearFooter()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500700 summary = ""
701 if taskfailures:
702 summary += pluralise("\nSummary: %s task failed:",
703 "\nSummary: %s tasks failed:", len(taskfailures))
704 for failure in taskfailures:
705 summary += "\n %s" % failure
706 if warnings:
707 summary += pluralise("\nSummary: There was %s WARNING message shown.",
708 "\nSummary: There were %s WARNING messages shown.", warnings)
709 if return_value and errors:
710 summary += pluralise("\nSummary: There was %s ERROR message shown, returning a non-zero exit code.",
711 "\nSummary: There were %s ERROR messages shown, returning a non-zero exit code.", errors)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500712 if summary and params.options.quiet == 0:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500713 print(summary)
714
715 if interrupted:
716 print("Execution was interrupted, returning a non-zero exit code.")
717 if return_value == 0:
718 return_value = 1
719 except IOError as e:
720 import errno
721 if e.errno == errno.EPIPE:
722 pass
723
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600724 if consolelog:
725 logger.removeHandler(consolelog)
726 consolelog.close()
727
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500728 return return_value