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