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: |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 147 | cr = (os.environ['LINES'], os.environ['COLUMNS']) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 383 | def drain_events_errorhandling(eventHandler): |
| 384 | # We don't have logging setup, we do need to show any events we see before exiting |
| 385 | event = True |
| 386 | logger = bb.msg.logger_create('bitbake', sys.stdout) |
| 387 | while event: |
| 388 | event = eventHandler.waitEvent(0) |
| 389 | if isinstance(event, logging.LogRecord): |
| 390 | logger.handle(event) |
| 391 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 392 | def main(server, eventHandler, params, tf = TerminalFilter): |
| 393 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 394 | try: |
| 395 | if not params.observe_only: |
| 396 | params.updateToServer(server, os.environ.copy()) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 397 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 398 | includelogs, loglines, consolelogfile, logconfigfile = _log_settings_from_server(server, params.observe_only) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 399 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 400 | loglevel, _ = bb.msg.constructLogOptions() |
| 401 | except bb.BBHandledException: |
| 402 | drain_events_errorhandling(eventHandler) |
| 403 | return 1 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 404 | |
| 405 | if params.options.quiet == 0: |
| 406 | console_loglevel = loglevel |
| 407 | elif params.options.quiet > 2: |
| 408 | console_loglevel = bb.msg.BBLogFormatter.ERROR |
| 409 | else: |
| 410 | console_loglevel = bb.msg.BBLogFormatter.WARNING |
| 411 | |
| 412 | logconfig = { |
| 413 | "version": 1, |
| 414 | "handlers": { |
| 415 | "BitBake.console": { |
| 416 | "class": "logging.StreamHandler", |
| 417 | "formatter": "BitBake.consoleFormatter", |
| 418 | "level": console_loglevel, |
| 419 | "stream": "ext://sys.stdout", |
| 420 | "filters": ["BitBake.stdoutFilter"], |
| 421 | ".": { |
| 422 | "is_console": True, |
| 423 | }, |
| 424 | }, |
| 425 | "BitBake.errconsole": { |
| 426 | "class": "logging.StreamHandler", |
| 427 | "formatter": "BitBake.consoleFormatter", |
| 428 | "level": loglevel, |
| 429 | "stream": "ext://sys.stderr", |
| 430 | "filters": ["BitBake.stderrFilter"], |
| 431 | ".": { |
| 432 | "is_console": True, |
| 433 | }, |
| 434 | }, |
| 435 | # This handler can be used if specific loggers should print on |
| 436 | # the console at a lower severity than the default. It will |
| 437 | # display any messages sent to it that are lower than then |
| 438 | # BitBake.console logging level (so as to prevent duplication of |
| 439 | # messages). Nothing is attached to this handler by default |
| 440 | "BitBake.verbconsole": { |
| 441 | "class": "logging.StreamHandler", |
| 442 | "formatter": "BitBake.consoleFormatter", |
| 443 | "level": 1, |
| 444 | "stream": "ext://sys.stdout", |
| 445 | "filters": ["BitBake.verbconsoleFilter"], |
| 446 | ".": { |
| 447 | "is_console": True, |
| 448 | }, |
| 449 | }, |
| 450 | }, |
| 451 | "formatters": { |
| 452 | # This format instance will get color output enabled by the |
| 453 | # terminal |
| 454 | "BitBake.consoleFormatter" : { |
| 455 | "()": "bb.msg.BBLogFormatter", |
| 456 | "format": "%(levelname)s: %(message)s" |
| 457 | }, |
| 458 | # The file log requires a separate instance so that it doesn't get |
| 459 | # color enabled |
| 460 | "BitBake.logfileFormatter": { |
| 461 | "()": "bb.msg.BBLogFormatter", |
| 462 | "format": "%(levelname)s: %(message)s" |
| 463 | } |
| 464 | }, |
| 465 | "filters": { |
| 466 | "BitBake.stdoutFilter": { |
| 467 | "()": "bb.msg.LogFilterLTLevel", |
| 468 | "level": "ERROR" |
| 469 | }, |
| 470 | "BitBake.stderrFilter": { |
| 471 | "()": "bb.msg.LogFilterGEQLevel", |
| 472 | "level": "ERROR" |
| 473 | }, |
| 474 | "BitBake.verbconsoleFilter": { |
| 475 | "()": "bb.msg.LogFilterLTLevel", |
| 476 | "level": console_loglevel |
| 477 | }, |
| 478 | }, |
| 479 | "loggers": { |
| 480 | "BitBake": { |
| 481 | "level": loglevel, |
| 482 | "handlers": ["BitBake.console", "BitBake.errconsole"], |
| 483 | } |
| 484 | }, |
| 485 | "disable_existing_loggers": False |
| 486 | } |
| 487 | |
| 488 | # Enable the console log file if enabled |
| 489 | if consolelogfile and not params.options.show_environment and not params.options.show_versions: |
| 490 | logconfig = bb.msg.mergeLoggingConfig(logconfig, { |
| 491 | "version": 1, |
| 492 | "handlers" : { |
| 493 | "BitBake.consolelog": { |
| 494 | "class": "logging.FileHandler", |
| 495 | "formatter": "BitBake.logfileFormatter", |
| 496 | "level": loglevel, |
| 497 | "filename": consolelogfile, |
| 498 | }, |
| 499 | # Just like verbconsole, anything sent here will go to the |
| 500 | # log file, unless it would go to BitBake.consolelog |
| 501 | "BitBake.verbconsolelog" : { |
| 502 | "class": "logging.FileHandler", |
| 503 | "formatter": "BitBake.logfileFormatter", |
| 504 | "level": 1, |
| 505 | "filename": consolelogfile, |
| 506 | "filters": ["BitBake.verbconsolelogFilter"], |
| 507 | }, |
| 508 | }, |
| 509 | "filters": { |
| 510 | "BitBake.verbconsolelogFilter": { |
| 511 | "()": "bb.msg.LogFilterLTLevel", |
| 512 | "level": loglevel, |
| 513 | }, |
| 514 | }, |
| 515 | "loggers": { |
| 516 | "BitBake": { |
| 517 | "handlers": ["BitBake.consolelog"], |
| 518 | }, |
| 519 | |
| 520 | # Other interesting things that we want to keep an eye on |
| 521 | # in the log files in case someone has an issue, but not |
| 522 | # necessarily show to the user on the console |
| 523 | "BitBake.SigGen.HashEquiv": { |
| 524 | "level": "VERBOSE", |
| 525 | "handlers": ["BitBake.verbconsolelog"], |
| 526 | }, |
| 527 | "BitBake.RunQueue.HashEquiv": { |
| 528 | "level": "VERBOSE", |
| 529 | "handlers": ["BitBake.verbconsolelog"], |
| 530 | } |
| 531 | } |
| 532 | }) |
| 533 | |
| 534 | bb.utils.mkdirhier(os.path.dirname(consolelogfile)) |
| 535 | loglink = os.path.join(os.path.dirname(consolelogfile), 'console-latest.log') |
| 536 | bb.utils.remove(loglink) |
| 537 | try: |
| 538 | os.symlink(os.path.basename(consolelogfile), loglink) |
| 539 | except OSError: |
| 540 | pass |
| 541 | |
| 542 | conf = bb.msg.setLoggingConfig(logconfig, logconfigfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 543 | |
| 544 | if sys.stdin.isatty() and sys.stdout.isatty(): |
| 545 | log_exec_tty = True |
| 546 | else: |
| 547 | log_exec_tty = False |
| 548 | |
| 549 | helper = uihelper.BBUIHelper() |
| 550 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 551 | # Look for the specially designated handlers which need to be passed to the |
| 552 | # terminal handler |
| 553 | 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] | 554 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 555 | bb.utils.set_process_name("KnottyUI") |
| 556 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 557 | if params.options.remote_server and params.options.kill_server: |
| 558 | server.terminateServer() |
| 559 | return |
| 560 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 561 | llevel, debug_domains = bb.msg.constructLogOptions() |
| 562 | server.runCommand(["setEventMask", server.getEventHandle(), llevel, debug_domains, _evt_list]) |
| 563 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 564 | # The logging_tree module is *extremely* helpful in debugging logging |
| 565 | # domains. Uncomment here to dump the logging tree when bitbake starts |
| 566 | #import logging_tree |
| 567 | #logging_tree.printout() |
| 568 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 569 | universe = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 570 | if not params.observe_only: |
| 571 | params.updateFromServer(server) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 572 | cmdline = params.parseActions() |
| 573 | if not cmdline: |
| 574 | print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.") |
| 575 | return 1 |
| 576 | if 'msg' in cmdline and cmdline['msg']: |
| 577 | logger.error(cmdline['msg']) |
| 578 | return 1 |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 579 | if cmdline['action'][0] == "buildTargets" and "universe" in cmdline['action'][1]: |
| 580 | universe = True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 581 | |
| 582 | ret, error = server.runCommand(cmdline['action']) |
| 583 | if error: |
| 584 | logger.error("Command '%s' failed: %s" % (cmdline, error)) |
| 585 | return 1 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 586 | elif not ret: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 587 | logger.error("Command '%s' failed: returned %s" % (cmdline, ret)) |
| 588 | return 1 |
| 589 | |
| 590 | |
| 591 | parseprogress = None |
| 592 | cacheprogress = None |
| 593 | main.shutdown = 0 |
| 594 | interrupted = False |
| 595 | return_value = 0 |
| 596 | errors = 0 |
| 597 | warnings = 0 |
| 598 | taskfailures = [] |
| 599 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 600 | printinterval = 5000 |
| 601 | lastprint = time.time() |
| 602 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 603 | termfilter = tf(main, helper, console_handlers, params.options.quiet) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 604 | atexit.register(termfilter.finish) |
| 605 | |
| 606 | while True: |
| 607 | try: |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 608 | if (lastprint + printinterval) <= time.time(): |
| 609 | termfilter.keepAlive(printinterval) |
| 610 | printinterval += 5000 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 611 | event = eventHandler.waitEvent(0) |
| 612 | if event is None: |
| 613 | if main.shutdown > 1: |
| 614 | break |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 615 | if not parseprogress: |
| 616 | termfilter.updateFooter() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 617 | event = eventHandler.waitEvent(0.25) |
| 618 | if event is None: |
| 619 | continue |
| 620 | helper.eventHandler(event) |
| 621 | if isinstance(event, bb.runqueue.runQueueExitWait): |
| 622 | if not main.shutdown: |
| 623 | main.shutdown = 1 |
| 624 | continue |
| 625 | if isinstance(event, bb.event.LogExecTTY): |
| 626 | if log_exec_tty: |
| 627 | tries = event.retries |
| 628 | while tries: |
| 629 | print("Trying to run: %s" % event.prog) |
| 630 | if os.system(event.prog) == 0: |
| 631 | break |
| 632 | time.sleep(event.sleep_delay) |
| 633 | tries -= 1 |
| 634 | if tries: |
| 635 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 636 | logger.warning(event.msg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 637 | continue |
| 638 | |
| 639 | if isinstance(event, logging.LogRecord): |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 640 | lastprint = time.time() |
| 641 | printinterval = 5000 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 642 | if event.levelno >= bb.msg.BBLogFormatter.ERROR: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 643 | errors = errors + 1 |
| 644 | return_value = 1 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 645 | elif event.levelno == bb.msg.BBLogFormatter.WARNING: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 646 | warnings = warnings + 1 |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 647 | |
| 648 | if event.taskpid != 0: |
| 649 | # For "normal" logging conditions, don't show note logs from tasks |
| 650 | # but do show them if the user has changed the default log level to |
| 651 | # include verbose/debug messages |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 652 | 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] | 653 | continue |
| 654 | |
| 655 | # Prefix task messages with recipe/task |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 656 | if event.taskpid in helper.pidmap and event.levelno != bb.msg.BBLogFormatter.PLAIN: |
| 657 | taskinfo = helper.running_tasks[helper.pidmap[event.taskpid]] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 658 | event.msg = taskinfo['title'] + ': ' + event.msg |
| 659 | if hasattr(event, 'fn'): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 660 | event.msg = event.fn + ': ' + event.msg |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 661 | logging.getLogger(event.name).handle(event) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 662 | continue |
| 663 | |
| 664 | if isinstance(event, bb.build.TaskFailedSilent): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 665 | logger.warning("Logfile for failed setscene task is %s" % event.logfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 666 | continue |
| 667 | if isinstance(event, bb.build.TaskFailed): |
| 668 | return_value = 1 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 669 | print_event_log(event, includelogs, loglines, termfilter) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 670 | if isinstance(event, bb.build.TaskBase): |
| 671 | logger.info(event._message) |
| 672 | continue |
| 673 | if isinstance(event, bb.event.ParseStarted): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 674 | if params.options.quiet > 1: |
| 675 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 676 | if event.total == 0: |
| 677 | continue |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 678 | termfilter.clearFooter() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 679 | parseprogress = new_progress("Parsing recipes", event.total).start() |
| 680 | continue |
| 681 | if isinstance(event, bb.event.ParseProgress): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 682 | if params.options.quiet > 1: |
| 683 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 684 | if parseprogress: |
| 685 | parseprogress.update(event.current) |
| 686 | else: |
| 687 | bb.warn("Got ParseProgress event for parsing that never started?") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 688 | continue |
| 689 | if isinstance(event, bb.event.ParseCompleted): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 690 | if params.options.quiet > 1: |
| 691 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 692 | if not parseprogress: |
| 693 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 694 | parseprogress.finish() |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 695 | parseprogress = None |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 696 | if params.options.quiet == 0: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 697 | print(("Parsing of %d .bb files complete (%d cached, %d parsed). %d targets, %d skipped, %d masked, %d errors." |
| 698 | % ( 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] | 699 | continue |
| 700 | |
| 701 | if isinstance(event, bb.event.CacheLoadStarted): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 702 | if params.options.quiet > 1: |
| 703 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 704 | cacheprogress = new_progress("Loading cache", event.total).start() |
| 705 | continue |
| 706 | if isinstance(event, bb.event.CacheLoadProgress): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 707 | if params.options.quiet > 1: |
| 708 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 709 | cacheprogress.update(event.current) |
| 710 | continue |
| 711 | if isinstance(event, bb.event.CacheLoadCompleted): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 712 | if params.options.quiet > 1: |
| 713 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 714 | cacheprogress.finish() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 715 | if params.options.quiet == 0: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 716 | print("Loaded %d entries from dependency cache." % event.num_entries) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 717 | continue |
| 718 | |
| 719 | if isinstance(event, bb.command.CommandFailed): |
| 720 | return_value = event.exitcode |
| 721 | if event.error: |
| 722 | errors = errors + 1 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 723 | logger.error(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 724 | main.shutdown = 2 |
| 725 | continue |
| 726 | if isinstance(event, bb.command.CommandExit): |
| 727 | if not return_value: |
| 728 | return_value = event.exitcode |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 729 | main.shutdown = 2 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 730 | continue |
| 731 | if isinstance(event, (bb.command.CommandCompleted, bb.cooker.CookerExit)): |
| 732 | main.shutdown = 2 |
| 733 | continue |
| 734 | if isinstance(event, bb.event.MultipleProviders): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 735 | logger.info(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 736 | continue |
| 737 | if isinstance(event, bb.event.NoProvider): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 738 | # For universe builds, only show these as warnings, not errors |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 739 | if not universe: |
| 740 | return_value = 1 |
| 741 | errors = errors + 1 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 742 | logger.error(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 743 | else: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 744 | logger.warning(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 745 | continue |
| 746 | |
| 747 | if isinstance(event, bb.runqueue.sceneQueueTaskStarted): |
| 748 | logger.info("Running setscene task %d of %d (%s)" % (event.stats.completed + event.stats.active + event.stats.failed + 1, event.stats.total, event.taskstring)) |
| 749 | continue |
| 750 | |
| 751 | if isinstance(event, bb.runqueue.runQueueTaskStarted): |
| 752 | if event.noexec: |
| 753 | tasktype = 'noexec task' |
| 754 | else: |
| 755 | tasktype = 'task' |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 756 | logger.info("Running %s %d of %d (%s)", |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 757 | tasktype, |
| 758 | event.stats.completed + event.stats.active + |
| 759 | event.stats.failed + 1, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 760 | event.stats.total, event.taskstring) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 761 | continue |
| 762 | |
| 763 | if isinstance(event, bb.runqueue.runQueueTaskFailed): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 764 | return_value = 1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 765 | taskfailures.append(event.taskstring) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 766 | logger.error(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 767 | continue |
| 768 | |
| 769 | if isinstance(event, bb.runqueue.sceneQueueTaskFailed): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 770 | logger.warning(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 771 | continue |
| 772 | |
| 773 | if isinstance(event, bb.event.DepTreeGenerated): |
| 774 | continue |
| 775 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 776 | if isinstance(event, bb.event.ProcessStarted): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 777 | if params.options.quiet > 1: |
| 778 | continue |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 779 | termfilter.clearFooter() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 780 | parseprogress = new_progress(event.processname, event.total) |
| 781 | parseprogress.start(False) |
| 782 | continue |
| 783 | if isinstance(event, bb.event.ProcessProgress): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 784 | if params.options.quiet > 1: |
| 785 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 786 | if parseprogress: |
| 787 | parseprogress.update(event.progress) |
| 788 | else: |
| 789 | bb.warn("Got ProcessProgress event for someting that never started?") |
| 790 | continue |
| 791 | if isinstance(event, bb.event.ProcessFinished): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 792 | if params.options.quiet > 1: |
| 793 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 794 | if parseprogress: |
| 795 | parseprogress.finish() |
| 796 | parseprogress = None |
| 797 | continue |
| 798 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 799 | # ignore |
| 800 | if isinstance(event, (bb.event.BuildBase, |
| 801 | bb.event.MetadataEvent, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 802 | bb.event.ConfigParsed, |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 803 | bb.event.MultiConfigParsed, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 804 | bb.event.RecipeParsed, |
| 805 | bb.event.RecipePreFinalise, |
| 806 | bb.runqueue.runQueueEvent, |
| 807 | bb.event.OperationStarted, |
| 808 | bb.event.OperationCompleted, |
| 809 | bb.event.OperationProgress, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 810 | bb.event.DiskFull, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 811 | bb.event.HeartbeatEvent, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 812 | bb.build.TaskProgress)): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 813 | continue |
| 814 | |
| 815 | logger.error("Unknown event: %s", event) |
| 816 | |
| 817 | except EnvironmentError as ioerror: |
| 818 | termfilter.clearFooter() |
| 819 | # ignore interrupted io |
| 820 | if ioerror.args[0] == 4: |
| 821 | continue |
| 822 | sys.stderr.write(str(ioerror)) |
| 823 | if not params.observe_only: |
| 824 | _, error = server.runCommand(["stateForceShutdown"]) |
| 825 | main.shutdown = 2 |
| 826 | except KeyboardInterrupt: |
| 827 | termfilter.clearFooter() |
| 828 | if params.observe_only: |
| 829 | print("\nKeyboard Interrupt, exiting observer...") |
| 830 | main.shutdown = 2 |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 831 | |
| 832 | def state_force_shutdown(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 833 | print("\nSecond Keyboard Interrupt, stopping...\n") |
| 834 | _, error = server.runCommand(["stateForceShutdown"]) |
| 835 | if error: |
| 836 | logger.error("Unable to cleanly stop: %s" % error) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 837 | |
| 838 | if not params.observe_only and main.shutdown == 1: |
| 839 | state_force_shutdown() |
| 840 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 841 | if not params.observe_only and main.shutdown == 0: |
| 842 | print("\nKeyboard Interrupt, closing down...\n") |
| 843 | interrupted = True |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 844 | # Capture the second KeyboardInterrupt during stateShutdown is running |
| 845 | try: |
| 846 | _, error = server.runCommand(["stateShutdown"]) |
| 847 | if error: |
| 848 | logger.error("Unable to cleanly shutdown: %s" % error) |
| 849 | except KeyboardInterrupt: |
| 850 | state_force_shutdown() |
| 851 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 852 | main.shutdown = main.shutdown + 1 |
| 853 | pass |
| 854 | except Exception as e: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 855 | import traceback |
| 856 | sys.stderr.write(traceback.format_exc()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 857 | if not params.observe_only: |
| 858 | _, error = server.runCommand(["stateForceShutdown"]) |
| 859 | main.shutdown = 2 |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 860 | return_value = 1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 861 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 862 | termfilter.clearFooter() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 863 | summary = "" |
| 864 | if taskfailures: |
| 865 | summary += pluralise("\nSummary: %s task failed:", |
| 866 | "\nSummary: %s tasks failed:", len(taskfailures)) |
| 867 | for failure in taskfailures: |
| 868 | summary += "\n %s" % failure |
| 869 | if warnings: |
| 870 | summary += pluralise("\nSummary: There was %s WARNING message shown.", |
| 871 | "\nSummary: There were %s WARNING messages shown.", warnings) |
| 872 | if return_value and errors: |
| 873 | summary += pluralise("\nSummary: There was %s ERROR message shown, returning a non-zero exit code.", |
| 874 | "\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] | 875 | if summary and params.options.quiet == 0: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 876 | print(summary) |
| 877 | |
| 878 | if interrupted: |
| 879 | print("Execution was interrupted, returning a non-zero exit code.") |
| 880 | if return_value == 0: |
| 881 | return_value = 1 |
| 882 | except IOError as e: |
| 883 | import errno |
| 884 | if e.errno == errno.EPIPE: |
| 885 | pass |
| 886 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 887 | logging.shutdown() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 888 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 889 | return return_value |