Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 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 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 8 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | |
| 11 | from __future__ import division |
| 12 | |
| 13 | import os |
| 14 | import sys |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | import logging |
| 16 | import progressbar |
| 17 | import signal |
| 18 | import bb.msg |
| 19 | import time |
| 20 | import fcntl |
| 21 | import struct |
| 22 | import copy |
| 23 | import atexit |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 24 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 25 | from bb.ui import uihelper |
| 26 | |
| 27 | featureSet = [bb.cooker.CookerFeatures.SEND_SANITYEVENTS] |
| 28 | |
| 29 | logger = logging.getLogger("BitBake") |
| 30 | interactive = sys.stdout.isatty() |
| 31 | |
| 32 | class BBProgress(progressbar.ProgressBar): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 33 | def __init__(self, msg, maxval, widgets=None, extrapos=-1, resize_handler=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 34 | self.msg = msg |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 35 | self.extrapos = extrapos |
| 36 | if not widgets: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 37 | widgets = [': ', progressbar.Percentage(), ' ', progressbar.Bar(), |
| 38 | ' ', progressbar.ETA()] |
| 39 | self.extrapos = 5 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 41 | if resize_handler: |
| 42 | self._resize_default = resize_handler |
| 43 | else: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 44 | self._resize_default = signal.getsignal(signal.SIGWINCH) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 45 | progressbar.ProgressBar.__init__(self, maxval, [self.msg] + widgets, fd=sys.stdout) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 47 | def _handle_resize(self, signum=None, frame=None): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | progressbar.ProgressBar._handle_resize(self, signum, frame) |
| 49 | if self._resize_default: |
| 50 | self._resize_default(signum, frame) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 51 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 52 | def finish(self): |
| 53 | progressbar.ProgressBar.finish(self) |
| 54 | if self._resize_default: |
| 55 | signal.signal(signal.SIGWINCH, self._resize_default) |
| 56 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 57 | def setmessage(self, msg): |
| 58 | self.msg = msg |
| 59 | self.widgets[0] = msg |
| 60 | |
| 61 | def setextra(self, extra): |
| 62 | if self.extrapos > -1: |
| 63 | if extra: |
| 64 | extrastr = str(extra) |
| 65 | if extrastr[0] != ' ': |
| 66 | extrastr = ' ' + extrastr |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 67 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 68 | extrastr = '' |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 69 | self.widgets[self.extrapos] = extrastr |
| 70 | |
| 71 | def _need_update(self): |
| 72 | # We always want the bar to print when update() is called |
| 73 | return True |
| 74 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 75 | class NonInteractiveProgress(object): |
| 76 | fobj = sys.stdout |
| 77 | |
| 78 | def __init__(self, msg, maxval): |
| 79 | self.msg = msg |
| 80 | self.maxval = maxval |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 81 | self.finished = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 82 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 83 | def start(self, update=True): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 84 | self.fobj.write("%s..." % self.msg) |
| 85 | self.fobj.flush() |
| 86 | return self |
| 87 | |
| 88 | def update(self, value): |
| 89 | pass |
| 90 | |
| 91 | def finish(self): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 92 | if self.finished: |
| 93 | return |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 94 | self.fobj.write("done.\n") |
| 95 | self.fobj.flush() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 96 | self.finished = True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 97 | |
| 98 | def new_progress(msg, maxval): |
| 99 | if interactive: |
| 100 | return BBProgress(msg, maxval) |
| 101 | else: |
| 102 | return NonInteractiveProgress(msg, maxval) |
| 103 | |
| 104 | def pluralise(singular, plural, qty): |
| 105 | if(qty == 1): |
| 106 | return singular % qty |
| 107 | else: |
| 108 | return plural % qty |
| 109 | |
| 110 | |
| 111 | class InteractConsoleLogFilter(logging.Filter): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 112 | def __init__(self, tf): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 113 | self.tf = tf |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 114 | |
| 115 | def filter(self, record): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 116 | if record.levelno == bb.msg.BBLogFormatter.NOTE and (record.msg.startswith("Running") or record.msg.startswith("recipe ")): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | return False |
| 118 | self.tf.clearFooter() |
| 119 | return True |
| 120 | |
| 121 | class TerminalFilter(object): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 122 | rows = 25 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 123 | columns = 80 |
| 124 | |
| 125 | def sigwinch_handle(self, signum, frame): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 126 | self.rows, self.columns = self.getTerminalColumns() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 127 | if self._sigwinch_default: |
| 128 | self._sigwinch_default(signum, frame) |
| 129 | |
| 130 | def getTerminalColumns(self): |
| 131 | def ioctl_GWINSZ(fd): |
| 132 | try: |
| 133 | cr = struct.unpack('hh', fcntl.ioctl(fd, self.termios.TIOCGWINSZ, '1234')) |
| 134 | except: |
| 135 | return None |
| 136 | return cr |
| 137 | cr = ioctl_GWINSZ(sys.stdout.fileno()) |
| 138 | if not cr: |
| 139 | try: |
| 140 | fd = os.open(os.ctermid(), os.O_RDONLY) |
| 141 | cr = ioctl_GWINSZ(fd) |
| 142 | os.close(fd) |
| 143 | except: |
| 144 | pass |
| 145 | if not cr: |
| 146 | try: |
| 147 | cr = (env['LINES'], env['COLUMNS']) |
| 148 | except: |
| 149 | cr = (25, 80) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 150 | return cr |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 151 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 152 | def __init__(self, main, helper, handlers, quiet): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 153 | self.main = main |
| 154 | self.helper = helper |
| 155 | self.cuu = None |
| 156 | self.stdinbackup = None |
| 157 | self.interactive = sys.stdout.isatty() |
| 158 | self.footer_present = False |
| 159 | self.lastpids = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 160 | self.lasttime = None |
| 161 | self.quiet = quiet |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 162 | |
| 163 | if not self.interactive: |
| 164 | return |
| 165 | |
| 166 | try: |
| 167 | import curses |
| 168 | except ImportError: |
| 169 | sys.exit("FATAL: The knotty ui could not load the required curses python module.") |
| 170 | |
| 171 | import termios |
| 172 | self.curses = curses |
| 173 | self.termios = termios |
| 174 | try: |
| 175 | fd = sys.stdin.fileno() |
| 176 | self.stdinbackup = termios.tcgetattr(fd) |
| 177 | new = copy.deepcopy(self.stdinbackup) |
| 178 | new[3] = new[3] & ~termios.ECHO |
| 179 | termios.tcsetattr(fd, termios.TCSADRAIN, new) |
| 180 | curses.setupterm() |
| 181 | if curses.tigetnum("colors") > 2: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 182 | for h in handlers: |
| 183 | try: |
| 184 | h.formatter.enable_color() |
| 185 | except AttributeError: |
| 186 | pass |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 187 | self.ed = curses.tigetstr("ed") |
| 188 | if self.ed: |
| 189 | self.cuu = curses.tigetstr("cuu") |
| 190 | try: |
| 191 | self._sigwinch_default = signal.getsignal(signal.SIGWINCH) |
| 192 | signal.signal(signal.SIGWINCH, self.sigwinch_handle) |
| 193 | except: |
| 194 | pass |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 195 | self.rows, self.columns = self.getTerminalColumns() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 196 | except: |
| 197 | self.cuu = None |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 198 | if not self.cuu: |
| 199 | self.interactive = False |
| 200 | bb.note("Unable to use interactive mode for this terminal, using fallback") |
| 201 | return |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 202 | |
| 203 | for h in handlers: |
| 204 | h.addFilter(InteractConsoleLogFilter(self)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 205 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 206 | self.main_progress = None |
| 207 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 208 | def clearFooter(self): |
| 209 | if self.footer_present: |
| 210 | lines = self.footer_present |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 211 | sys.stdout.buffer.write(self.curses.tparm(self.cuu, lines)) |
| 212 | sys.stdout.buffer.write(self.curses.tparm(self.ed)) |
| 213 | sys.stdout.flush() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 214 | self.footer_present = False |
| 215 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 216 | def elapsed(self, sec): |
| 217 | hrs = int(sec / 3600.0) |
| 218 | sec -= hrs * 3600 |
| 219 | min = int(sec / 60.0) |
| 220 | sec -= min * 60 |
| 221 | if hrs > 0: |
| 222 | return "%dh%dm%ds" % (hrs, min, sec) |
| 223 | elif min > 0: |
| 224 | return "%dm%ds" % (min, sec) |
| 225 | else: |
| 226 | return "%ds" % (sec) |
| 227 | |
| 228 | def keepAlive(self, t): |
| 229 | if not self.cuu: |
| 230 | print("Bitbake still alive (%ds)" % t) |
| 231 | sys.stdout.flush() |
| 232 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 233 | def updateFooter(self): |
| 234 | if not self.cuu: |
| 235 | return |
| 236 | activetasks = self.helper.running_tasks |
| 237 | failedtasks = self.helper.failed_tasks |
| 238 | runningpids = self.helper.running_pids |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 239 | currenttime = time.time() |
| 240 | if not self.lasttime or (currenttime - self.lasttime > 5): |
| 241 | self.helper.needUpdate = True |
| 242 | self.lasttime = currenttime |
| 243 | if self.footer_present and not self.helper.needUpdate: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 244 | return |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 245 | self.helper.needUpdate = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 246 | if self.footer_present: |
| 247 | self.clearFooter() |
| 248 | if (not self.helper.tasknumber_total or self.helper.tasknumber_current == self.helper.tasknumber_total) and not len(activetasks): |
| 249 | return |
| 250 | tasks = [] |
| 251 | for t in runningpids: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 252 | progress = activetasks[t].get("progress", None) |
| 253 | if progress is not None: |
| 254 | pbar = activetasks[t].get("progressbar", None) |
| 255 | rate = activetasks[t].get("rate", None) |
| 256 | start_time = activetasks[t].get("starttime", None) |
| 257 | if not pbar or pbar.bouncing != (progress < 0): |
| 258 | if progress < 0: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 259 | pbar = BBProgress("0: %s (pid %s)" % (activetasks[t]["title"], activetasks[t]["pid"]), 100, widgets=[' ', progressbar.BouncingSlider(), ''], extrapos=3, resize_handler=self.sigwinch_handle) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 260 | pbar.bouncing = True |
| 261 | else: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 262 | pbar = BBProgress("0: %s (pid %s)" % (activetasks[t]["title"], activetasks[t]["pid"]), 100, widgets=[' ', progressbar.Percentage(), ' ', progressbar.Bar(), ''], extrapos=5, resize_handler=self.sigwinch_handle) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 263 | pbar.bouncing = False |
| 264 | activetasks[t]["progressbar"] = pbar |
| 265 | tasks.append((pbar, progress, rate, start_time)) |
| 266 | else: |
| 267 | start_time = activetasks[t].get("starttime", None) |
| 268 | if start_time: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 269 | tasks.append("%s - %s (pid %s)" % (activetasks[t]["title"], self.elapsed(currenttime - start_time), activetasks[t]["pid"])) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 270 | else: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 271 | tasks.append("%s (pid %s)" % (activetasks[t]["title"], activetasks[t]["pid"])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 272 | |
| 273 | if self.main.shutdown: |
| 274 | content = "Waiting for %s running tasks to finish:" % len(activetasks) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 275 | print(content) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 276 | else: |
| 277 | if self.quiet: |
| 278 | content = "Running tasks (%s of %s)" % (self.helper.tasknumber_current, self.helper.tasknumber_total) |
| 279 | elif not len(activetasks): |
| 280 | content = "No currently running tasks (%s of %s)" % (self.helper.tasknumber_current, self.helper.tasknumber_total) |
| 281 | else: |
| 282 | content = "Currently %2s running tasks (%s of %s)" % (len(activetasks), self.helper.tasknumber_current, self.helper.tasknumber_total) |
| 283 | maxtask = self.helper.tasknumber_total |
| 284 | if not self.main_progress or self.main_progress.maxval != maxtask: |
| 285 | widgets = [' ', progressbar.Percentage(), ' ', progressbar.Bar()] |
| 286 | self.main_progress = BBProgress("Running tasks", maxtask, widgets=widgets, resize_handler=self.sigwinch_handle) |
| 287 | self.main_progress.start(False) |
| 288 | self.main_progress.setmessage(content) |
| 289 | progress = self.helper.tasknumber_current - 1 |
| 290 | if progress < 0: |
| 291 | progress = 0 |
| 292 | content = self.main_progress.update(progress) |
| 293 | print('') |
| 294 | lines = 1 + int(len(content) / (self.columns + 1)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 295 | if self.quiet == 0: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 296 | for tasknum, task in enumerate(tasks[:(self.rows - 2)]): |
| 297 | if isinstance(task, tuple): |
| 298 | pbar, progress, rate, start_time = task |
| 299 | if not pbar.start_time: |
| 300 | pbar.start(False) |
| 301 | if start_time: |
| 302 | pbar.start_time = start_time |
| 303 | pbar.setmessage('%s:%s' % (tasknum, pbar.msg.split(':', 1)[1])) |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 304 | pbar.setextra(rate) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 305 | if progress > -1: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 306 | content = pbar.update(progress) |
| 307 | else: |
| 308 | content = pbar.update(1) |
| 309 | print('') |
| 310 | else: |
| 311 | content = "%s: %s" % (tasknum, task) |
| 312 | print(content) |
| 313 | lines = lines + 1 + int(len(content) / (self.columns + 1)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 314 | self.footer_present = lines |
| 315 | self.lastpids = runningpids[:] |
| 316 | self.lastcount = self.helper.tasknumber_current |
| 317 | |
| 318 | def finish(self): |
| 319 | if self.stdinbackup: |
| 320 | fd = sys.stdin.fileno() |
| 321 | self.termios.tcsetattr(fd, self.termios.TCSADRAIN, self.stdinbackup) |
| 322 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 323 | def print_event_log(event, includelogs, loglines, termfilter): |
| 324 | # FIXME refactor this out further |
| 325 | logfile = event.logfile |
| 326 | if logfile and os.path.exists(logfile): |
| 327 | termfilter.clearFooter() |
| 328 | bb.error("Logfile of failure stored in: %s" % logfile) |
| 329 | if includelogs and not event.errprinted: |
| 330 | print("Log data follows:") |
| 331 | f = open(logfile, "r") |
| 332 | lines = [] |
| 333 | while True: |
| 334 | l = f.readline() |
| 335 | if l == '': |
| 336 | break |
| 337 | l = l.rstrip() |
| 338 | if loglines: |
| 339 | lines.append(' | %s' % l) |
| 340 | if len(lines) > int(loglines): |
| 341 | lines.pop(0) |
| 342 | else: |
| 343 | print('| %s' % l) |
| 344 | f.close() |
| 345 | if lines: |
| 346 | for line in lines: |
| 347 | print(line) |
| 348 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 349 | def _log_settings_from_server(server, observe_only): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 350 | # Get values of variables which control our output |
| 351 | includelogs, error = server.runCommand(["getVariable", "BBINCLUDELOGS"]) |
| 352 | if error: |
| 353 | logger.error("Unable to get the value of BBINCLUDELOGS variable: %s" % error) |
| 354 | raise BaseException(error) |
| 355 | loglines, error = server.runCommand(["getVariable", "BBINCLUDELOGS_LINES"]) |
| 356 | if error: |
| 357 | logger.error("Unable to get the value of BBINCLUDELOGS_LINES variable: %s" % error) |
| 358 | raise BaseException(error) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 359 | if observe_only: |
| 360 | cmd = 'getVariable' |
| 361 | else: |
| 362 | cmd = 'getSetVariable' |
| 363 | consolelogfile, error = server.runCommand([cmd, "BB_CONSOLELOG"]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 364 | if error: |
| 365 | logger.error("Unable to get the value of BB_CONSOLELOG variable: %s" % error) |
| 366 | raise BaseException(error) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 367 | logconfigfile, error = server.runCommand([cmd, "BB_LOGCONFIG"]) |
| 368 | if error: |
| 369 | logger.error("Unable to get the value of BB_LOGCONFIG variable: %s" % error) |
| 370 | raise BaseException(error) |
| 371 | return includelogs, loglines, consolelogfile, logconfigfile |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 372 | |
| 373 | _evt_list = [ "bb.runqueue.runQueueExitWait", "bb.event.LogExecTTY", "logging.LogRecord", |
| 374 | "bb.build.TaskFailed", "bb.build.TaskBase", "bb.event.ParseStarted", |
| 375 | "bb.event.ParseProgress", "bb.event.ParseCompleted", "bb.event.CacheLoadStarted", |
| 376 | "bb.event.CacheLoadProgress", "bb.event.CacheLoadCompleted", "bb.command.CommandFailed", |
| 377 | "bb.command.CommandExit", "bb.command.CommandCompleted", "bb.cooker.CookerExit", |
| 378 | "bb.event.MultipleProviders", "bb.event.NoProvider", "bb.runqueue.sceneQueueTaskStarted", |
| 379 | "bb.runqueue.runQueueTaskStarted", "bb.runqueue.runQueueTaskFailed", "bb.runqueue.sceneQueueTaskFailed", |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 380 | "bb.event.BuildBase", "bb.build.TaskStarted", "bb.build.TaskSucceeded", "bb.build.TaskFailedSilent", |
| 381 | "bb.build.TaskProgress", "bb.event.ProcessStarted", "bb.event.ProcessProgress", "bb.event.ProcessFinished"] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 382 | |
| 383 | def main(server, eventHandler, params, tf = TerminalFilter): |
| 384 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 385 | if not params.observe_only: |
| 386 | params.updateToServer(server, os.environ.copy()) |
| 387 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 388 | includelogs, loglines, consolelogfile, logconfigfile = _log_settings_from_server(server, params.observe_only) |
| 389 | |
| 390 | loglevel, _ = bb.msg.constructLogOptions() |
| 391 | |
| 392 | if params.options.quiet == 0: |
| 393 | console_loglevel = loglevel |
| 394 | elif params.options.quiet > 2: |
| 395 | console_loglevel = bb.msg.BBLogFormatter.ERROR |
| 396 | else: |
| 397 | console_loglevel = bb.msg.BBLogFormatter.WARNING |
| 398 | |
| 399 | logconfig = { |
| 400 | "version": 1, |
| 401 | "handlers": { |
| 402 | "BitBake.console": { |
| 403 | "class": "logging.StreamHandler", |
| 404 | "formatter": "BitBake.consoleFormatter", |
| 405 | "level": console_loglevel, |
| 406 | "stream": "ext://sys.stdout", |
| 407 | "filters": ["BitBake.stdoutFilter"], |
| 408 | ".": { |
| 409 | "is_console": True, |
| 410 | }, |
| 411 | }, |
| 412 | "BitBake.errconsole": { |
| 413 | "class": "logging.StreamHandler", |
| 414 | "formatter": "BitBake.consoleFormatter", |
| 415 | "level": loglevel, |
| 416 | "stream": "ext://sys.stderr", |
| 417 | "filters": ["BitBake.stderrFilter"], |
| 418 | ".": { |
| 419 | "is_console": True, |
| 420 | }, |
| 421 | }, |
| 422 | # This handler can be used if specific loggers should print on |
| 423 | # the console at a lower severity than the default. It will |
| 424 | # display any messages sent to it that are lower than then |
| 425 | # BitBake.console logging level (so as to prevent duplication of |
| 426 | # messages). Nothing is attached to this handler by default |
| 427 | "BitBake.verbconsole": { |
| 428 | "class": "logging.StreamHandler", |
| 429 | "formatter": "BitBake.consoleFormatter", |
| 430 | "level": 1, |
| 431 | "stream": "ext://sys.stdout", |
| 432 | "filters": ["BitBake.verbconsoleFilter"], |
| 433 | ".": { |
| 434 | "is_console": True, |
| 435 | }, |
| 436 | }, |
| 437 | }, |
| 438 | "formatters": { |
| 439 | # This format instance will get color output enabled by the |
| 440 | # terminal |
| 441 | "BitBake.consoleFormatter" : { |
| 442 | "()": "bb.msg.BBLogFormatter", |
| 443 | "format": "%(levelname)s: %(message)s" |
| 444 | }, |
| 445 | # The file log requires a separate instance so that it doesn't get |
| 446 | # color enabled |
| 447 | "BitBake.logfileFormatter": { |
| 448 | "()": "bb.msg.BBLogFormatter", |
| 449 | "format": "%(levelname)s: %(message)s" |
| 450 | } |
| 451 | }, |
| 452 | "filters": { |
| 453 | "BitBake.stdoutFilter": { |
| 454 | "()": "bb.msg.LogFilterLTLevel", |
| 455 | "level": "ERROR" |
| 456 | }, |
| 457 | "BitBake.stderrFilter": { |
| 458 | "()": "bb.msg.LogFilterGEQLevel", |
| 459 | "level": "ERROR" |
| 460 | }, |
| 461 | "BitBake.verbconsoleFilter": { |
| 462 | "()": "bb.msg.LogFilterLTLevel", |
| 463 | "level": console_loglevel |
| 464 | }, |
| 465 | }, |
| 466 | "loggers": { |
| 467 | "BitBake": { |
| 468 | "level": loglevel, |
| 469 | "handlers": ["BitBake.console", "BitBake.errconsole"], |
| 470 | } |
| 471 | }, |
| 472 | "disable_existing_loggers": False |
| 473 | } |
| 474 | |
| 475 | # Enable the console log file if enabled |
| 476 | if consolelogfile and not params.options.show_environment and not params.options.show_versions: |
| 477 | logconfig = bb.msg.mergeLoggingConfig(logconfig, { |
| 478 | "version": 1, |
| 479 | "handlers" : { |
| 480 | "BitBake.consolelog": { |
| 481 | "class": "logging.FileHandler", |
| 482 | "formatter": "BitBake.logfileFormatter", |
| 483 | "level": loglevel, |
| 484 | "filename": consolelogfile, |
| 485 | }, |
| 486 | # Just like verbconsole, anything sent here will go to the |
| 487 | # log file, unless it would go to BitBake.consolelog |
| 488 | "BitBake.verbconsolelog" : { |
| 489 | "class": "logging.FileHandler", |
| 490 | "formatter": "BitBake.logfileFormatter", |
| 491 | "level": 1, |
| 492 | "filename": consolelogfile, |
| 493 | "filters": ["BitBake.verbconsolelogFilter"], |
| 494 | }, |
| 495 | }, |
| 496 | "filters": { |
| 497 | "BitBake.verbconsolelogFilter": { |
| 498 | "()": "bb.msg.LogFilterLTLevel", |
| 499 | "level": loglevel, |
| 500 | }, |
| 501 | }, |
| 502 | "loggers": { |
| 503 | "BitBake": { |
| 504 | "handlers": ["BitBake.consolelog"], |
| 505 | }, |
| 506 | |
| 507 | # Other interesting things that we want to keep an eye on |
| 508 | # in the log files in case someone has an issue, but not |
| 509 | # necessarily show to the user on the console |
| 510 | "BitBake.SigGen.HashEquiv": { |
| 511 | "level": "VERBOSE", |
| 512 | "handlers": ["BitBake.verbconsolelog"], |
| 513 | }, |
| 514 | "BitBake.RunQueue.HashEquiv": { |
| 515 | "level": "VERBOSE", |
| 516 | "handlers": ["BitBake.verbconsolelog"], |
| 517 | } |
| 518 | } |
| 519 | }) |
| 520 | |
| 521 | bb.utils.mkdirhier(os.path.dirname(consolelogfile)) |
| 522 | loglink = os.path.join(os.path.dirname(consolelogfile), 'console-latest.log') |
| 523 | bb.utils.remove(loglink) |
| 524 | try: |
| 525 | os.symlink(os.path.basename(consolelogfile), loglink) |
| 526 | except OSError: |
| 527 | pass |
| 528 | |
| 529 | conf = bb.msg.setLoggingConfig(logconfig, logconfigfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 530 | |
| 531 | if sys.stdin.isatty() and sys.stdout.isatty(): |
| 532 | log_exec_tty = True |
| 533 | else: |
| 534 | log_exec_tty = False |
| 535 | |
| 536 | helper = uihelper.BBUIHelper() |
| 537 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 538 | # Look for the specially designated handlers which need to be passed to the |
| 539 | # terminal handler |
| 540 | console_handlers = [h for h in conf.config['handlers'].values() if getattr(h, 'is_console', False)] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 541 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 542 | bb.utils.set_process_name("KnottyUI") |
| 543 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 544 | if params.options.remote_server and params.options.kill_server: |
| 545 | server.terminateServer() |
| 546 | return |
| 547 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 548 | llevel, debug_domains = bb.msg.constructLogOptions() |
| 549 | server.runCommand(["setEventMask", server.getEventHandle(), llevel, debug_domains, _evt_list]) |
| 550 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 551 | # The logging_tree module is *extremely* helpful in debugging logging |
| 552 | # domains. Uncomment here to dump the logging tree when bitbake starts |
| 553 | #import logging_tree |
| 554 | #logging_tree.printout() |
| 555 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 556 | universe = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 557 | if not params.observe_only: |
| 558 | params.updateFromServer(server) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 559 | cmdline = params.parseActions() |
| 560 | if not cmdline: |
| 561 | print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.") |
| 562 | return 1 |
| 563 | if 'msg' in cmdline and cmdline['msg']: |
| 564 | logger.error(cmdline['msg']) |
| 565 | return 1 |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 566 | if cmdline['action'][0] == "buildTargets" and "universe" in cmdline['action'][1]: |
| 567 | universe = True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 568 | |
| 569 | ret, error = server.runCommand(cmdline['action']) |
| 570 | if error: |
| 571 | logger.error("Command '%s' failed: %s" % (cmdline, error)) |
| 572 | return 1 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 573 | elif not ret: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 574 | logger.error("Command '%s' failed: returned %s" % (cmdline, ret)) |
| 575 | return 1 |
| 576 | |
| 577 | |
| 578 | parseprogress = None |
| 579 | cacheprogress = None |
| 580 | main.shutdown = 0 |
| 581 | interrupted = False |
| 582 | return_value = 0 |
| 583 | errors = 0 |
| 584 | warnings = 0 |
| 585 | taskfailures = [] |
| 586 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 587 | printinterval = 5000 |
| 588 | lastprint = time.time() |
| 589 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 590 | termfilter = tf(main, helper, console_handlers, params.options.quiet) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 591 | atexit.register(termfilter.finish) |
| 592 | |
| 593 | while True: |
| 594 | try: |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 595 | if (lastprint + printinterval) <= time.time(): |
| 596 | termfilter.keepAlive(printinterval) |
| 597 | printinterval += 5000 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 598 | event = eventHandler.waitEvent(0) |
| 599 | if event is None: |
| 600 | if main.shutdown > 1: |
| 601 | break |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 602 | if not parseprogress: |
| 603 | termfilter.updateFooter() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 604 | event = eventHandler.waitEvent(0.25) |
| 605 | if event is None: |
| 606 | continue |
| 607 | helper.eventHandler(event) |
| 608 | if isinstance(event, bb.runqueue.runQueueExitWait): |
| 609 | if not main.shutdown: |
| 610 | main.shutdown = 1 |
| 611 | continue |
| 612 | if isinstance(event, bb.event.LogExecTTY): |
| 613 | if log_exec_tty: |
| 614 | tries = event.retries |
| 615 | while tries: |
| 616 | print("Trying to run: %s" % event.prog) |
| 617 | if os.system(event.prog) == 0: |
| 618 | break |
| 619 | time.sleep(event.sleep_delay) |
| 620 | tries -= 1 |
| 621 | if tries: |
| 622 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 623 | logger.warning(event.msg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 624 | continue |
| 625 | |
| 626 | if isinstance(event, logging.LogRecord): |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 627 | lastprint = time.time() |
| 628 | printinterval = 5000 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 629 | if event.levelno >= bb.msg.BBLogFormatter.ERROR: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 630 | errors = errors + 1 |
| 631 | return_value = 1 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 632 | elif event.levelno == bb.msg.BBLogFormatter.WARNING: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 633 | warnings = warnings + 1 |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 634 | |
| 635 | if event.taskpid != 0: |
| 636 | # For "normal" logging conditions, don't show note logs from tasks |
| 637 | # but do show them if the user has changed the default log level to |
| 638 | # include verbose/debug messages |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 639 | if event.levelno <= bb.msg.BBLogFormatter.NOTE and (event.levelno < llevel or (event.levelno == bb.msg.BBLogFormatter.NOTE and llevel != bb.msg.BBLogFormatter.VERBOSE)): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 640 | continue |
| 641 | |
| 642 | # Prefix task messages with recipe/task |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 643 | if event.taskpid in helper.pidmap and event.levelno != bb.msg.BBLogFormatter.PLAIN: |
| 644 | taskinfo = helper.running_tasks[helper.pidmap[event.taskpid]] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 645 | event.msg = taskinfo['title'] + ': ' + event.msg |
| 646 | if hasattr(event, 'fn'): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 647 | event.msg = event.fn + ': ' + event.msg |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 648 | logging.getLogger(event.name).handle(event) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 649 | continue |
| 650 | |
| 651 | if isinstance(event, bb.build.TaskFailedSilent): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 652 | logger.warning("Logfile for failed setscene task is %s" % event.logfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 653 | continue |
| 654 | if isinstance(event, bb.build.TaskFailed): |
| 655 | return_value = 1 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 656 | print_event_log(event, includelogs, loglines, termfilter) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 657 | if isinstance(event, bb.build.TaskBase): |
| 658 | logger.info(event._message) |
| 659 | continue |
| 660 | if isinstance(event, bb.event.ParseStarted): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 661 | if params.options.quiet > 1: |
| 662 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 663 | if event.total == 0: |
| 664 | continue |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 665 | termfilter.clearFooter() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 666 | parseprogress = new_progress("Parsing recipes", event.total).start() |
| 667 | continue |
| 668 | if isinstance(event, bb.event.ParseProgress): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 669 | if params.options.quiet > 1: |
| 670 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 671 | if parseprogress: |
| 672 | parseprogress.update(event.current) |
| 673 | else: |
| 674 | bb.warn("Got ParseProgress event for parsing that never started?") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 675 | continue |
| 676 | if isinstance(event, bb.event.ParseCompleted): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 677 | if params.options.quiet > 1: |
| 678 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 679 | if not parseprogress: |
| 680 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 681 | parseprogress.finish() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 682 | pasreprogress = None |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 683 | if params.options.quiet == 0: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 684 | print(("Parsing of %d .bb files complete (%d cached, %d parsed). %d targets, %d skipped, %d masked, %d errors." |
| 685 | % ( event.total, event.cached, event.parsed, event.virtuals, event.skipped, event.masked, event.errors))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 686 | continue |
| 687 | |
| 688 | if isinstance(event, bb.event.CacheLoadStarted): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 689 | if params.options.quiet > 1: |
| 690 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 691 | cacheprogress = new_progress("Loading cache", event.total).start() |
| 692 | continue |
| 693 | if isinstance(event, bb.event.CacheLoadProgress): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 694 | if params.options.quiet > 1: |
| 695 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 696 | cacheprogress.update(event.current) |
| 697 | continue |
| 698 | if isinstance(event, bb.event.CacheLoadCompleted): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 699 | if params.options.quiet > 1: |
| 700 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 701 | cacheprogress.finish() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 702 | if params.options.quiet == 0: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 703 | print("Loaded %d entries from dependency cache." % event.num_entries) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 704 | continue |
| 705 | |
| 706 | if isinstance(event, bb.command.CommandFailed): |
| 707 | return_value = event.exitcode |
| 708 | if event.error: |
| 709 | errors = errors + 1 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 710 | logger.error(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 711 | main.shutdown = 2 |
| 712 | continue |
| 713 | if isinstance(event, bb.command.CommandExit): |
| 714 | if not return_value: |
| 715 | return_value = event.exitcode |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 716 | main.shutdown = 2 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 717 | continue |
| 718 | if isinstance(event, (bb.command.CommandCompleted, bb.cooker.CookerExit)): |
| 719 | main.shutdown = 2 |
| 720 | continue |
| 721 | if isinstance(event, bb.event.MultipleProviders): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 722 | logger.info(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 723 | continue |
| 724 | if isinstance(event, bb.event.NoProvider): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 725 | # For universe builds, only show these as warnings, not errors |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 726 | if not universe: |
| 727 | return_value = 1 |
| 728 | errors = errors + 1 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 729 | logger.error(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 730 | else: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 731 | logger.warning(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 732 | continue |
| 733 | |
| 734 | if isinstance(event, bb.runqueue.sceneQueueTaskStarted): |
| 735 | logger.info("Running setscene task %d of %d (%s)" % (event.stats.completed + event.stats.active + event.stats.failed + 1, event.stats.total, event.taskstring)) |
| 736 | continue |
| 737 | |
| 738 | if isinstance(event, bb.runqueue.runQueueTaskStarted): |
| 739 | if event.noexec: |
| 740 | tasktype = 'noexec task' |
| 741 | else: |
| 742 | tasktype = 'task' |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 743 | logger.info("Running %s %d of %d (%s)", |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 744 | tasktype, |
| 745 | event.stats.completed + event.stats.active + |
| 746 | event.stats.failed + 1, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 747 | event.stats.total, event.taskstring) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 748 | continue |
| 749 | |
| 750 | if isinstance(event, bb.runqueue.runQueueTaskFailed): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 751 | return_value = 1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 752 | taskfailures.append(event.taskstring) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 753 | logger.error(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 754 | continue |
| 755 | |
| 756 | if isinstance(event, bb.runqueue.sceneQueueTaskFailed): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 757 | logger.warning(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 758 | continue |
| 759 | |
| 760 | if isinstance(event, bb.event.DepTreeGenerated): |
| 761 | continue |
| 762 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 763 | if isinstance(event, bb.event.ProcessStarted): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 764 | if params.options.quiet > 1: |
| 765 | continue |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 766 | termfilter.clearFooter() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 767 | parseprogress = new_progress(event.processname, event.total) |
| 768 | parseprogress.start(False) |
| 769 | continue |
| 770 | if isinstance(event, bb.event.ProcessProgress): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 771 | if params.options.quiet > 1: |
| 772 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 773 | if parseprogress: |
| 774 | parseprogress.update(event.progress) |
| 775 | else: |
| 776 | bb.warn("Got ProcessProgress event for someting that never started?") |
| 777 | continue |
| 778 | if isinstance(event, bb.event.ProcessFinished): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 779 | if params.options.quiet > 1: |
| 780 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 781 | if parseprogress: |
| 782 | parseprogress.finish() |
| 783 | parseprogress = None |
| 784 | continue |
| 785 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 786 | # ignore |
| 787 | if isinstance(event, (bb.event.BuildBase, |
| 788 | bb.event.MetadataEvent, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 789 | bb.event.ConfigParsed, |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 790 | bb.event.MultiConfigParsed, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 791 | bb.event.RecipeParsed, |
| 792 | bb.event.RecipePreFinalise, |
| 793 | bb.runqueue.runQueueEvent, |
| 794 | bb.event.OperationStarted, |
| 795 | bb.event.OperationCompleted, |
| 796 | bb.event.OperationProgress, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 797 | bb.event.DiskFull, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 798 | bb.event.HeartbeatEvent, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 799 | bb.build.TaskProgress)): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 800 | continue |
| 801 | |
| 802 | logger.error("Unknown event: %s", event) |
| 803 | |
| 804 | except EnvironmentError as ioerror: |
| 805 | termfilter.clearFooter() |
| 806 | # ignore interrupted io |
| 807 | if ioerror.args[0] == 4: |
| 808 | continue |
| 809 | sys.stderr.write(str(ioerror)) |
| 810 | if not params.observe_only: |
| 811 | _, error = server.runCommand(["stateForceShutdown"]) |
| 812 | main.shutdown = 2 |
| 813 | except KeyboardInterrupt: |
| 814 | termfilter.clearFooter() |
| 815 | if params.observe_only: |
| 816 | print("\nKeyboard Interrupt, exiting observer...") |
| 817 | main.shutdown = 2 |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 818 | |
| 819 | def state_force_shutdown(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 820 | print("\nSecond Keyboard Interrupt, stopping...\n") |
| 821 | _, error = server.runCommand(["stateForceShutdown"]) |
| 822 | if error: |
| 823 | logger.error("Unable to cleanly stop: %s" % error) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 824 | |
| 825 | if not params.observe_only and main.shutdown == 1: |
| 826 | state_force_shutdown() |
| 827 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 828 | if not params.observe_only and main.shutdown == 0: |
| 829 | print("\nKeyboard Interrupt, closing down...\n") |
| 830 | interrupted = True |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 831 | # Capture the second KeyboardInterrupt during stateShutdown is running |
| 832 | try: |
| 833 | _, error = server.runCommand(["stateShutdown"]) |
| 834 | if error: |
| 835 | logger.error("Unable to cleanly shutdown: %s" % error) |
| 836 | except KeyboardInterrupt: |
| 837 | state_force_shutdown() |
| 838 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 839 | main.shutdown = main.shutdown + 1 |
| 840 | pass |
| 841 | except Exception as e: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 842 | import traceback |
| 843 | sys.stderr.write(traceback.format_exc()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 844 | if not params.observe_only: |
| 845 | _, error = server.runCommand(["stateForceShutdown"]) |
| 846 | main.shutdown = 2 |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 847 | return_value = 1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 848 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 849 | termfilter.clearFooter() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 850 | summary = "" |
| 851 | if taskfailures: |
| 852 | summary += pluralise("\nSummary: %s task failed:", |
| 853 | "\nSummary: %s tasks failed:", len(taskfailures)) |
| 854 | for failure in taskfailures: |
| 855 | summary += "\n %s" % failure |
| 856 | if warnings: |
| 857 | summary += pluralise("\nSummary: There was %s WARNING message shown.", |
| 858 | "\nSummary: There were %s WARNING messages shown.", warnings) |
| 859 | if return_value and errors: |
| 860 | summary += pluralise("\nSummary: There was %s ERROR message shown, returning a non-zero exit code.", |
| 861 | "\nSummary: There were %s ERROR messages shown, returning a non-zero exit code.", errors) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 862 | if summary and params.options.quiet == 0: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 863 | print(summary) |
| 864 | |
| 865 | if interrupted: |
| 866 | print("Execution was interrupted, returning a non-zero exit code.") |
| 867 | if return_value == 0: |
| 868 | return_value = 1 |
| 869 | except IOError as e: |
| 870 | import errno |
| 871 | if e.errno == errno.EPIPE: |
| 872 | pass |
| 873 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 874 | logging.shutdown() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 875 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 876 | return return_value |