blob: 82aa7c46448b28d586cfb3b02d1f095afbfc077a [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
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500210 console.addFilter(InteractConsoleLogFilter(self, format))
211 errconsole.addFilter(InteractConsoleLogFilter(self, format))
212
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600213 self.main_progress = None
214
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500215 def clearFooter(self):
216 if self.footer_present:
217 lines = self.footer_present
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600218 sys.stdout.buffer.write(self.curses.tparm(self.cuu, lines))
219 sys.stdout.buffer.write(self.curses.tparm(self.ed))
220 sys.stdout.flush()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500221 self.footer_present = False
222
223 def updateFooter(self):
224 if not self.cuu:
225 return
226 activetasks = self.helper.running_tasks
227 failedtasks = self.helper.failed_tasks
228 runningpids = self.helper.running_pids
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600229 currenttime = time.time()
230 if not self.lasttime or (currenttime - self.lasttime > 5):
231 self.helper.needUpdate = True
232 self.lasttime = currenttime
233 if self.footer_present and not self.helper.needUpdate:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234 return
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600235 self.helper.needUpdate = False
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500236 if self.footer_present:
237 self.clearFooter()
238 if (not self.helper.tasknumber_total or self.helper.tasknumber_current == self.helper.tasknumber_total) and not len(activetasks):
239 return
240 tasks = []
241 for t in runningpids:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600242 progress = activetasks[t].get("progress", None)
243 if progress is not None:
244 pbar = activetasks[t].get("progressbar", None)
245 rate = activetasks[t].get("rate", None)
246 start_time = activetasks[t].get("starttime", None)
247 if not pbar or pbar.bouncing != (progress < 0):
248 if progress < 0:
249 pbar = BBProgress("0: %s (pid %s) " % (activetasks[t]["title"], t), 100, widgets=[progressbar.BouncingSlider(), ''], extrapos=2, resize_handler=self.sigwinch_handle)
250 pbar.bouncing = True
251 else:
252 pbar = BBProgress("0: %s (pid %s) " % (activetasks[t]["title"], t), 100, widgets=[progressbar.Percentage(), ' ', progressbar.Bar(), ''], extrapos=4, resize_handler=self.sigwinch_handle)
253 pbar.bouncing = False
254 activetasks[t]["progressbar"] = pbar
255 tasks.append((pbar, progress, rate, start_time))
256 else:
257 start_time = activetasks[t].get("starttime", None)
258 if start_time:
259 tasks.append("%s - %ds (pid %s)" % (activetasks[t]["title"], currenttime - start_time, t))
260 else:
261 tasks.append("%s (pid %s)" % (activetasks[t]["title"], t))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500262
263 if self.main.shutdown:
264 content = "Waiting for %s running tasks to finish:" % len(activetasks)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500265 print(content)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600266 else:
267 if self.quiet:
268 content = "Running tasks (%s of %s)" % (self.helper.tasknumber_current, self.helper.tasknumber_total)
269 elif not len(activetasks):
270 content = "No currently running tasks (%s of %s)" % (self.helper.tasknumber_current, self.helper.tasknumber_total)
271 else:
272 content = "Currently %2s running tasks (%s of %s)" % (len(activetasks), self.helper.tasknumber_current, self.helper.tasknumber_total)
273 maxtask = self.helper.tasknumber_total
274 if not self.main_progress or self.main_progress.maxval != maxtask:
275 widgets = [' ', progressbar.Percentage(), ' ', progressbar.Bar()]
276 self.main_progress = BBProgress("Running tasks", maxtask, widgets=widgets, resize_handler=self.sigwinch_handle)
277 self.main_progress.start(False)
278 self.main_progress.setmessage(content)
279 progress = self.helper.tasknumber_current - 1
280 if progress < 0:
281 progress = 0
282 content = self.main_progress.update(progress)
283 print('')
284 lines = 1 + int(len(content) / (self.columns + 1))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500285 if self.quiet == 0:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600286 for tasknum, task in enumerate(tasks[:(self.rows - 2)]):
287 if isinstance(task, tuple):
288 pbar, progress, rate, start_time = task
289 if not pbar.start_time:
290 pbar.start(False)
291 if start_time:
292 pbar.start_time = start_time
293 pbar.setmessage('%s:%s' % (tasknum, pbar.msg.split(':', 1)[1]))
294 if progress > -1:
295 pbar.setextra(rate)
296 content = pbar.update(progress)
297 else:
298 content = pbar.update(1)
299 print('')
300 else:
301 content = "%s: %s" % (tasknum, task)
302 print(content)
303 lines = lines + 1 + int(len(content) / (self.columns + 1))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500304 self.footer_present = lines
305 self.lastpids = runningpids[:]
306 self.lastcount = self.helper.tasknumber_current
307
308 def finish(self):
309 if self.stdinbackup:
310 fd = sys.stdin.fileno()
311 self.termios.tcsetattr(fd, self.termios.TCSADRAIN, self.stdinbackup)
312
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500313def _log_settings_from_server(server, observe_only):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500314 # Get values of variables which control our output
315 includelogs, error = server.runCommand(["getVariable", "BBINCLUDELOGS"])
316 if error:
317 logger.error("Unable to get the value of BBINCLUDELOGS variable: %s" % error)
318 raise BaseException(error)
319 loglines, error = server.runCommand(["getVariable", "BBINCLUDELOGS_LINES"])
320 if error:
321 logger.error("Unable to get the value of BBINCLUDELOGS_LINES variable: %s" % error)
322 raise BaseException(error)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500323 if observe_only:
324 cmd = 'getVariable'
325 else:
326 cmd = 'getSetVariable'
327 consolelogfile, error = server.runCommand([cmd, "BB_CONSOLELOG"])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500328 if error:
329 logger.error("Unable to get the value of BB_CONSOLELOG variable: %s" % error)
330 raise BaseException(error)
331 return includelogs, loglines, consolelogfile
332
333_evt_list = [ "bb.runqueue.runQueueExitWait", "bb.event.LogExecTTY", "logging.LogRecord",
334 "bb.build.TaskFailed", "bb.build.TaskBase", "bb.event.ParseStarted",
335 "bb.event.ParseProgress", "bb.event.ParseCompleted", "bb.event.CacheLoadStarted",
336 "bb.event.CacheLoadProgress", "bb.event.CacheLoadCompleted", "bb.command.CommandFailed",
337 "bb.command.CommandExit", "bb.command.CommandCompleted", "bb.cooker.CookerExit",
338 "bb.event.MultipleProviders", "bb.event.NoProvider", "bb.runqueue.sceneQueueTaskStarted",
339 "bb.runqueue.runQueueTaskStarted", "bb.runqueue.runQueueTaskFailed", "bb.runqueue.sceneQueueTaskFailed",
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600340 "bb.event.BuildBase", "bb.build.TaskStarted", "bb.build.TaskSucceeded", "bb.build.TaskFailedSilent",
341 "bb.build.TaskProgress", "bb.event.ProcessStarted", "bb.event.ProcessProgress", "bb.event.ProcessFinished"]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500342
343def main(server, eventHandler, params, tf = TerminalFilter):
344
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500345 includelogs, loglines, consolelogfile = _log_settings_from_server(server, params.observe_only)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500346
347 if sys.stdin.isatty() and sys.stdout.isatty():
348 log_exec_tty = True
349 else:
350 log_exec_tty = False
351
352 helper = uihelper.BBUIHelper()
353
354 console = logging.StreamHandler(sys.stdout)
355 errconsole = logging.StreamHandler(sys.stderr)
356 format_str = "%(levelname)s: %(message)s"
357 format = bb.msg.BBLogFormatter(format_str)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500358 if params.options.quiet == 0:
359 forcelevel = None
360 elif params.options.quiet > 2:
361 forcelevel = bb.msg.BBLogFormatter.ERROR
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600362 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500363 forcelevel = bb.msg.BBLogFormatter.WARNING
364 bb.msg.addDefaultlogFilter(console, bb.msg.BBLogFilterStdOut, forcelevel)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500365 bb.msg.addDefaultlogFilter(errconsole, bb.msg.BBLogFilterStdErr)
366 console.setFormatter(format)
367 errconsole.setFormatter(format)
368 logger.addHandler(console)
369 logger.addHandler(errconsole)
370
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500371 bb.utils.set_process_name("KnottyUI")
372
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500373 if params.options.remote_server and params.options.kill_server:
374 server.terminateServer()
375 return
376
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600377 consolelog = None
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500378 if consolelogfile and not params.options.show_environment and not params.options.show_versions:
379 bb.utils.mkdirhier(os.path.dirname(consolelogfile))
380 conlogformat = bb.msg.BBLogFormatter(format_str)
381 consolelog = logging.FileHandler(consolelogfile)
382 bb.msg.addDefaultlogFilter(consolelog)
383 consolelog.setFormatter(conlogformat)
384 logger.addHandler(consolelog)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600385 loglink = os.path.join(os.path.dirname(consolelogfile), 'console-latest.log')
386 bb.utils.remove(loglink)
387 try:
388 os.symlink(os.path.basename(consolelogfile), loglink)
389 except OSError:
390 pass
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500391
392 llevel, debug_domains = bb.msg.constructLogOptions()
393 server.runCommand(["setEventMask", server.getEventHandle(), llevel, debug_domains, _evt_list])
394
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500395 universe = False
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500396 if not params.observe_only:
397 params.updateFromServer(server)
398 params.updateToServer(server, os.environ.copy())
399 cmdline = params.parseActions()
400 if not cmdline:
401 print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.")
402 return 1
403 if 'msg' in cmdline and cmdline['msg']:
404 logger.error(cmdline['msg'])
405 return 1
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500406 if cmdline['action'][0] == "buildTargets" and "universe" in cmdline['action'][1]:
407 universe = True
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500408
409 ret, error = server.runCommand(cmdline['action'])
410 if error:
411 logger.error("Command '%s' failed: %s" % (cmdline, error))
412 return 1
413 elif ret != True:
414 logger.error("Command '%s' failed: returned %s" % (cmdline, ret))
415 return 1
416
417
418 parseprogress = None
419 cacheprogress = None
420 main.shutdown = 0
421 interrupted = False
422 return_value = 0
423 errors = 0
424 warnings = 0
425 taskfailures = []
426
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600427 termfilter = tf(main, helper, console, errconsole, format, params.options.quiet)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500428 atexit.register(termfilter.finish)
429
430 while True:
431 try:
432 event = eventHandler.waitEvent(0)
433 if event is None:
434 if main.shutdown > 1:
435 break
436 termfilter.updateFooter()
437 event = eventHandler.waitEvent(0.25)
438 if event is None:
439 continue
440 helper.eventHandler(event)
441 if isinstance(event, bb.runqueue.runQueueExitWait):
442 if not main.shutdown:
443 main.shutdown = 1
444 continue
445 if isinstance(event, bb.event.LogExecTTY):
446 if log_exec_tty:
447 tries = event.retries
448 while tries:
449 print("Trying to run: %s" % event.prog)
450 if os.system(event.prog) == 0:
451 break
452 time.sleep(event.sleep_delay)
453 tries -= 1
454 if tries:
455 continue
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600456 logger.warning(event.msg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500457 continue
458
459 if isinstance(event, logging.LogRecord):
460 if event.levelno >= format.ERROR:
461 errors = errors + 1
462 return_value = 1
463 elif event.levelno == format.WARNING:
464 warnings = warnings + 1
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500465
466 if event.taskpid != 0:
467 # For "normal" logging conditions, don't show note logs from tasks
468 # but do show them if the user has changed the default log level to
469 # include verbose/debug messages
470 if event.levelno <= format.NOTE and (event.levelno < llevel or (event.levelno == format.NOTE and llevel != format.VERBOSE)):
471 continue
472
473 # Prefix task messages with recipe/task
474 if event.taskpid in helper.running_tasks:
475 taskinfo = helper.running_tasks[event.taskpid]
476 event.msg = taskinfo['title'] + ': ' + event.msg
477 if hasattr(event, 'fn'):
478 event.msg = event.fn + ': ' + event.msg
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500479 logger.handle(event)
480 continue
481
482 if isinstance(event, bb.build.TaskFailedSilent):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600483 logger.warning("Logfile for failed setscene task is %s" % event.logfile)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500484 continue
485 if isinstance(event, bb.build.TaskFailed):
486 return_value = 1
487 logfile = event.logfile
488 if logfile and os.path.exists(logfile):
489 termfilter.clearFooter()
490 bb.error("Logfile of failure stored in: %s" % logfile)
491 if includelogs and not event.errprinted:
492 print("Log data follows:")
493 f = open(logfile, "r")
494 lines = []
495 while True:
496 l = f.readline()
497 if l == '':
498 break
499 l = l.rstrip()
500 if loglines:
501 lines.append(' | %s' % l)
502 if len(lines) > int(loglines):
503 lines.pop(0)
504 else:
505 print('| %s' % l)
506 f.close()
507 if lines:
508 for line in lines:
509 print(line)
510 if isinstance(event, bb.build.TaskBase):
511 logger.info(event._message)
512 continue
513 if isinstance(event, bb.event.ParseStarted):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500514 if params.options.quiet > 1:
515 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500516 if event.total == 0:
517 continue
518 parseprogress = new_progress("Parsing recipes", event.total).start()
519 continue
520 if isinstance(event, bb.event.ParseProgress):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500521 if params.options.quiet > 1:
522 continue
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600523 if parseprogress:
524 parseprogress.update(event.current)
525 else:
526 bb.warn("Got ParseProgress event for parsing that never started?")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500527 continue
528 if isinstance(event, bb.event.ParseCompleted):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500529 if params.options.quiet > 1:
530 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500531 if not parseprogress:
532 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500533 parseprogress.finish()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600534 pasreprogress = None
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500535 if params.options.quiet == 0:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600536 print(("Parsing of %d .bb files complete (%d cached, %d parsed). %d targets, %d skipped, %d masked, %d errors."
537 % ( event.total, event.cached, event.parsed, event.virtuals, event.skipped, event.masked, event.errors)))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500538 continue
539
540 if isinstance(event, bb.event.CacheLoadStarted):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500541 if params.options.quiet > 1:
542 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500543 cacheprogress = new_progress("Loading cache", event.total).start()
544 continue
545 if isinstance(event, bb.event.CacheLoadProgress):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500546 if params.options.quiet > 1:
547 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500548 cacheprogress.update(event.current)
549 continue
550 if isinstance(event, bb.event.CacheLoadCompleted):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500551 if params.options.quiet > 1:
552 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500553 cacheprogress.finish()
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500554 if params.options.quiet == 0:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600555 print("Loaded %d entries from dependency cache." % event.num_entries)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500556 continue
557
558 if isinstance(event, bb.command.CommandFailed):
559 return_value = event.exitcode
560 if event.error:
561 errors = errors + 1
562 logger.error("Command execution failed: %s", event.error)
563 main.shutdown = 2
564 continue
565 if isinstance(event, bb.command.CommandExit):
566 if not return_value:
567 return_value = event.exitcode
568 continue
569 if isinstance(event, (bb.command.CommandCompleted, bb.cooker.CookerExit)):
570 main.shutdown = 2
571 continue
572 if isinstance(event, bb.event.MultipleProviders):
573 logger.info("multiple providers are available for %s%s (%s)", event._is_runtime and "runtime " or "",
574 event._item,
575 ", ".join(event._candidates))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500576 rtime = ""
577 if event._is_runtime:
578 rtime = "R"
579 logger.info("consider defining a PREFERRED_%sPROVIDER entry to match %s" % (rtime, event._item))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500580 continue
581 if isinstance(event, bb.event.NoProvider):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500582 if event._runtime:
583 r = "R"
584 else:
585 r = ""
586
587 extra = ''
588 if not event._reasons:
589 if event._close_matches:
590 extra = ". Close matches:\n %s" % '\n '.join(event._close_matches)
591
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500592 # For universe builds, only show these as warnings, not errors
593 h = logger.warning
594 if not universe:
595 return_value = 1
596 errors = errors + 1
597 h = logger.error
598
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500599 if event._dependees:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500600 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 -0500601 else:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500602 h("Nothing %sPROVIDES '%s'%s", r, event._item, extra)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500603 if event._reasons:
604 for reason in event._reasons:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500605 h("%s", reason)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500606 continue
607
608 if isinstance(event, bb.runqueue.sceneQueueTaskStarted):
609 logger.info("Running setscene task %d of %d (%s)" % (event.stats.completed + event.stats.active + event.stats.failed + 1, event.stats.total, event.taskstring))
610 continue
611
612 if isinstance(event, bb.runqueue.runQueueTaskStarted):
613 if event.noexec:
614 tasktype = 'noexec task'
615 else:
616 tasktype = 'task'
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600617 logger.info("Running %s %d of %d (%s)",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500618 tasktype,
619 event.stats.completed + event.stats.active +
620 event.stats.failed + 1,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600621 event.stats.total, event.taskstring)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500622 continue
623
624 if isinstance(event, bb.runqueue.runQueueTaskFailed):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500625 return_value = 1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500626 taskfailures.append(event.taskstring)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600627 logger.error("Task (%s) failed with exit code '%s'",
628 event.taskstring, event.exitcode)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500629 continue
630
631 if isinstance(event, bb.runqueue.sceneQueueTaskFailed):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600632 logger.warning("Setscene task (%s) failed with exit code '%s' - real task will be run instead",
633 event.taskstring, event.exitcode)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500634 continue
635
636 if isinstance(event, bb.event.DepTreeGenerated):
637 continue
638
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600639 if isinstance(event, bb.event.ProcessStarted):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500640 if params.options.quiet > 1:
641 continue
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600642 parseprogress = new_progress(event.processname, event.total)
643 parseprogress.start(False)
644 continue
645 if isinstance(event, bb.event.ProcessProgress):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500646 if params.options.quiet > 1:
647 continue
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600648 if parseprogress:
649 parseprogress.update(event.progress)
650 else:
651 bb.warn("Got ProcessProgress event for someting that never started?")
652 continue
653 if isinstance(event, bb.event.ProcessFinished):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500654 if params.options.quiet > 1:
655 continue
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600656 if parseprogress:
657 parseprogress.finish()
658 parseprogress = None
659 continue
660
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500661 # ignore
662 if isinstance(event, (bb.event.BuildBase,
663 bb.event.MetadataEvent,
664 bb.event.StampUpdate,
665 bb.event.ConfigParsed,
666 bb.event.RecipeParsed,
667 bb.event.RecipePreFinalise,
668 bb.runqueue.runQueueEvent,
669 bb.event.OperationStarted,
670 bb.event.OperationCompleted,
671 bb.event.OperationProgress,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600672 bb.event.DiskFull,
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500673 bb.event.HeartbeatEvent,
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600674 bb.build.TaskProgress)):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500675 continue
676
677 logger.error("Unknown event: %s", event)
678
679 except EnvironmentError as ioerror:
680 termfilter.clearFooter()
681 # ignore interrupted io
682 if ioerror.args[0] == 4:
683 continue
684 sys.stderr.write(str(ioerror))
685 if not params.observe_only:
686 _, error = server.runCommand(["stateForceShutdown"])
687 main.shutdown = 2
688 except KeyboardInterrupt:
689 termfilter.clearFooter()
690 if params.observe_only:
691 print("\nKeyboard Interrupt, exiting observer...")
692 main.shutdown = 2
693 if not params.observe_only and main.shutdown == 1:
694 print("\nSecond Keyboard Interrupt, stopping...\n")
695 _, error = server.runCommand(["stateForceShutdown"])
696 if error:
697 logger.error("Unable to cleanly stop: %s" % error)
698 if not params.observe_only and main.shutdown == 0:
699 print("\nKeyboard Interrupt, closing down...\n")
700 interrupted = True
701 _, error = server.runCommand(["stateShutdown"])
702 if error:
703 logger.error("Unable to cleanly shutdown: %s" % error)
704 main.shutdown = main.shutdown + 1
705 pass
706 except Exception as e:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500707 import traceback
708 sys.stderr.write(traceback.format_exc())
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500709 if not params.observe_only:
710 _, error = server.runCommand(["stateForceShutdown"])
711 main.shutdown = 2
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500712 return_value = 1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500713 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600714 termfilter.clearFooter()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500715 summary = ""
716 if taskfailures:
717 summary += pluralise("\nSummary: %s task failed:",
718 "\nSummary: %s tasks failed:", len(taskfailures))
719 for failure in taskfailures:
720 summary += "\n %s" % failure
721 if warnings:
722 summary += pluralise("\nSummary: There was %s WARNING message shown.",
723 "\nSummary: There were %s WARNING messages shown.", warnings)
724 if return_value and errors:
725 summary += pluralise("\nSummary: There was %s ERROR message shown, returning a non-zero exit code.",
726 "\nSummary: There were %s ERROR messages shown, returning a non-zero exit code.", errors)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500727 if summary and params.options.quiet == 0:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500728 print(summary)
729
730 if interrupted:
731 print("Execution was interrupted, returning a non-zero exit code.")
732 if return_value == 0:
733 return_value = 1
734 except IOError as e:
735 import errno
736 if e.errno == errno.EPIPE:
737 pass
738
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600739 if consolelog:
740 logger.removeHandler(consolelog)
741 consolelog.close()
742
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500743 return return_value