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 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 28 | featureSet = [bb.cooker.CookerFeatures.SEND_SANITYEVENTS, bb.cooker.CookerFeatures.BASEDATASTORE_TRACKING] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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: |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 231 | print("Bitbake still alive (no events for %ds). Active tasks:" % t) |
| 232 | for t in self.helper.running_tasks: |
| 233 | print(t) |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 234 | sys.stdout.flush() |
| 235 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 236 | def updateFooter(self): |
| 237 | if not self.cuu: |
| 238 | return |
| 239 | activetasks = self.helper.running_tasks |
| 240 | failedtasks = self.helper.failed_tasks |
| 241 | runningpids = self.helper.running_pids |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 242 | currenttime = time.time() |
| 243 | if not self.lasttime or (currenttime - self.lasttime > 5): |
| 244 | self.helper.needUpdate = True |
| 245 | self.lasttime = currenttime |
| 246 | if self.footer_present and not self.helper.needUpdate: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 247 | return |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 248 | self.helper.needUpdate = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 249 | if self.footer_present: |
| 250 | self.clearFooter() |
| 251 | if (not self.helper.tasknumber_total or self.helper.tasknumber_current == self.helper.tasknumber_total) and not len(activetasks): |
| 252 | return |
| 253 | tasks = [] |
| 254 | for t in runningpids: |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 255 | start_time = activetasks[t].get("starttime", None) |
| 256 | if start_time: |
| 257 | msg = "%s - %s (pid %s)" % (activetasks[t]["title"], self.elapsed(currenttime - start_time), activetasks[t]["pid"]) |
| 258 | else: |
| 259 | msg = "%s (pid %s)" % (activetasks[t]["title"], activetasks[t]["pid"]) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 260 | progress = activetasks[t].get("progress", None) |
| 261 | if progress is not None: |
| 262 | pbar = activetasks[t].get("progressbar", None) |
| 263 | rate = activetasks[t].get("rate", None) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 264 | if not pbar or pbar.bouncing != (progress < 0): |
| 265 | if progress < 0: |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 266 | pbar = BBProgress("0: %s" % msg, 100, widgets=[' ', progressbar.BouncingSlider(), ''], extrapos=3, resize_handler=self.sigwinch_handle) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 267 | pbar.bouncing = True |
| 268 | else: |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 269 | pbar = BBProgress("0: %s" % msg, 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] | 270 | pbar.bouncing = False |
| 271 | activetasks[t]["progressbar"] = pbar |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 272 | tasks.append((pbar, msg, progress, rate, start_time)) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 273 | else: |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 274 | tasks.append(msg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 275 | |
| 276 | if self.main.shutdown: |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 277 | content = pluralise("Waiting for %s running task to finish", |
| 278 | "Waiting for %s running tasks to finish", len(activetasks)) |
| 279 | if not self.quiet: |
| 280 | content += ':' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 281 | print(content) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 282 | else: |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 283 | scene_tasks = "%s of %s" % (self.helper.setscene_current, self.helper.setscene_total) |
| 284 | cur_tasks = "%s of %s" % (self.helper.tasknumber_current, self.helper.tasknumber_total) |
| 285 | |
| 286 | content = '' |
| 287 | if not self.quiet: |
| 288 | msg = "Setscene tasks: %s" % scene_tasks |
| 289 | content += msg + "\n" |
| 290 | print(msg) |
| 291 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 292 | if self.quiet: |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 293 | msg = "Running tasks (%s, %s)" % (scene_tasks, cur_tasks) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 294 | elif not len(activetasks): |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 295 | msg = "No currently running tasks (%s)" % cur_tasks |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 296 | else: |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 297 | msg = "Currently %2s running tasks (%s)" % (len(activetasks), cur_tasks) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 298 | maxtask = self.helper.tasknumber_total |
| 299 | if not self.main_progress or self.main_progress.maxval != maxtask: |
| 300 | widgets = [' ', progressbar.Percentage(), ' ', progressbar.Bar()] |
| 301 | self.main_progress = BBProgress("Running tasks", maxtask, widgets=widgets, resize_handler=self.sigwinch_handle) |
| 302 | self.main_progress.start(False) |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 303 | self.main_progress.setmessage(msg) |
| 304 | progress = max(0, self.helper.tasknumber_current - 1) |
| 305 | content += self.main_progress.update(progress) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 306 | print('') |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 307 | lines = self.getlines(content) |
| 308 | if not self.quiet: |
| 309 | for tasknum, task in enumerate(tasks[:(self.rows - 1 - lines)]): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 310 | if isinstance(task, tuple): |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 311 | pbar, msg, progress, rate, start_time = task |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 312 | if not pbar.start_time: |
| 313 | pbar.start(False) |
| 314 | if start_time: |
| 315 | pbar.start_time = start_time |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 316 | pbar.setmessage('%s: %s' % (tasknum, msg)) |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 317 | pbar.setextra(rate) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 318 | if progress > -1: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 319 | content = pbar.update(progress) |
| 320 | else: |
| 321 | content = pbar.update(1) |
| 322 | print('') |
| 323 | else: |
| 324 | content = "%s: %s" % (tasknum, task) |
| 325 | print(content) |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 326 | lines = lines + self.getlines(content) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 327 | self.footer_present = lines |
| 328 | self.lastpids = runningpids[:] |
| 329 | self.lastcount = self.helper.tasknumber_current |
| 330 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 331 | def getlines(self, content): |
| 332 | lines = 0 |
| 333 | for line in content.split("\n"): |
| 334 | lines = lines + 1 + int(len(line) / (self.columns + 1)) |
| 335 | return lines |
| 336 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 337 | def finish(self): |
| 338 | if self.stdinbackup: |
| 339 | fd = sys.stdin.fileno() |
| 340 | self.termios.tcsetattr(fd, self.termios.TCSADRAIN, self.stdinbackup) |
| 341 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 342 | def print_event_log(event, includelogs, loglines, termfilter): |
| 343 | # FIXME refactor this out further |
| 344 | logfile = event.logfile |
| 345 | if logfile and os.path.exists(logfile): |
| 346 | termfilter.clearFooter() |
| 347 | bb.error("Logfile of failure stored in: %s" % logfile) |
| 348 | if includelogs and not event.errprinted: |
| 349 | print("Log data follows:") |
| 350 | f = open(logfile, "r") |
| 351 | lines = [] |
| 352 | while True: |
| 353 | l = f.readline() |
| 354 | if l == '': |
| 355 | break |
| 356 | l = l.rstrip() |
| 357 | if loglines: |
| 358 | lines.append(' | %s' % l) |
| 359 | if len(lines) > int(loglines): |
| 360 | lines.pop(0) |
| 361 | else: |
| 362 | print('| %s' % l) |
| 363 | f.close() |
| 364 | if lines: |
| 365 | for line in lines: |
| 366 | print(line) |
| 367 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 368 | def _log_settings_from_server(server, observe_only): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 369 | # Get values of variables which control our output |
| 370 | includelogs, error = server.runCommand(["getVariable", "BBINCLUDELOGS"]) |
| 371 | if error: |
| 372 | logger.error("Unable to get the value of BBINCLUDELOGS variable: %s" % error) |
| 373 | raise BaseException(error) |
| 374 | loglines, error = server.runCommand(["getVariable", "BBINCLUDELOGS_LINES"]) |
| 375 | if error: |
| 376 | logger.error("Unable to get the value of BBINCLUDELOGS_LINES variable: %s" % error) |
| 377 | raise BaseException(error) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 378 | if observe_only: |
| 379 | cmd = 'getVariable' |
| 380 | else: |
| 381 | cmd = 'getSetVariable' |
| 382 | consolelogfile, error = server.runCommand([cmd, "BB_CONSOLELOG"]) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 383 | if error: |
| 384 | logger.error("Unable to get the value of BB_CONSOLELOG variable: %s" % error) |
| 385 | raise BaseException(error) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 386 | logconfigfile, error = server.runCommand([cmd, "BB_LOGCONFIG"]) |
| 387 | if error: |
| 388 | logger.error("Unable to get the value of BB_LOGCONFIG variable: %s" % error) |
| 389 | raise BaseException(error) |
| 390 | return includelogs, loglines, consolelogfile, logconfigfile |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 391 | |
| 392 | _evt_list = [ "bb.runqueue.runQueueExitWait", "bb.event.LogExecTTY", "logging.LogRecord", |
| 393 | "bb.build.TaskFailed", "bb.build.TaskBase", "bb.event.ParseStarted", |
| 394 | "bb.event.ParseProgress", "bb.event.ParseCompleted", "bb.event.CacheLoadStarted", |
| 395 | "bb.event.CacheLoadProgress", "bb.event.CacheLoadCompleted", "bb.command.CommandFailed", |
| 396 | "bb.command.CommandExit", "bb.command.CommandCompleted", "bb.cooker.CookerExit", |
| 397 | "bb.event.MultipleProviders", "bb.event.NoProvider", "bb.runqueue.sceneQueueTaskStarted", |
| 398 | "bb.runqueue.runQueueTaskStarted", "bb.runqueue.runQueueTaskFailed", "bb.runqueue.sceneQueueTaskFailed", |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 399 | "bb.event.BuildBase", "bb.build.TaskStarted", "bb.build.TaskSucceeded", "bb.build.TaskFailedSilent", |
| 400 | "bb.build.TaskProgress", "bb.event.ProcessStarted", "bb.event.ProcessProgress", "bb.event.ProcessFinished"] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 401 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 402 | def drain_events_errorhandling(eventHandler): |
| 403 | # We don't have logging setup, we do need to show any events we see before exiting |
| 404 | event = True |
| 405 | logger = bb.msg.logger_create('bitbake', sys.stdout) |
| 406 | while event: |
| 407 | event = eventHandler.waitEvent(0) |
| 408 | if isinstance(event, logging.LogRecord): |
| 409 | logger.handle(event) |
| 410 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 411 | def main(server, eventHandler, params, tf = TerminalFilter): |
| 412 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 413 | try: |
| 414 | if not params.observe_only: |
| 415 | params.updateToServer(server, os.environ.copy()) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 416 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 417 | includelogs, loglines, consolelogfile, logconfigfile = _log_settings_from_server(server, params.observe_only) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 418 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 419 | loglevel, _ = bb.msg.constructLogOptions() |
| 420 | except bb.BBHandledException: |
| 421 | drain_events_errorhandling(eventHandler) |
| 422 | return 1 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 423 | |
| 424 | if params.options.quiet == 0: |
| 425 | console_loglevel = loglevel |
| 426 | elif params.options.quiet > 2: |
| 427 | console_loglevel = bb.msg.BBLogFormatter.ERROR |
| 428 | else: |
| 429 | console_loglevel = bb.msg.BBLogFormatter.WARNING |
| 430 | |
| 431 | logconfig = { |
| 432 | "version": 1, |
| 433 | "handlers": { |
| 434 | "BitBake.console": { |
| 435 | "class": "logging.StreamHandler", |
| 436 | "formatter": "BitBake.consoleFormatter", |
| 437 | "level": console_loglevel, |
| 438 | "stream": "ext://sys.stdout", |
| 439 | "filters": ["BitBake.stdoutFilter"], |
| 440 | ".": { |
| 441 | "is_console": True, |
| 442 | }, |
| 443 | }, |
| 444 | "BitBake.errconsole": { |
| 445 | "class": "logging.StreamHandler", |
| 446 | "formatter": "BitBake.consoleFormatter", |
| 447 | "level": loglevel, |
| 448 | "stream": "ext://sys.stderr", |
| 449 | "filters": ["BitBake.stderrFilter"], |
| 450 | ".": { |
| 451 | "is_console": True, |
| 452 | }, |
| 453 | }, |
| 454 | # This handler can be used if specific loggers should print on |
| 455 | # the console at a lower severity than the default. It will |
| 456 | # display any messages sent to it that are lower than then |
| 457 | # BitBake.console logging level (so as to prevent duplication of |
| 458 | # messages). Nothing is attached to this handler by default |
| 459 | "BitBake.verbconsole": { |
| 460 | "class": "logging.StreamHandler", |
| 461 | "formatter": "BitBake.consoleFormatter", |
| 462 | "level": 1, |
| 463 | "stream": "ext://sys.stdout", |
| 464 | "filters": ["BitBake.verbconsoleFilter"], |
| 465 | ".": { |
| 466 | "is_console": True, |
| 467 | }, |
| 468 | }, |
| 469 | }, |
| 470 | "formatters": { |
| 471 | # This format instance will get color output enabled by the |
| 472 | # terminal |
| 473 | "BitBake.consoleFormatter" : { |
| 474 | "()": "bb.msg.BBLogFormatter", |
| 475 | "format": "%(levelname)s: %(message)s" |
| 476 | }, |
| 477 | # The file log requires a separate instance so that it doesn't get |
| 478 | # color enabled |
| 479 | "BitBake.logfileFormatter": { |
| 480 | "()": "bb.msg.BBLogFormatter", |
| 481 | "format": "%(levelname)s: %(message)s" |
| 482 | } |
| 483 | }, |
| 484 | "filters": { |
| 485 | "BitBake.stdoutFilter": { |
| 486 | "()": "bb.msg.LogFilterLTLevel", |
| 487 | "level": "ERROR" |
| 488 | }, |
| 489 | "BitBake.stderrFilter": { |
| 490 | "()": "bb.msg.LogFilterGEQLevel", |
| 491 | "level": "ERROR" |
| 492 | }, |
| 493 | "BitBake.verbconsoleFilter": { |
| 494 | "()": "bb.msg.LogFilterLTLevel", |
| 495 | "level": console_loglevel |
| 496 | }, |
| 497 | }, |
| 498 | "loggers": { |
| 499 | "BitBake": { |
| 500 | "level": loglevel, |
| 501 | "handlers": ["BitBake.console", "BitBake.errconsole"], |
| 502 | } |
| 503 | }, |
| 504 | "disable_existing_loggers": False |
| 505 | } |
| 506 | |
| 507 | # Enable the console log file if enabled |
| 508 | if consolelogfile and not params.options.show_environment and not params.options.show_versions: |
| 509 | logconfig = bb.msg.mergeLoggingConfig(logconfig, { |
| 510 | "version": 1, |
| 511 | "handlers" : { |
| 512 | "BitBake.consolelog": { |
| 513 | "class": "logging.FileHandler", |
| 514 | "formatter": "BitBake.logfileFormatter", |
| 515 | "level": loglevel, |
| 516 | "filename": consolelogfile, |
| 517 | }, |
| 518 | # Just like verbconsole, anything sent here will go to the |
| 519 | # log file, unless it would go to BitBake.consolelog |
| 520 | "BitBake.verbconsolelog" : { |
| 521 | "class": "logging.FileHandler", |
| 522 | "formatter": "BitBake.logfileFormatter", |
| 523 | "level": 1, |
| 524 | "filename": consolelogfile, |
| 525 | "filters": ["BitBake.verbconsolelogFilter"], |
| 526 | }, |
| 527 | }, |
| 528 | "filters": { |
| 529 | "BitBake.verbconsolelogFilter": { |
| 530 | "()": "bb.msg.LogFilterLTLevel", |
| 531 | "level": loglevel, |
| 532 | }, |
| 533 | }, |
| 534 | "loggers": { |
| 535 | "BitBake": { |
| 536 | "handlers": ["BitBake.consolelog"], |
| 537 | }, |
| 538 | |
| 539 | # Other interesting things that we want to keep an eye on |
| 540 | # in the log files in case someone has an issue, but not |
| 541 | # necessarily show to the user on the console |
| 542 | "BitBake.SigGen.HashEquiv": { |
| 543 | "level": "VERBOSE", |
| 544 | "handlers": ["BitBake.verbconsolelog"], |
| 545 | }, |
| 546 | "BitBake.RunQueue.HashEquiv": { |
| 547 | "level": "VERBOSE", |
| 548 | "handlers": ["BitBake.verbconsolelog"], |
| 549 | } |
| 550 | } |
| 551 | }) |
| 552 | |
| 553 | bb.utils.mkdirhier(os.path.dirname(consolelogfile)) |
| 554 | loglink = os.path.join(os.path.dirname(consolelogfile), 'console-latest.log') |
| 555 | bb.utils.remove(loglink) |
| 556 | try: |
| 557 | os.symlink(os.path.basename(consolelogfile), loglink) |
| 558 | except OSError: |
| 559 | pass |
| 560 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 561 | # Add the logging domains specified by the user on the command line |
| 562 | for (domainarg, iterator) in groupby(params.debug_domains): |
| 563 | dlevel = len(tuple(iterator)) |
| 564 | l = logconfig["loggers"].setdefault("BitBake.%s" % domainarg, {}) |
| 565 | l["level"] = logging.DEBUG - dlevel + 1 |
| 566 | l.setdefault("handlers", []).extend(["BitBake.verbconsole"]) |
| 567 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 568 | conf = bb.msg.setLoggingConfig(logconfig, logconfigfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 569 | |
| 570 | if sys.stdin.isatty() and sys.stdout.isatty(): |
| 571 | log_exec_tty = True |
| 572 | else: |
| 573 | log_exec_tty = False |
| 574 | |
| 575 | helper = uihelper.BBUIHelper() |
| 576 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 577 | # Look for the specially designated handlers which need to be passed to the |
| 578 | # terminal handler |
| 579 | 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] | 580 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 581 | bb.utils.set_process_name("KnottyUI") |
| 582 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 583 | if params.options.remote_server and params.options.kill_server: |
| 584 | server.terminateServer() |
| 585 | return |
| 586 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 587 | llevel, debug_domains = bb.msg.constructLogOptions() |
| 588 | server.runCommand(["setEventMask", server.getEventHandle(), llevel, debug_domains, _evt_list]) |
| 589 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 590 | # The logging_tree module is *extremely* helpful in debugging logging |
| 591 | # domains. Uncomment here to dump the logging tree when bitbake starts |
| 592 | #import logging_tree |
| 593 | #logging_tree.printout() |
| 594 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 595 | universe = False |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 596 | if not params.observe_only: |
| 597 | params.updateFromServer(server) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 598 | cmdline = params.parseActions() |
| 599 | if not cmdline: |
| 600 | print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.") |
| 601 | return 1 |
| 602 | if 'msg' in cmdline and cmdline['msg']: |
| 603 | logger.error(cmdline['msg']) |
| 604 | return 1 |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 605 | if cmdline['action'][0] == "buildTargets" and "universe" in cmdline['action'][1]: |
| 606 | universe = True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 607 | |
| 608 | ret, error = server.runCommand(cmdline['action']) |
| 609 | if error: |
| 610 | logger.error("Command '%s' failed: %s" % (cmdline, error)) |
| 611 | return 1 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 612 | elif not ret: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 613 | logger.error("Command '%s' failed: returned %s" % (cmdline, ret)) |
| 614 | return 1 |
| 615 | |
| 616 | |
| 617 | parseprogress = None |
| 618 | cacheprogress = None |
| 619 | main.shutdown = 0 |
| 620 | interrupted = False |
| 621 | return_value = 0 |
| 622 | errors = 0 |
| 623 | warnings = 0 |
| 624 | taskfailures = [] |
| 625 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 626 | printintervaldelta = 10 * 60 # 10 minutes |
| 627 | printinterval = printintervaldelta |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 628 | pinginterval = 1 * 60 # 1 minute |
| 629 | lastevent = lastprint = time.time() |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 630 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 631 | termfilter = tf(main, helper, console_handlers, params.options.quiet) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 632 | atexit.register(termfilter.finish) |
| 633 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 634 | # shutdown levels |
| 635 | # 0 - normal operation |
| 636 | # 1 - no new task execution, let current running tasks finish |
| 637 | # 2 - interrupting currently executing tasks |
| 638 | # 3 - we're done, exit |
| 639 | while main.shutdown < 3: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 640 | try: |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 641 | if (lastprint + printinterval) <= time.time(): |
| 642 | termfilter.keepAlive(printinterval) |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 643 | printinterval += printintervaldelta |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 644 | event = eventHandler.waitEvent(0) |
| 645 | if event is None: |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 646 | if (lastevent + pinginterval) <= time.time(): |
| 647 | ret, error = server.runCommand(["ping"]) |
| 648 | if error or not ret: |
| 649 | termfilter.clearFooter() |
| 650 | print("No reply after pinging server (%s, %s), exiting." % (str(error), str(ret))) |
| 651 | return_value = 3 |
| 652 | main.shutdown = 3 |
| 653 | lastevent = time.time() |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 654 | if not parseprogress: |
| 655 | termfilter.updateFooter() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 656 | event = eventHandler.waitEvent(0.25) |
| 657 | if event is None: |
| 658 | continue |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 659 | lastevent = time.time() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 660 | helper.eventHandler(event) |
| 661 | if isinstance(event, bb.runqueue.runQueueExitWait): |
| 662 | if not main.shutdown: |
| 663 | main.shutdown = 1 |
| 664 | continue |
| 665 | if isinstance(event, bb.event.LogExecTTY): |
| 666 | if log_exec_tty: |
| 667 | tries = event.retries |
| 668 | while tries: |
| 669 | print("Trying to run: %s" % event.prog) |
| 670 | if os.system(event.prog) == 0: |
| 671 | break |
| 672 | time.sleep(event.sleep_delay) |
| 673 | tries -= 1 |
| 674 | if tries: |
| 675 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 676 | logger.warning(event.msg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 677 | continue |
| 678 | |
| 679 | if isinstance(event, logging.LogRecord): |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 680 | lastprint = time.time() |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 681 | printinterval = printintervaldelta |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 682 | if event.levelno >= bb.msg.BBLogFormatter.ERRORONCE: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 683 | errors = errors + 1 |
| 684 | return_value = 1 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 685 | elif event.levelno == bb.msg.BBLogFormatter.WARNING: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 686 | warnings = warnings + 1 |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 687 | |
| 688 | if event.taskpid != 0: |
| 689 | # For "normal" logging conditions, don't show note logs from tasks |
| 690 | # but do show them if the user has changed the default log level to |
| 691 | # include verbose/debug messages |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 692 | 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] | 693 | continue |
| 694 | |
| 695 | # Prefix task messages with recipe/task |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 696 | if event.taskpid in helper.pidmap and event.levelno not in [bb.msg.BBLogFormatter.PLAIN, bb.msg.BBLogFormatter.WARNONCE, bb.msg.BBLogFormatter.ERRORONCE]: |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 697 | taskinfo = helper.running_tasks[helper.pidmap[event.taskpid]] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 698 | event.msg = taskinfo['title'] + ': ' + event.msg |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 699 | if hasattr(event, 'fn') and event.levelno not in [bb.msg.BBLogFormatter.WARNONCE, bb.msg.BBLogFormatter.ERRORONCE]: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 700 | event.msg = event.fn + ': ' + event.msg |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 701 | logging.getLogger(event.name).handle(event) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 702 | continue |
| 703 | |
| 704 | if isinstance(event, bb.build.TaskFailedSilent): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 705 | logger.warning("Logfile for failed setscene task is %s" % event.logfile) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 706 | continue |
| 707 | if isinstance(event, bb.build.TaskFailed): |
| 708 | return_value = 1 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 709 | print_event_log(event, includelogs, loglines, termfilter) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 710 | if isinstance(event, bb.build.TaskBase): |
| 711 | logger.info(event._message) |
| 712 | continue |
| 713 | if isinstance(event, bb.event.ParseStarted): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 714 | if params.options.quiet > 1: |
| 715 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 716 | if event.total == 0: |
| 717 | continue |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 718 | termfilter.clearFooter() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 719 | parseprogress = new_progress("Parsing recipes", event.total).start() |
| 720 | continue |
| 721 | if isinstance(event, bb.event.ParseProgress): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 722 | if params.options.quiet > 1: |
| 723 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 724 | if parseprogress: |
| 725 | parseprogress.update(event.current) |
| 726 | else: |
| 727 | bb.warn("Got ParseProgress event for parsing that never started?") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 728 | continue |
| 729 | if isinstance(event, bb.event.ParseCompleted): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 730 | if params.options.quiet > 1: |
| 731 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 732 | if not parseprogress: |
| 733 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 734 | parseprogress.finish() |
Andrew Geissler | 4c19ea1 | 2020-10-27 13:52:24 -0500 | [diff] [blame] | 735 | parseprogress = None |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 736 | if params.options.quiet == 0: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 737 | print(("Parsing of %d .bb files complete (%d cached, %d parsed). %d targets, %d skipped, %d masked, %d errors." |
| 738 | % ( 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] | 739 | continue |
| 740 | |
| 741 | if isinstance(event, bb.event.CacheLoadStarted): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 742 | if params.options.quiet > 1: |
| 743 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 744 | cacheprogress = new_progress("Loading cache", event.total).start() |
| 745 | continue |
| 746 | if isinstance(event, bb.event.CacheLoadProgress): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 747 | if params.options.quiet > 1: |
| 748 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 749 | cacheprogress.update(event.current) |
| 750 | continue |
| 751 | if isinstance(event, bb.event.CacheLoadCompleted): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 752 | if params.options.quiet > 1: |
| 753 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 754 | cacheprogress.finish() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 755 | if params.options.quiet == 0: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 756 | print("Loaded %d entries from dependency cache." % event.num_entries) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 757 | continue |
| 758 | |
| 759 | if isinstance(event, bb.command.CommandFailed): |
| 760 | return_value = event.exitcode |
| 761 | if event.error: |
| 762 | errors = errors + 1 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 763 | logger.error(str(event)) |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 764 | main.shutdown = 3 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 765 | continue |
| 766 | if isinstance(event, bb.command.CommandExit): |
| 767 | if not return_value: |
| 768 | return_value = event.exitcode |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 769 | main.shutdown = 3 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 770 | continue |
| 771 | if isinstance(event, (bb.command.CommandCompleted, bb.cooker.CookerExit)): |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 772 | main.shutdown = 3 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 773 | continue |
| 774 | if isinstance(event, bb.event.MultipleProviders): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 775 | logger.info(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 776 | continue |
| 777 | if isinstance(event, bb.event.NoProvider): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 778 | # For universe builds, only show these as warnings, not errors |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 779 | if not universe: |
| 780 | return_value = 1 |
| 781 | errors = errors + 1 |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 782 | logger.error(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 783 | else: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 784 | logger.warning(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 785 | continue |
| 786 | |
| 787 | if isinstance(event, bb.runqueue.sceneQueueTaskStarted): |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 788 | 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] | 789 | continue |
| 790 | |
| 791 | if isinstance(event, bb.runqueue.runQueueTaskStarted): |
| 792 | if event.noexec: |
| 793 | tasktype = 'noexec task' |
| 794 | else: |
| 795 | tasktype = 'task' |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 796 | logger.info("Running %s %d of %d (%s)", |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 797 | tasktype, |
| 798 | event.stats.completed + event.stats.active + |
| 799 | event.stats.failed + 1, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 800 | event.stats.total, event.taskstring) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 801 | continue |
| 802 | |
| 803 | if isinstance(event, bb.runqueue.runQueueTaskFailed): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 804 | return_value = 1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 805 | taskfailures.append(event.taskstring) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 806 | logger.error(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 807 | continue |
| 808 | |
| 809 | if isinstance(event, bb.runqueue.sceneQueueTaskFailed): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 810 | logger.warning(str(event)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 811 | continue |
| 812 | |
| 813 | if isinstance(event, bb.event.DepTreeGenerated): |
| 814 | continue |
| 815 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 816 | if isinstance(event, bb.event.ProcessStarted): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 817 | if params.options.quiet > 1: |
| 818 | continue |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 819 | termfilter.clearFooter() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 820 | parseprogress = new_progress(event.processname, event.total) |
| 821 | parseprogress.start(False) |
| 822 | continue |
| 823 | if isinstance(event, bb.event.ProcessProgress): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 824 | if params.options.quiet > 1: |
| 825 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 826 | if parseprogress: |
| 827 | parseprogress.update(event.progress) |
| 828 | else: |
| 829 | bb.warn("Got ProcessProgress event for someting that never started?") |
| 830 | continue |
| 831 | if isinstance(event, bb.event.ProcessFinished): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 832 | if params.options.quiet > 1: |
| 833 | continue |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 834 | if parseprogress: |
| 835 | parseprogress.finish() |
| 836 | parseprogress = None |
| 837 | continue |
| 838 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 839 | # ignore |
| 840 | if isinstance(event, (bb.event.BuildBase, |
| 841 | bb.event.MetadataEvent, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 842 | bb.event.ConfigParsed, |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 843 | bb.event.MultiConfigParsed, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 844 | bb.event.RecipeParsed, |
| 845 | bb.event.RecipePreFinalise, |
| 846 | bb.runqueue.runQueueEvent, |
| 847 | bb.event.OperationStarted, |
| 848 | bb.event.OperationCompleted, |
| 849 | bb.event.OperationProgress, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 850 | bb.event.DiskFull, |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 851 | bb.event.HeartbeatEvent, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 852 | bb.build.TaskProgress)): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 853 | continue |
| 854 | |
| 855 | logger.error("Unknown event: %s", event) |
| 856 | |
| 857 | except EnvironmentError as ioerror: |
| 858 | termfilter.clearFooter() |
| 859 | # ignore interrupted io |
| 860 | if ioerror.args[0] == 4: |
| 861 | continue |
| 862 | sys.stderr.write(str(ioerror)) |
| 863 | if not params.observe_only: |
| 864 | _, error = server.runCommand(["stateForceShutdown"]) |
| 865 | main.shutdown = 2 |
| 866 | except KeyboardInterrupt: |
| 867 | termfilter.clearFooter() |
| 868 | if params.observe_only: |
| 869 | print("\nKeyboard Interrupt, exiting observer...") |
| 870 | main.shutdown = 2 |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 871 | |
| 872 | def state_force_shutdown(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 873 | print("\nSecond Keyboard Interrupt, stopping...\n") |
| 874 | _, error = server.runCommand(["stateForceShutdown"]) |
| 875 | if error: |
| 876 | logger.error("Unable to cleanly stop: %s" % error) |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 877 | |
| 878 | if not params.observe_only and main.shutdown == 1: |
| 879 | state_force_shutdown() |
| 880 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 881 | if not params.observe_only and main.shutdown == 0: |
| 882 | print("\nKeyboard Interrupt, closing down...\n") |
| 883 | interrupted = True |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 884 | # Capture the second KeyboardInterrupt during stateShutdown is running |
| 885 | try: |
| 886 | _, error = server.runCommand(["stateShutdown"]) |
| 887 | if error: |
| 888 | logger.error("Unable to cleanly shutdown: %s" % error) |
| 889 | except KeyboardInterrupt: |
| 890 | state_force_shutdown() |
| 891 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 892 | main.shutdown = main.shutdown + 1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 893 | except Exception as e: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 894 | import traceback |
| 895 | sys.stderr.write(traceback.format_exc()) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 896 | if not params.observe_only: |
| 897 | _, error = server.runCommand(["stateForceShutdown"]) |
| 898 | main.shutdown = 2 |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 899 | return_value = 1 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 900 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 901 | termfilter.clearFooter() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 902 | summary = "" |
| 903 | if taskfailures: |
| 904 | summary += pluralise("\nSummary: %s task failed:", |
| 905 | "\nSummary: %s tasks failed:", len(taskfailures)) |
| 906 | for failure in taskfailures: |
| 907 | summary += "\n %s" % failure |
| 908 | if warnings: |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 909 | summary += pluralise("\nSummary: There was %s WARNING message.", |
| 910 | "\nSummary: There were %s WARNING messages.", warnings) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 911 | if return_value and errors: |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 912 | summary += pluralise("\nSummary: There was %s ERROR message, returning a non-zero exit code.", |
| 913 | "\nSummary: There were %s ERROR messages, returning a non-zero exit code.", errors) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 914 | if summary and params.options.quiet == 0: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 915 | print(summary) |
| 916 | |
| 917 | if interrupted: |
| 918 | print("Execution was interrupted, returning a non-zero exit code.") |
| 919 | if return_value == 0: |
| 920 | return_value = 1 |
| 921 | except IOError as e: |
| 922 | import errno |
| 923 | if e.errno == errno.EPIPE: |
| 924 | pass |
| 925 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 926 | logging.shutdown() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 927 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 928 | return return_value |