Complete Yocto mirror with license table for TQMa6UL (2038-compliance)

- 264 license table entries with exact download URLs (224/264 resolved)
- Complete sources/ directory with all BitBake recipes
- Build configuration: tqma6ul-multi-mba6ulx, spaetzle (musl)
- Full traceability for Softwarefreigabeantrag
- GCC 13.4.0, Linux 6.6.102, U-Boot 2023.04, musl 1.2.4
- License distribution: GPL-2.0 (24), MIT (23), GPL-2.0+ (18), BSD-3 (16)
This commit is contained in:
Siggi (OpenClaw Agent)
2026-03-01 20:58:18 +00:00
commit 16accb6b24
15086 changed files with 1292356 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
#
# BitBake UI Implementation
#
# Copyright (C) 2006-2007 Richard Purdie
#
# SPDX-License-Identifier: GPL-2.0-only
#

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,86 @@
#!/usr/bin/env python3
#
# SPDX-License-Identifier: GPL-2.0-only
#
# This file re-uses code spread throughout other Bitbake source files.
# As such, all other copyrights belong to their own right holders.
#
import os
import sys
import json
import pickle
import codecs
class EventPlayer:
"""Emulate a connection to a bitbake server."""
def __init__(self, eventfile, variables):
self.eventfile = eventfile
self.variables = variables
self.eventmask = []
def waitEvent(self, _timeout):
"""Read event from the file."""
line = self.eventfile.readline().strip()
if not line:
return
try:
decodedline = json.loads(line)
if 'allvariables' in decodedline:
self.variables = decodedline['allvariables']
return
if not 'vars' in decodedline:
raise ValueError
event_str = decodedline['vars'].encode('utf-8')
event = pickle.loads(codecs.decode(event_str, 'base64'))
event_name = "%s.%s" % (event.__module__, event.__class__.__name__)
if event_name not in self.eventmask:
return
return event
except ValueError as err:
print("Failed loading ", line)
raise err
def runCommand(self, command_line):
"""Emulate running a command on the server."""
name = command_line[0]
if name == "getVariable":
var_name = command_line[1]
variable = self.variables.get(var_name)
if variable:
return variable['v'], None
return None, "Missing variable %s" % var_name
elif name == "getAllKeysWithFlags":
dump = {}
flaglist = command_line[1]
for key, val in self.variables.items():
try:
if not key.startswith("__"):
dump[key] = {
'v': val['v'],
'history' : val['history'],
}
for flag in flaglist:
dump[key][flag] = val[flag]
except Exception as err:
print(err)
return (dump, None)
elif name == 'setEventMask':
self.eventmask = command_line[-1]
return True, None
else:
raise Exception("Command %s not implemented" % command_line[0])
def getEventHandle(self):
"""
This method is called by toasterui.
The return value is passed to self.runCommand but not used there.
"""
pass

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@@ -0,0 +1,984 @@
#
# BitBake (No)TTY UI Implementation
#
# Handling output to TTYs or files (no TTY)
#
# Copyright (C) 2006-2012 Richard Purdie
#
# SPDX-License-Identifier: GPL-2.0-only
#
from __future__ import division
import os
import sys
import logging
import progressbar
import signal
import bb.msg
import time
import fcntl
import struct
import copy
import atexit
from itertools import groupby
from bb.ui import uihelper
featureSet = [bb.cooker.CookerFeatures.SEND_SANITYEVENTS, bb.cooker.CookerFeatures.BASEDATASTORE_TRACKING]
logger = logging.getLogger("BitBake")
interactive = sys.stdout.isatty()
class BBProgress(progressbar.ProgressBar):
def __init__(self, msg, maxval, widgets=None, extrapos=-1, resize_handler=None):
self.msg = msg
self.extrapos = extrapos
if not widgets:
widgets = [': ', progressbar.Percentage(), ' ', progressbar.Bar(),
' ', progressbar.ETA()]
self.extrapos = 5
if resize_handler:
self._resize_default = resize_handler
else:
self._resize_default = signal.getsignal(signal.SIGWINCH)
progressbar.ProgressBar.__init__(self, maxval, [self.msg] + widgets, fd=sys.stdout)
def _handle_resize(self, signum=None, frame=None):
progressbar.ProgressBar._handle_resize(self, signum, frame)
if self._resize_default:
self._resize_default(signum, frame)
def finish(self):
progressbar.ProgressBar.finish(self)
if self._resize_default:
signal.signal(signal.SIGWINCH, self._resize_default)
def setmessage(self, msg):
self.msg = msg
self.widgets[0] = msg
def setextra(self, extra):
if self.extrapos > -1:
if extra:
extrastr = str(extra)
if extrastr[0] != ' ':
extrastr = ' ' + extrastr
else:
extrastr = ''
self.widgets[self.extrapos] = extrastr
def _need_update(self):
# We always want the bar to print when update() is called
return True
class NonInteractiveProgress(object):
fobj = sys.stdout
def __init__(self, msg, maxval):
self.msg = msg
self.maxval = maxval
self.finished = False
def start(self, update=True):
self.fobj.write("%s..." % self.msg)
self.fobj.flush()
return self
def update(self, value):
pass
def finish(self):
if self.finished:
return
self.fobj.write("done.\n")
self.fobj.flush()
self.finished = True
def new_progress(msg, maxval):
if interactive:
return BBProgress(msg, maxval)
else:
return NonInteractiveProgress(msg, maxval)
def pluralise(singular, plural, qty):
if(qty == 1):
return singular % qty
else:
return plural % qty
class InteractConsoleLogFilter(logging.Filter):
def __init__(self, tf):
self.tf = tf
def filter(self, record):
if record.levelno == bb.msg.BBLogFormatter.NOTE and (record.msg.startswith("Running") or record.msg.startswith("recipe ")):
return False
self.tf.clearFooter()
return True
class TerminalFilter(object):
rows = 25
columns = 80
def sigwinch_handle(self, signum, frame):
self.rows, self.columns = self.getTerminalColumns()
if self._sigwinch_default:
self._sigwinch_default(signum, frame)
def getTerminalColumns(self):
def ioctl_GWINSZ(fd):
try:
cr = struct.unpack('hh', fcntl.ioctl(fd, self.termios.TIOCGWINSZ, '1234'))
except:
return None
return cr
cr = ioctl_GWINSZ(sys.stdout.fileno())
if not cr:
try:
fd = os.open(os.ctermid(), os.O_RDONLY)
cr = ioctl_GWINSZ(fd)
os.close(fd)
except:
pass
if not cr:
try:
cr = (os.environ['LINES'], os.environ['COLUMNS'])
except:
cr = (25, 80)
return cr
def __init__(self, main, helper, handlers, quiet):
self.main = main
self.helper = helper
self.cuu = None
self.stdinbackup = None
self.interactive = sys.stdout.isatty()
self.footer_present = False
self.lastpids = []
self.lasttime = None
self.quiet = quiet
if not self.interactive:
return
try:
import curses
except ImportError:
sys.exit("FATAL: The knotty ui could not load the required curses python module.")
import termios
self.curses = curses
self.termios = termios
try:
fd = sys.stdin.fileno()
self.stdinbackup = termios.tcgetattr(fd)
new = copy.deepcopy(self.stdinbackup)
new[3] = new[3] & ~termios.ECHO
termios.tcsetattr(fd, termios.TCSADRAIN, new)
curses.setupterm()
if curses.tigetnum("colors") > 2 and os.environ.get('NO_COLOR', '') == '':
for h in handlers:
try:
h.formatter.enable_color()
except AttributeError:
pass
self.ed = curses.tigetstr("ed")
if self.ed:
self.cuu = curses.tigetstr("cuu")
try:
self._sigwinch_default = signal.getsignal(signal.SIGWINCH)
signal.signal(signal.SIGWINCH, self.sigwinch_handle)
except:
pass
self.rows, self.columns = self.getTerminalColumns()
except:
self.cuu = None
if not self.cuu:
self.interactive = False
bb.note("Unable to use interactive mode for this terminal, using fallback")
return
for h in handlers:
h.addFilter(InteractConsoleLogFilter(self))
self.main_progress = None
def clearFooter(self):
if self.footer_present:
lines = self.footer_present
sys.stdout.buffer.write(self.curses.tparm(self.cuu, lines))
sys.stdout.buffer.write(self.curses.tparm(self.ed))
sys.stdout.flush()
self.footer_present = False
def elapsed(self, sec):
hrs = int(sec / 3600.0)
sec -= hrs * 3600
min = int(sec / 60.0)
sec -= min * 60
if hrs > 0:
return "%dh%dm%ds" % (hrs, min, sec)
elif min > 0:
return "%dm%ds" % (min, sec)
else:
return "%ds" % (sec)
def keepAlive(self, t):
if not self.cuu:
print("Bitbake still alive (no events for %ds). Active tasks:" % t)
for t in self.helper.running_tasks:
print(t)
sys.stdout.flush()
def updateFooter(self):
if not self.cuu:
return
activetasks = self.helper.running_tasks
failedtasks = self.helper.failed_tasks
runningpids = self.helper.running_pids
currenttime = time.time()
if not self.lasttime or (currenttime - self.lasttime > 5):
self.helper.needUpdate = True
self.lasttime = currenttime
if self.footer_present and not self.helper.needUpdate:
return
self.helper.needUpdate = False
if self.footer_present:
self.clearFooter()
if (not self.helper.tasknumber_total or self.helper.tasknumber_current == self.helper.tasknumber_total) and not len(activetasks):
return
tasks = []
for t in runningpids:
start_time = activetasks[t].get("starttime", None)
if start_time:
msg = "%s - %s (pid %s)" % (activetasks[t]["title"], self.elapsed(currenttime - start_time), activetasks[t]["pid"])
else:
msg = "%s (pid %s)" % (activetasks[t]["title"], activetasks[t]["pid"])
progress = activetasks[t].get("progress", None)
if progress is not None:
pbar = activetasks[t].get("progressbar", None)
rate = activetasks[t].get("rate", None)
if not pbar or pbar.bouncing != (progress < 0):
if progress < 0:
pbar = BBProgress("0: %s" % msg, 100, widgets=[' ', progressbar.BouncingSlider(), ''], extrapos=3, resize_handler=self.sigwinch_handle)
pbar.bouncing = True
else:
pbar = BBProgress("0: %s" % msg, 100, widgets=[' ', progressbar.Percentage(), ' ', progressbar.Bar(), ''], extrapos=5, resize_handler=self.sigwinch_handle)
pbar.bouncing = False
activetasks[t]["progressbar"] = pbar
tasks.append((pbar, msg, progress, rate, start_time))
else:
tasks.append(msg)
if self.main.shutdown:
content = pluralise("Waiting for %s running task to finish",
"Waiting for %s running tasks to finish", len(activetasks))
if not self.quiet:
content += ':'
print(content)
else:
scene_tasks = "%s of %s" % (self.helper.setscene_current, self.helper.setscene_total)
cur_tasks = "%s of %s" % (self.helper.tasknumber_current, self.helper.tasknumber_total)
content = ''
if not self.quiet:
msg = "Setscene tasks: %s" % scene_tasks
content += msg + "\n"
print(msg)
if self.quiet:
msg = "Running tasks (%s, %s)" % (scene_tasks, cur_tasks)
elif not len(activetasks):
msg = "No currently running tasks (%s)" % cur_tasks
else:
msg = "Currently %2s running tasks (%s)" % (len(activetasks), cur_tasks)
maxtask = self.helper.tasknumber_total
if not self.main_progress or self.main_progress.maxval != maxtask:
widgets = [' ', progressbar.Percentage(), ' ', progressbar.Bar()]
self.main_progress = BBProgress("Running tasks", maxtask, widgets=widgets, resize_handler=self.sigwinch_handle)
self.main_progress.start(False)
self.main_progress.setmessage(msg)
progress = max(0, self.helper.tasknumber_current - 1)
content += self.main_progress.update(progress)
print('')
lines = self.getlines(content)
if not self.quiet:
for tasknum, task in enumerate(tasks[:(self.rows - 1 - lines)]):
if isinstance(task, tuple):
pbar, msg, progress, rate, start_time = task
if not pbar.start_time:
pbar.start(False)
if start_time:
pbar.start_time = start_time
pbar.setmessage('%s: %s' % (tasknum, msg))
pbar.setextra(rate)
if progress > -1:
content = pbar.update(progress)
else:
content = pbar.update(1)
print('')
else:
content = "%s: %s" % (tasknum, task)
print(content)
lines = lines + self.getlines(content)
self.footer_present = lines
self.lastpids = runningpids[:]
self.lastcount = self.helper.tasknumber_current
def getlines(self, content):
lines = 0
for line in content.split("\n"):
lines = lines + 1 + int(len(line) / (self.columns + 1))
return lines
def finish(self):
if self.stdinbackup:
fd = sys.stdin.fileno()
self.termios.tcsetattr(fd, self.termios.TCSADRAIN, self.stdinbackup)
def print_event_log(event, includelogs, loglines, termfilter):
# FIXME refactor this out further
logfile = event.logfile
if logfile and os.path.exists(logfile):
termfilter.clearFooter()
bb.error("Logfile of failure stored in: %s" % logfile)
if includelogs and not event.errprinted:
print("Log data follows:")
f = open(logfile, "r")
lines = []
while True:
l = f.readline()
if l == '':
break
l = l.rstrip()
if loglines:
lines.append(' | %s' % l)
if len(lines) > int(loglines):
lines.pop(0)
else:
print('| %s' % l)
f.close()
if lines:
for line in lines:
print(line)
def _log_settings_from_server(server, observe_only):
# Get values of variables which control our output
includelogs, error = server.runCommand(["getVariable", "BBINCLUDELOGS"])
if error:
logger.error("Unable to get the value of BBINCLUDELOGS variable: %s" % error)
raise BaseException(error)
loglines, error = server.runCommand(["getVariable", "BBINCLUDELOGS_LINES"])
if error:
logger.error("Unable to get the value of BBINCLUDELOGS_LINES variable: %s" % error)
raise BaseException(error)
if observe_only:
cmd = 'getVariable'
else:
cmd = 'getSetVariable'
consolelogfile, error = server.runCommand([cmd, "BB_CONSOLELOG"])
if error:
logger.error("Unable to get the value of BB_CONSOLELOG variable: %s" % error)
raise BaseException(error)
logconfigfile, error = server.runCommand([cmd, "BB_LOGCONFIG"])
if error:
logger.error("Unable to get the value of BB_LOGCONFIG variable: %s" % error)
raise BaseException(error)
return includelogs, loglines, consolelogfile, logconfigfile
_evt_list = [ "bb.runqueue.runQueueExitWait", "bb.event.LogExecTTY", "logging.LogRecord",
"bb.build.TaskFailed", "bb.build.TaskBase", "bb.event.ParseStarted",
"bb.event.ParseProgress", "bb.event.ParseCompleted", "bb.event.CacheLoadStarted",
"bb.event.CacheLoadProgress", "bb.event.CacheLoadCompleted", "bb.command.CommandFailed",
"bb.command.CommandExit", "bb.command.CommandCompleted", "bb.cooker.CookerExit",
"bb.event.MultipleProviders", "bb.event.NoProvider", "bb.runqueue.sceneQueueTaskStarted",
"bb.runqueue.runQueueTaskStarted", "bb.runqueue.runQueueTaskFailed", "bb.runqueue.sceneQueueTaskFailed",
"bb.event.BuildBase", "bb.build.TaskStarted", "bb.build.TaskSucceeded", "bb.build.TaskFailedSilent",
"bb.build.TaskProgress", "bb.event.ProcessStarted", "bb.event.ProcessProgress", "bb.event.ProcessFinished"]
def drain_events_errorhandling(eventHandler):
# We don't have logging setup, we do need to show any events we see before exiting
event = True
logger = bb.msg.logger_create('bitbake', sys.stdout)
while event:
event = eventHandler.waitEvent(0)
if isinstance(event, logging.LogRecord):
logger.handle(event)
def main(server, eventHandler, params, tf = TerminalFilter):
try:
if not params.observe_only:
params.updateToServer(server, os.environ.copy())
includelogs, loglines, consolelogfile, logconfigfile = _log_settings_from_server(server, params.observe_only)
loglevel, _ = bb.msg.constructLogOptions()
except bb.BBHandledException:
drain_events_errorhandling(eventHandler)
return 1
except Exception as e:
# bitbake-server comms failure
early_logger = bb.msg.logger_create('bitbake', sys.stdout)
early_logger.fatal("Attempting to set server environment: %s", e)
return 1
if params.options.quiet == 0:
console_loglevel = loglevel
elif params.options.quiet > 2:
console_loglevel = bb.msg.BBLogFormatter.ERROR
else:
console_loglevel = bb.msg.BBLogFormatter.WARNING
logconfig = {
"version": 1,
"handlers": {
"BitBake.console": {
"class": "logging.StreamHandler",
"formatter": "BitBake.consoleFormatter",
"level": console_loglevel,
"stream": "ext://sys.stdout",
"filters": ["BitBake.stdoutFilter"],
".": {
"is_console": True,
},
},
"BitBake.errconsole": {
"class": "logging.StreamHandler",
"formatter": "BitBake.consoleFormatter",
"level": loglevel,
"stream": "ext://sys.stderr",
"filters": ["BitBake.stderrFilter"],
".": {
"is_console": True,
},
},
# This handler can be used if specific loggers should print on
# the console at a lower severity than the default. It will
# display any messages sent to it that are lower than then
# BitBake.console logging level (so as to prevent duplication of
# messages). Nothing is attached to this handler by default
"BitBake.verbconsole": {
"class": "logging.StreamHandler",
"formatter": "BitBake.consoleFormatter",
"level": 1,
"stream": "ext://sys.stdout",
"filters": ["BitBake.verbconsoleFilter"],
".": {
"is_console": True,
},
},
},
"formatters": {
# This format instance will get color output enabled by the
# terminal
"BitBake.consoleFormatter" : {
"()": "bb.msg.BBLogFormatter",
"format": "%(levelname)s: %(message)s"
},
# The file log requires a separate instance so that it doesn't get
# color enabled
"BitBake.logfileFormatter": {
"()": "bb.msg.BBLogFormatter",
"format": "%(levelname)s: %(message)s"
}
},
"filters": {
"BitBake.stdoutFilter": {
"()": "bb.msg.LogFilterLTLevel",
"level": "ERROR"
},
"BitBake.stderrFilter": {
"()": "bb.msg.LogFilterGEQLevel",
"level": "ERROR"
},
"BitBake.verbconsoleFilter": {
"()": "bb.msg.LogFilterLTLevel",
"level": console_loglevel
},
},
"loggers": {
"BitBake": {
"level": loglevel,
"handlers": ["BitBake.console", "BitBake.errconsole"],
}
},
"disable_existing_loggers": False
}
# Enable the console log file if enabled
if consolelogfile and not params.options.show_environment and not params.options.show_versions:
logconfig = bb.msg.mergeLoggingConfig(logconfig, {
"version": 1,
"handlers" : {
"BitBake.consolelog": {
"class": "logging.FileHandler",
"formatter": "BitBake.logfileFormatter",
"level": loglevel,
"filename": consolelogfile,
},
# Just like verbconsole, anything sent here will go to the
# log file, unless it would go to BitBake.consolelog
"BitBake.verbconsolelog" : {
"class": "logging.FileHandler",
"formatter": "BitBake.logfileFormatter",
"level": 1,
"filename": consolelogfile,
"filters": ["BitBake.verbconsolelogFilter"],
},
},
"filters": {
"BitBake.verbconsolelogFilter": {
"()": "bb.msg.LogFilterLTLevel",
"level": loglevel,
},
},
"loggers": {
"BitBake": {
"handlers": ["BitBake.consolelog"],
},
# Other interesting things that we want to keep an eye on
# in the log files in case someone has an issue, but not
# necessarily show to the user on the console
"BitBake.SigGen.HashEquiv": {
"level": "VERBOSE",
"handlers": ["BitBake.verbconsolelog"],
},
"BitBake.RunQueue.HashEquiv": {
"level": "VERBOSE",
"handlers": ["BitBake.verbconsolelog"],
}
}
})
bb.utils.mkdirhier(os.path.dirname(consolelogfile))
loglink = os.path.join(os.path.dirname(consolelogfile), 'console-latest.log')
bb.utils.remove(loglink)
try:
os.symlink(os.path.basename(consolelogfile), loglink)
except OSError:
pass
# Add the logging domains specified by the user on the command line
for (domainarg, iterator) in groupby(params.debug_domains):
dlevel = len(tuple(iterator))
l = logconfig["loggers"].setdefault("BitBake.%s" % domainarg, {})
l["level"] = logging.DEBUG - dlevel + 1
l.setdefault("handlers", []).extend(["BitBake.verbconsole"])
conf = bb.msg.setLoggingConfig(logconfig, logconfigfile)
if sys.stdin.isatty() and sys.stdout.isatty():
log_exec_tty = True
else:
log_exec_tty = False
should_print_hyperlinks = sys.stdout.isatty() and os.environ.get('NO_COLOR', '') == ''
helper = uihelper.BBUIHelper()
# Look for the specially designated handlers which need to be passed to the
# terminal handler
console_handlers = [h for h in conf.config['handlers'].values() if getattr(h, 'is_console', False)]
bb.utils.set_process_name("KnottyUI")
if params.options.remote_server and params.options.kill_server:
server.terminateServer()
return
llevel, debug_domains = bb.msg.constructLogOptions()
try:
server.runCommand(["setEventMask", server.getEventHandle(), llevel, debug_domains, _evt_list])
except (BrokenPipeError, EOFError) as e:
# bitbake-server comms failure
logger.fatal("Attempting to set event mask: %s", e)
return 1
# The logging_tree module is *extremely* helpful in debugging logging
# domains. Uncomment here to dump the logging tree when bitbake starts
#import logging_tree
#logging_tree.printout()
universe = False
if not params.observe_only:
try:
params.updateFromServer(server)
except Exception as e:
logger.fatal("Fetching command line: %s", e)
return 1
cmdline = params.parseActions()
if not cmdline:
print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.")
return 1
if 'msg' in cmdline and cmdline['msg']:
logger.error(cmdline['msg'])
return 1
if cmdline['action'][0] == "buildTargets" and "universe" in cmdline['action'][1]:
universe = True
try:
ret, error = server.runCommand(cmdline['action'])
except (BrokenPipeError, EOFError) as e:
# bitbake-server comms failure
logger.fatal("Command '{}' failed: %s".format(cmdline), e)
return 1
if error:
logger.error("Command '%s' failed: %s" % (cmdline, error))
return 1
elif not ret:
logger.error("Command '%s' failed: returned %s" % (cmdline, ret))
return 1
parseprogress = None
cacheprogress = None
main.shutdown = 0
interrupted = False
return_value = 0
errors = 0
warnings = 0
taskfailures = {}
printintervaldelta = 10 * 60 # 10 minutes
printinterval = printintervaldelta
pinginterval = 1 * 60 # 1 minute
lastevent = lastprint = time.time()
termfilter = tf(main, helper, console_handlers, params.options.quiet)
atexit.register(termfilter.finish)
# shutdown levels
# 0 - normal operation
# 1 - no new task execution, let current running tasks finish
# 2 - interrupting currently executing tasks
# 3 - we're done, exit
while main.shutdown < 3:
try:
if (lastprint + printinterval) <= time.time():
termfilter.keepAlive(printinterval)
printinterval += printintervaldelta
event = eventHandler.waitEvent(0)
if event is None:
if (lastevent + pinginterval) <= time.time():
ret, error = server.runCommand(["ping"])
if error or not ret:
termfilter.clearFooter()
print("No reply after pinging server (%s, %s), exiting." % (str(error), str(ret)))
return_value = 3
main.shutdown = 3
lastevent = time.time()
if not parseprogress:
termfilter.updateFooter()
event = eventHandler.waitEvent(0.25)
if event is None:
continue
lastevent = time.time()
helper.eventHandler(event)
if isinstance(event, bb.runqueue.runQueueExitWait):
if not main.shutdown:
main.shutdown = 1
continue
if isinstance(event, bb.event.LogExecTTY):
if log_exec_tty:
tries = event.retries
while tries:
print("Trying to run: %s" % event.prog)
if os.system(event.prog) == 0:
break
time.sleep(event.sleep_delay)
tries -= 1
if tries:
continue
logger.warning(event.msg)
continue
if isinstance(event, logging.LogRecord):
lastprint = time.time()
printinterval = printintervaldelta
if event.levelno >= bb.msg.BBLogFormatter.ERRORONCE:
errors = errors + 1
return_value = 1
elif event.levelno == bb.msg.BBLogFormatter.WARNING:
warnings = warnings + 1
if event.taskpid != 0:
# For "normal" logging conditions, don't show note logs from tasks
# but do show them if the user has changed the default log level to
# include verbose/debug messages
if event.levelno <= bb.msg.BBLogFormatter.NOTE and (event.levelno < llevel or (event.levelno == bb.msg.BBLogFormatter.NOTE and llevel != bb.msg.BBLogFormatter.VERBOSE)):
continue
# Prefix task messages with recipe/task
if event.taskpid in helper.pidmap and event.levelno not in [bb.msg.BBLogFormatter.PLAIN, bb.msg.BBLogFormatter.WARNONCE, bb.msg.BBLogFormatter.ERRORONCE]:
taskinfo = helper.running_tasks[helper.pidmap[event.taskpid]]
event.msg = taskinfo['title'] + ': ' + event.msg
if hasattr(event, 'fn') and event.levelno not in [bb.msg.BBLogFormatter.WARNONCE, bb.msg.BBLogFormatter.ERRORONCE]:
event.msg = event.fn + ': ' + event.msg
logging.getLogger(event.name).handle(event)
continue
if isinstance(event, bb.build.TaskFailedSilent):
logger.warning("Logfile for failed setscene task is %s" % event.logfile)
continue
if isinstance(event, bb.build.TaskFailed):
return_value = 1
print_event_log(event, includelogs, loglines, termfilter)
k = "{}:{}".format(event._fn, event._task)
taskfailures[k] = event.logfile
if isinstance(event, bb.build.TaskBase):
logger.info(event._message)
continue
if isinstance(event, bb.event.ParseStarted):
if params.options.quiet > 1:
continue
if event.total == 0:
continue
termfilter.clearFooter()
parseprogress = new_progress("Parsing recipes", event.total).start()
continue
if isinstance(event, bb.event.ParseProgress):
if params.options.quiet > 1:
continue
if parseprogress:
parseprogress.update(event.current)
else:
bb.warn("Got ParseProgress event for parsing that never started?")
continue
if isinstance(event, bb.event.ParseCompleted):
if params.options.quiet > 1:
continue
if not parseprogress:
continue
parseprogress.finish()
parseprogress = None
if params.options.quiet == 0:
print(("Parsing of %d .bb files complete (%d cached, %d parsed). %d targets, %d skipped, %d masked, %d errors."
% ( event.total, event.cached, event.parsed, event.virtuals, event.skipped, event.masked, event.errors)))
continue
if isinstance(event, bb.event.CacheLoadStarted):
if params.options.quiet > 1:
continue
cacheprogress = new_progress("Loading cache", event.total).start()
continue
if isinstance(event, bb.event.CacheLoadProgress):
if params.options.quiet > 1:
continue
cacheprogress.update(event.current)
continue
if isinstance(event, bb.event.CacheLoadCompleted):
if params.options.quiet > 1:
continue
cacheprogress.finish()
if params.options.quiet == 0:
print("Loaded %d entries from dependency cache." % event.num_entries)
continue
if isinstance(event, bb.command.CommandFailed):
return_value = event.exitcode
if event.error:
errors = errors + 1
logger.error(str(event))
main.shutdown = 3
continue
if isinstance(event, bb.command.CommandExit):
if not return_value:
return_value = event.exitcode
main.shutdown = 3
continue
if isinstance(event, (bb.command.CommandCompleted, bb.cooker.CookerExit)):
main.shutdown = 3
continue
if isinstance(event, bb.event.MultipleProviders):
logger.info(str(event))
continue
if isinstance(event, bb.event.NoProvider):
# For universe builds, only show these as warnings, not errors
if not universe:
return_value = 1
errors = errors + 1
logger.error(str(event))
else:
logger.warning(str(event))
continue
if isinstance(event, bb.runqueue.sceneQueueTaskStarted):
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))
continue
if isinstance(event, bb.runqueue.runQueueTaskStarted):
if event.noexec:
tasktype = 'noexec task'
else:
tasktype = 'task'
logger.info("Running %s %d of %d (%s)",
tasktype,
event.stats.completed + event.stats.active +
event.stats.failed + 1,
event.stats.total, event.taskstring)
continue
if isinstance(event, bb.runqueue.runQueueTaskFailed):
return_value = 1
taskfailures.setdefault(event.taskstring)
logger.error(str(event))
continue
if isinstance(event, bb.runqueue.sceneQueueTaskFailed):
logger.warning(str(event))
continue
if isinstance(event, bb.event.DepTreeGenerated):
continue
if isinstance(event, bb.event.ProcessStarted):
if params.options.quiet > 1:
continue
termfilter.clearFooter()
parseprogress = new_progress(event.processname, event.total)
parseprogress.start(False)
continue
if isinstance(event, bb.event.ProcessProgress):
if params.options.quiet > 1:
continue
if parseprogress:
parseprogress.update(event.progress)
else:
bb.warn("Got ProcessProgress event for someting that never started?")
continue
if isinstance(event, bb.event.ProcessFinished):
if params.options.quiet > 1:
continue
if parseprogress:
parseprogress.finish()
parseprogress = None
continue
# ignore
if isinstance(event, (bb.event.BuildBase,
bb.event.MetadataEvent,
bb.event.ConfigParsed,
bb.event.MultiConfigParsed,
bb.event.RecipeParsed,
bb.event.RecipePreFinalise,
bb.runqueue.runQueueEvent,
bb.event.OperationStarted,
bb.event.OperationCompleted,
bb.event.OperationProgress,
bb.event.DiskFull,
bb.event.HeartbeatEvent,
bb.build.TaskProgress)):
continue
logger.error("Unknown event: %s", event)
except (BrokenPipeError, EOFError) as e:
# bitbake-server comms failure, don't attempt further comms and exit
logger.fatal("Executing event: %s", e)
return_value = 1
errors = errors + 1
main.shutdown = 3
except EnvironmentError as ioerror:
termfilter.clearFooter()
# ignore interrupted io
if ioerror.args[0] == 4:
continue
sys.stderr.write(str(ioerror))
main.shutdown = 2
if not params.observe_only:
try:
_, error = server.runCommand(["stateForceShutdown"])
except (BrokenPipeError, EOFError) as e:
# bitbake-server comms failure, don't attempt further comms and exit
logger.fatal("Unable to force shutdown: %s", e)
main.shutdown = 3
except KeyboardInterrupt:
termfilter.clearFooter()
if params.observe_only:
print("\nKeyboard Interrupt, exiting observer...")
main.shutdown = 2
def state_force_shutdown():
print("\nSecond Keyboard Interrupt, stopping...\n")
try:
_, error = server.runCommand(["stateForceShutdown"])
if error:
logger.error("Unable to cleanly stop: %s" % error)
except (BrokenPipeError, EOFError) as e:
# bitbake-server comms failure
logger.fatal("Unable to cleanly stop: %s", e)
if not params.observe_only and main.shutdown == 1:
state_force_shutdown()
if not params.observe_only and main.shutdown == 0:
print("\nKeyboard Interrupt, closing down...\n")
interrupted = True
# Capture the second KeyboardInterrupt during stateShutdown is running
try:
_, error = server.runCommand(["stateShutdown"])
if error:
logger.error("Unable to cleanly shutdown: %s" % error)
except (BrokenPipeError, EOFError) as e:
# bitbake-server comms failure
logger.fatal("Unable to cleanly shutdown: %s", e)
except KeyboardInterrupt:
state_force_shutdown()
main.shutdown = main.shutdown + 1
except Exception as e:
import traceback
sys.stderr.write(traceback.format_exc())
main.shutdown = 2
if not params.observe_only:
try:
_, error = server.runCommand(["stateForceShutdown"])
except (BrokenPipeError, EOFError) as e:
# bitbake-server comms failure, don't attempt further comms and exit
logger.fatal("Unable to force shutdown: %s", e)
main.shudown = 3
return_value = 1
try:
termfilter.clearFooter()
summary = ""
def format_hyperlink(url, link_text):
if should_print_hyperlinks:
start = f'\033]8;;{url}\033\\'
end = '\033]8;;\033\\'
return f'{start}{link_text}{end}'
return link_text
if taskfailures:
summary += pluralise("\nSummary: %s task failed:",
"\nSummary: %s tasks failed:", len(taskfailures))
for (failure, log_file) in taskfailures.items():
summary += "\n %s" % failure
if log_file:
hyperlink = format_hyperlink(f"file://{log_file}", log_file)
summary += "\n log: {}".format(hyperlink)
if warnings:
summary += pluralise("\nSummary: There was %s WARNING message.",
"\nSummary: There were %s WARNING messages.", warnings)
if return_value and errors:
summary += pluralise("\nSummary: There was %s ERROR message, returning a non-zero exit code.",
"\nSummary: There were %s ERROR messages, returning a non-zero exit code.", errors)
if summary and params.options.quiet == 0:
print(summary)
if interrupted:
print("Execution was interrupted, returning a non-zero exit code.")
if return_value == 0:
return_value = 1
except IOError as e:
import errno
if e.errno == errno.EPIPE:
pass
logging.shutdown()
return return_value

View File

@@ -0,0 +1,367 @@
#
# BitBake Curses UI Implementation
#
# Implements an ncurses frontend for the BitBake utility.
#
# Copyright (C) 2006 Michael 'Mickey' Lauer
# Copyright (C) 2006-2007 Richard Purdie
#
# SPDX-License-Identifier: GPL-2.0-only
#
"""
We have the following windows:
1.) Main Window: Shows what we are ultimately building and how far we are. Includes status bar
2.) Thread Activity Window: Shows one status line for every concurrent bitbake thread.
3.) Command Line Window: Contains an interactive command line where you can interact w/ Bitbake.
Basic window layout is like that:
|---------------------------------------------------------|
| <Main Window> | <Thread Activity Window> |
| | 0: foo do_compile complete|
| Building Gtk+-2.6.10 | 1: bar do_patch complete |
| Status: 60% | ... |
| | ... |
| | ... |
|---------------------------------------------------------|
|<Command Line Window> |
|>>> which virtual/kernel |
|openzaurus-kernel |
|>>> _ |
|---------------------------------------------------------|
"""
import logging
import os, sys, itertools, time
try:
import curses
except ImportError:
sys.exit("FATAL: The ncurses ui could not load the required curses python module.")
import bb
import xmlrpc.client
from bb.ui import uihelper
logger = logging.getLogger(__name__)
parsespin = itertools.cycle( r'|/-\\' )
X = 0
Y = 1
WIDTH = 2
HEIGHT = 3
MAXSTATUSLENGTH = 32
class NCursesUI:
"""
NCurses UI Class
"""
class Window:
"""Base Window Class"""
def __init__( self, x, y, width, height, fg=curses.COLOR_BLACK, bg=curses.COLOR_WHITE ):
self.win = curses.newwin( height, width, y, x )
self.dimensions = ( x, y, width, height )
"""
if curses.has_colors():
color = 1
curses.init_pair( color, fg, bg )
self.win.bkgdset( ord(' '), curses.color_pair(color) )
else:
self.win.bkgdset( ord(' '), curses.A_BOLD )
"""
self.erase()
self.setScrolling()
self.win.noutrefresh()
def erase( self ):
self.win.erase()
def setScrolling( self, b = True ):
self.win.scrollok( b )
self.win.idlok( b )
def setBoxed( self ):
self.boxed = True
self.win.box()
self.win.noutrefresh()
def setText( self, x, y, text, *args ):
self.win.addstr( y, x, text, *args )
self.win.noutrefresh()
def appendText( self, text, *args ):
self.win.addstr( text, *args )
self.win.noutrefresh()
def drawHline( self, y ):
self.win.hline( y, 0, curses.ACS_HLINE, self.dimensions[WIDTH] )
self.win.noutrefresh()
class DecoratedWindow( Window ):
"""Base class for windows with a box and a title bar"""
def __init__( self, title, x, y, width, height, fg=curses.COLOR_BLACK, bg=curses.COLOR_WHITE ):
NCursesUI.Window.__init__( self, x+1, y+3, width-2, height-4, fg, bg )
self.decoration = NCursesUI.Window( x, y, width, height, fg, bg )
self.decoration.setBoxed()
self.decoration.win.hline( 2, 1, curses.ACS_HLINE, width-2 )
self.setTitle( title )
def setTitle( self, title ):
self.decoration.setText( 1, 1, title.center( self.dimensions[WIDTH]-2 ), curses.A_BOLD )
#-------------------------------------------------------------------------#
# class TitleWindow( Window ):
#-------------------------------------------------------------------------#
# """Title Window"""
# def __init__( self, x, y, width, height ):
# NCursesUI.Window.__init__( self, x, y, width, height )
# version = bb.__version__
# title = "BitBake %s" % version
# credit = "(C) 2003-2007 Team BitBake"
# #self.win.hline( 2, 1, curses.ACS_HLINE, width-2 )
# self.win.border()
# self.setText( 1, 1, title.center( self.dimensions[WIDTH]-2 ), curses.A_BOLD )
# self.setText( 1, 2, credit.center( self.dimensions[WIDTH]-2 ), curses.A_BOLD )
#-------------------------------------------------------------------------#
class ThreadActivityWindow( DecoratedWindow ):
#-------------------------------------------------------------------------#
"""Thread Activity Window"""
def __init__( self, x, y, width, height ):
NCursesUI.DecoratedWindow.__init__( self, "Thread Activity", x, y, width, height )
def setStatus( self, thread, text ):
line = "%02d: %s" % ( thread, text )
width = self.dimensions[WIDTH]
if ( len(line) > width ):
line = line[:width-3] + "..."
else:
line = line.ljust( width )
self.setText( 0, thread, line )
#-------------------------------------------------------------------------#
class MainWindow( DecoratedWindow ):
#-------------------------------------------------------------------------#
"""Main Window"""
def __init__( self, x, y, width, height ):
self.StatusPosition = width - MAXSTATUSLENGTH
NCursesUI.DecoratedWindow.__init__( self, None, x, y, width, height )
curses.nl()
def setTitle( self, title ):
title = "BitBake %s" % bb.__version__
self.decoration.setText( 2, 1, title, curses.A_BOLD )
self.decoration.setText( self.StatusPosition - 8, 1, "Status:", curses.A_BOLD )
def setStatus(self, status):
while len(status) < MAXSTATUSLENGTH:
status = status + " "
self.decoration.setText( self.StatusPosition, 1, status, curses.A_BOLD )
#-------------------------------------------------------------------------#
class ShellOutputWindow( DecoratedWindow ):
#-------------------------------------------------------------------------#
"""Interactive Command Line Output"""
def __init__( self, x, y, width, height ):
NCursesUI.DecoratedWindow.__init__( self, "Command Line Window", x, y, width, height )
#-------------------------------------------------------------------------#
class ShellInputWindow( Window ):
#-------------------------------------------------------------------------#
"""Interactive Command Line Input"""
def __init__( self, x, y, width, height ):
NCursesUI.Window.__init__( self, x, y, width, height )
# put that to the top again from curses.textpad import Textbox
# self.textbox = Textbox( self.win )
# t = threading.Thread()
# t.run = self.textbox.edit
# t.start()
#-------------------------------------------------------------------------#
def main(self, stdscr, server, eventHandler, params):
#-------------------------------------------------------------------------#
height, width = stdscr.getmaxyx()
# for now split it like that:
# MAIN_y + THREAD_y = 2/3 screen at the top
# MAIN_x = 2/3 left, THREAD_y = 1/3 right
# CLI_y = 1/3 of screen at the bottom
# CLI_x = full
main_left = 0
main_top = 0
main_height = ( height // 3 * 2 )
main_width = ( width // 3 ) * 2
clo_left = main_left
clo_top = main_top + main_height
clo_height = height - main_height - main_top - 1
clo_width = width
cli_left = main_left
cli_top = clo_top + clo_height
cli_height = 1
cli_width = width
thread_left = main_left + main_width
thread_top = main_top
thread_height = main_height
thread_width = width - main_width
#tw = self.TitleWindow( 0, 0, width, main_top )
mw = self.MainWindow( main_left, main_top, main_width, main_height )
taw = self.ThreadActivityWindow( thread_left, thread_top, thread_width, thread_height )
clo = self.ShellOutputWindow( clo_left, clo_top, clo_width, clo_height )
cli = self.ShellInputWindow( cli_left, cli_top, cli_width, cli_height )
cli.setText( 0, 0, "BB>" )
mw.setStatus("Idle")
helper = uihelper.BBUIHelper()
shutdown = 0
try:
if not params.observe_only:
params.updateToServer(server, os.environ.copy())
params.updateFromServer(server)
cmdline = params.parseActions()
if not cmdline:
print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.")
return 1
if 'msg' in cmdline and cmdline['msg']:
logger.error(cmdline['msg'])
return 1
cmdline = cmdline['action']
ret, error = server.runCommand(cmdline)
if error:
print("Error running command '%s': %s" % (cmdline, error))
return
elif not ret:
print("Couldn't get default commandlind! %s" % ret)
return
except xmlrpc.client.Fault as x:
print("XMLRPC Fault getting commandline:\n %s" % x)
return
exitflag = False
while not exitflag:
try:
event = eventHandler.waitEvent(0.25)
if not event:
continue
helper.eventHandler(event)
if isinstance(event, bb.build.TaskBase):
mw.appendText("NOTE: %s\n" % event._message)
if isinstance(event, logging.LogRecord):
mw.appendText(logging.getLevelName(event.levelno) + ': ' + event.getMessage() + '\n')
if isinstance(event, bb.event.CacheLoadStarted):
self.parse_total = event.total
if isinstance(event, bb.event.CacheLoadProgress):
x = event.current
y = self.parse_total
mw.setStatus("Loading Cache: %s [%2d %%]" % ( next(parsespin), x*100/y ) )
if isinstance(event, bb.event.CacheLoadCompleted):
mw.setStatus("Idle")
mw.appendText("Loaded %d entries from dependency cache.\n"
% ( event.num_entries))
if isinstance(event, bb.event.ParseStarted):
self.parse_total = event.total
if isinstance(event, bb.event.ParseProgress):
x = event.current
y = self.parse_total
mw.setStatus("Parsing Recipes: %s [%2d %%]" % ( next(parsespin), x*100/y ) )
if isinstance(event, bb.event.ParseCompleted):
mw.setStatus("Idle")
mw.appendText("Parsing finished. %d cached, %d parsed, %d skipped, %d masked.\n"
% ( event.cached, event.parsed, event.skipped, event.masked ))
# if isinstance(event, bb.build.TaskFailed):
# if event.logfile:
# if data.getVar("BBINCLUDELOGS", d):
# bb.error("log data follows (%s)" % logfile)
# number_of_lines = data.getVar("BBINCLUDELOGS_LINES", d)
# if number_of_lines:
# subprocess.check_call('tail -n%s %s' % (number_of_lines, logfile), shell=True)
# else:
# f = open(logfile, "r")
# while True:
# l = f.readline()
# if l == '':
# break
# l = l.rstrip()
# print '| %s' % l
# f.close()
# else:
# bb.error("see log in %s" % logfile)
if isinstance(event, bb.command.CommandCompleted):
# stop so the user can see the result of the build, but
# also allow them to now exit with a single ^C
shutdown = 2
if isinstance(event, bb.command.CommandFailed):
mw.appendText(str(event))
time.sleep(2)
exitflag = True
if isinstance(event, bb.command.CommandExit):
exitflag = True
if isinstance(event, bb.cooker.CookerExit):
exitflag = True
if isinstance(event, bb.event.LogExecTTY):
mw.appendText('WARN: ' + event.msg + '\n')
if helper.needUpdate:
activetasks, failedtasks = helper.getTasks()
taw.erase()
taw.setText(0, 0, "")
if activetasks:
taw.appendText("Active Tasks:\n")
for task in activetasks.values():
taw.appendText(task["title"] + '\n')
if failedtasks:
taw.appendText("Failed Tasks:\n")
for task in failedtasks:
taw.appendText(task["title"] + '\n')
curses.doupdate()
except EnvironmentError as ioerror:
# ignore interrupted io
if ioerror.args[0] == 4:
pass
except KeyboardInterrupt:
if shutdown == 2:
mw.appendText("Third Keyboard Interrupt, exit.\n")
exitflag = True
if shutdown == 1:
mw.appendText("Second Keyboard Interrupt, stopping...\n")
_, error = server.runCommand(["stateForceShutdown"])
if error:
print("Unable to cleanly stop: %s" % error)
if shutdown == 0:
mw.appendText("Keyboard Interrupt, closing down...\n")
_, error = server.runCommand(["stateShutdown"])
if error:
print("Unable to cleanly shutdown: %s" % error)
shutdown = shutdown + 1
pass
def main(server, eventHandler, params):
if not os.isatty(sys.stdout.fileno()):
print("FATAL: Unable to run 'ncurses' UI without a TTY.")
return
ui = NCursesUI()
try:
curses.wrapper(ui.main, server, eventHandler, params)
except:
import traceback
traceback.print_exc()

View File

@@ -0,0 +1,341 @@
#
# BitBake Graphical GTK based Dependency Explorer
#
# Copyright (C) 2007 Ross Burton
# Copyright (C) 2007 - 2008 Richard Purdie
#
# SPDX-License-Identifier: GPL-2.0-only
#
import sys
import traceback
try:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GObject
except ValueError:
sys.exit("FATAL: Gtk version needs to be 3.0")
except ImportError:
sys.exit("FATAL: Gtk ui could not load the required gi python module")
import threading
from xmlrpc import client
import bb
import bb.event
# Package Model
(COL_PKG_NAME) = (0)
# Dependency Model
(TYPE_DEP, TYPE_RDEP) = (0, 1)
(COL_DEP_TYPE, COL_DEP_PARENT, COL_DEP_PACKAGE) = (0, 1, 2)
class PackageDepView(Gtk.TreeView):
def __init__(self, model, dep_type, label):
Gtk.TreeView.__init__(self)
self.current = None
self.dep_type = dep_type
self.filter_model = model.filter_new()
self.filter_model.set_visible_func(self._filter, data=None)
self.set_model(self.filter_model)
self.append_column(Gtk.TreeViewColumn(label, Gtk.CellRendererText(), text=COL_DEP_PACKAGE))
def _filter(self, model, iter, data):
this_type = model[iter][COL_DEP_TYPE]
package = model[iter][COL_DEP_PARENT]
if this_type != self.dep_type: return False
return package == self.current
def set_current_package(self, package):
self.current = package
self.filter_model.refilter()
class PackageReverseDepView(Gtk.TreeView):
def __init__(self, model, label):
Gtk.TreeView.__init__(self)
self.current = None
self.filter_model = model.filter_new()
self.filter_model.set_visible_func(self._filter)
# The introspected API was fixed but we can't rely on a pygobject that hides this.
# https://gitlab.gnome.org/GNOME/pygobject/-/commit/9cdbc56fbac4db2de78dc080934b8f0a7efc892a
if hasattr(Gtk.TreeModelSort, "new_with_model"):
self.sort_model = Gtk.TreeModelSort.new_with_model(self.filter_model)
else:
self.sort_model = self.filter_model.sort_new_with_model()
self.sort_model.set_sort_column_id(COL_DEP_PARENT, Gtk.SortType.ASCENDING)
self.set_model(self.sort_model)
self.append_column(Gtk.TreeViewColumn(label, Gtk.CellRendererText(), text=COL_DEP_PARENT))
def _filter(self, model, iter, data):
package = model[iter][COL_DEP_PACKAGE]
return package == self.current
def set_current_package(self, package):
self.current = package
self.filter_model.refilter()
class DepExplorer(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("Task Dependency Explorer")
self.set_default_size(500, 500)
self.connect("delete-event", Gtk.main_quit)
# Create the data models
self.pkg_model = Gtk.ListStore(GObject.TYPE_STRING)
self.pkg_model.set_sort_column_id(COL_PKG_NAME, Gtk.SortType.ASCENDING)
self.depends_model = Gtk.ListStore(GObject.TYPE_INT, GObject.TYPE_STRING, GObject.TYPE_STRING)
self.depends_model.set_sort_column_id(COL_DEP_PACKAGE, Gtk.SortType.ASCENDING)
pane = Gtk.HPaned()
pane.set_position(250)
self.add(pane)
# The master list of packages
scrolled = Gtk.ScrolledWindow()
scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
scrolled.set_shadow_type(Gtk.ShadowType.IN)
self.pkg_treeview = Gtk.TreeView(self.pkg_model)
self.pkg_treeview.get_selection().connect("changed", self.on_cursor_changed)
column = Gtk.TreeViewColumn("Package", Gtk.CellRendererText(), text=COL_PKG_NAME)
self.pkg_treeview.append_column(column)
scrolled.add(self.pkg_treeview)
self.search_entry = Gtk.SearchEntry.new()
self.pkg_treeview.set_search_entry(self.search_entry)
left_panel = Gtk.VPaned()
left_panel.add(self.search_entry)
left_panel.add(scrolled)
pane.add1(left_panel)
box = Gtk.VBox(homogeneous=True, spacing=4)
# Task Depends
scrolled = Gtk.ScrolledWindow()
scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
scrolled.set_shadow_type(Gtk.ShadowType.IN)
self.dep_treeview = PackageDepView(self.depends_model, TYPE_DEP, "Dependencies")
self.dep_treeview.connect("row-activated", self.on_package_activated, COL_DEP_PACKAGE)
scrolled.add(self.dep_treeview)
box.add(scrolled)
pane.add2(box)
# Reverse Task Depends
scrolled = Gtk.ScrolledWindow()
scrolled.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
scrolled.set_shadow_type(Gtk.ShadowType.IN)
self.revdep_treeview = PackageReverseDepView(self.depends_model, "Dependent Tasks")
self.revdep_treeview.connect("row-activated", self.on_package_activated, COL_DEP_PARENT)
scrolled.add(self.revdep_treeview)
box.add(scrolled)
pane.add2(box)
self.show_all()
self.search_entry.grab_focus()
def on_package_activated(self, treeview, path, column, data_col):
model = treeview.get_model()
package = model.get_value(model.get_iter(path), data_col)
pkg_path = []
def finder(model, path, iter, needle):
package = model.get_value(iter, COL_PKG_NAME)
if package == needle:
pkg_path.append(path)
return True
else:
return False
self.pkg_model.foreach(finder, package)
if pkg_path:
self.pkg_treeview.get_selection().select_path(pkg_path[0])
self.pkg_treeview.scroll_to_cell(pkg_path[0])
def on_cursor_changed(self, selection):
(model, it) = selection.get_selected()
if it is None:
current_package = None
else:
current_package = model.get_value(it, COL_PKG_NAME)
self.dep_treeview.set_current_package(current_package)
self.revdep_treeview.set_current_package(current_package)
def parse(self, depgraph):
for task in depgraph["tdepends"]:
self.pkg_model.insert(0, (task,))
for depend in depgraph["tdepends"][task]:
self.depends_model.insert (0, (TYPE_DEP, task, depend))
class gtkthread(threading.Thread):
quit = threading.Event()
def __init__(self, shutdown):
threading.Thread.__init__(self)
self.daemon = True
self.shutdown = shutdown
if not Gtk.init_check()[0]:
sys.stderr.write("Gtk+ init failed. Make sure DISPLAY variable is set.\n")
gtkthread.quit.set()
def run(self):
GObject.threads_init()
Gdk.threads_init()
Gtk.main()
gtkthread.quit.set()
def main(server, eventHandler, params):
shutdown = 0
gtkgui = gtkthread(shutdown)
gtkgui.start()
try:
params.updateToServer(server, os.environ.copy())
params.updateFromServer(server)
cmdline = params.parseActions()
if not cmdline:
print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.")
return 1
if 'msg' in cmdline and cmdline['msg']:
print(cmdline['msg'])
return 1
cmdline = cmdline['action']
if not cmdline or cmdline[0] != "generateDotGraph":
print("This UI requires the -g option")
return 1
ret, error = server.runCommand(["generateDepTreeEvent", cmdline[1], cmdline[2]])
if error:
print("Error running command '%s': %s" % (cmdline, error))
return 1
elif not ret:
print("Error running command '%s': returned %s" % (cmdline, ret))
return 1
except client.Fault as x:
print("XMLRPC Fault getting commandline:\n %s" % x)
return
except Exception as e:
print("Exception in startup:\n %s" % traceback.format_exc())
return
if gtkthread.quit.isSet():
return
Gdk.threads_enter()
dep = DepExplorer()
bardialog = Gtk.Dialog(parent=dep,
flags=Gtk.DialogFlags.MODAL|Gtk.DialogFlags.DESTROY_WITH_PARENT)
bardialog.set_default_size(400, 50)
box = bardialog.get_content_area()
pbar = Gtk.ProgressBar()
box.pack_start(pbar, True, True, 0)
bardialog.show_all()
bardialog.connect("delete-event", Gtk.main_quit)
Gdk.threads_leave()
progress_total = 0
while True:
try:
event = eventHandler.waitEvent(0.25)
if gtkthread.quit.isSet():
_, error = server.runCommand(["stateForceShutdown"])
if error:
print('Unable to cleanly stop: %s' % error)
break
if event is None:
continue
if isinstance(event, bb.event.CacheLoadStarted):
progress_total = event.total
Gdk.threads_enter()
bardialog.set_title("Loading Cache")
pbar.set_fraction(0.0)
Gdk.threads_leave()
if isinstance(event, bb.event.CacheLoadProgress):
x = event.current
Gdk.threads_enter()
pbar.set_fraction(x * 1.0 / progress_total)
Gdk.threads_leave()
continue
if isinstance(event, bb.event.CacheLoadCompleted):
continue
if isinstance(event, bb.event.ParseStarted):
progress_total = event.total
if progress_total == 0:
continue
Gdk.threads_enter()
pbar.set_fraction(0.0)
bardialog.set_title("Processing recipes")
Gdk.threads_leave()
if isinstance(event, bb.event.ParseProgress):
x = event.current
Gdk.threads_enter()
pbar.set_fraction(x * 1.0 / progress_total)
Gdk.threads_leave()
continue
if isinstance(event, bb.event.ParseCompleted):
Gdk.threads_enter()
bardialog.set_title("Generating dependency tree")
Gdk.threads_leave()
continue
if isinstance(event, bb.event.DepTreeGenerated):
Gdk.threads_enter()
bardialog.hide()
dep.parse(event._depgraph)
Gdk.threads_leave()
if isinstance(event, bb.command.CommandCompleted):
continue
if isinstance(event, bb.event.NoProvider):
print(str(event))
_, error = server.runCommand(["stateShutdown"])
if error:
print('Unable to cleanly shutdown: %s' % error)
break
if isinstance(event, bb.command.CommandFailed):
print(str(event))
return event.exitcode
if isinstance(event, bb.command.CommandExit):
return event.exitcode
if isinstance(event, bb.cooker.CookerExit):
break
continue
except EnvironmentError as ioerror:
# ignore interrupted io
if ioerror.args[0] == 4:
pass
except KeyboardInterrupt:
if shutdown == 2:
print("\nThird Keyboard Interrupt, exit.\n")
break
if shutdown == 1:
print("\nSecond Keyboard Interrupt, stopping...\n")
_, error = server.runCommand(["stateForceShutdown"])
if error:
print('Unable to cleanly stop: %s' % error)
if shutdown == 0:
print("\nKeyboard Interrupt, closing down...\n")
_, error = server.runCommand(["stateShutdown"])
if error:
print('Unable to cleanly shutdown: %s' % error)
shutdown = shutdown + 1
pass

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,391 @@
#
# TeamCity UI Implementation
#
# Implements a TeamCity frontend for the BitBake utility, via service messages.
# See https://www.jetbrains.com/help/teamcity/build-script-interaction-with-teamcity.html
#
# Based on ncurses.py and knotty.py, variously by Michael Lauer and Richard Purdie
#
# Copyright (C) 2006 Michael 'Mickey' Lauer
# Copyright (C) 2006-2012 Richard Purdie
# Copyright (C) 2018-2020 Agilent Technologies, Inc.
#
# SPDX-License-Identifier: GPL-2.0-only
#
# Author: Chris Laplante <chris.laplante@agilent.com>
from __future__ import division
import datetime
import logging
import math
import os
import re
import sys
import xmlrpc.client
from collections import deque
import bb
import bb.build
import bb.command
import bb.cooker
import bb.event
import bb.runqueue
from bb.ui import uihelper
logger = logging.getLogger("BitBake")
class TeamCityUI:
def __init__(self):
self._block_stack = []
self._last_progress_state = None
@classmethod
def escape_service_value(cls, value):
"""
Escape a value for inclusion in a service message. TeamCity uses the vertical pipe character for escaping.
See: https://confluence.jetbrains.com/display/TCD10/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-Escapedvalues
"""
return re.sub(r"(['|\[\]])", r"|\1", value).replace("\n", "|n").replace("\r", "|r")
@classmethod
def emit_service_message(cls, message_type, **kwargs):
print(cls.format_service_message(message_type, **kwargs), flush=True)
@classmethod
def format_service_message(cls, message_type, **kwargs):
payload = " ".join(["{0}='{1}'".format(k, cls.escape_service_value(v)) for k, v in kwargs.items()])
return "##teamcity[{0} {1}]".format(message_type, payload)
@classmethod
def emit_simple_service_message(cls, message_type, message):
print(cls.format_simple_service_message(message_type, message), flush=True)
@classmethod
def format_simple_service_message(cls, message_type, message):
return "##teamcity[{0} '{1}']".format(message_type, cls.escape_service_value(message))
@classmethod
def format_build_message(cls, text, status):
return cls.format_service_message("message", text=text, status=status)
def block_start(self, name):
self._block_stack.append(name)
self.emit_service_message("blockOpened", name=name)
def block_end(self):
if self._block_stack:
name = self._block_stack.pop()
self.emit_service_message("blockClosed", name=name)
def progress(self, message, percent, extra=None):
now = datetime.datetime.now()
percent = "{0: >3.0f}".format(percent)
report = False
if not self._last_progress_state \
or (self._last_progress_state[0] == message
and self._last_progress_state[1] != percent
and (now - self._last_progress_state[2]).microseconds >= 5000) \
or self._last_progress_state[0] != message:
report = True
self._last_progress_state = (message, percent, now)
if report or percent in [0, 100]:
self.emit_simple_service_message("progressMessage", "{0}: {1}%{2}".format(message, percent, extra or ""))
class TeamcityLogFormatter(logging.Formatter):
def format(self, record):
details = ""
if hasattr(record, 'bb_exc_formatted'):
details = ''.join(record.bb_exc_formatted)
if record.levelno in [bb.msg.BBLogFormatter.ERROR, bb.msg.BBLogFormatter.CRITICAL]:
# ERROR gets a separate errorDetails field
msg = TeamCityUI.format_service_message("message", text=record.getMessage(), status="ERROR",
errorDetails=details)
else:
payload = record.getMessage()
if details:
payload += "\n" + details
if record.levelno == bb.msg.BBLogFormatter.PLAIN:
msg = payload
elif record.levelno == bb.msg.BBLogFormatter.WARNING:
msg = TeamCityUI.format_service_message("message", text=payload, status="WARNING")
else:
msg = TeamCityUI.format_service_message("message", text=payload, status="NORMAL")
return msg
_evt_list = ["bb.runqueue.runQueueExitWait", "bb.event.LogExecTTY", "logging.LogRecord",
"bb.build.TaskFailed", "bb.build.TaskBase", "bb.event.ParseStarted",
"bb.event.ParseProgress", "bb.event.ParseCompleted", "bb.event.CacheLoadStarted",
"bb.event.CacheLoadProgress", "bb.event.CacheLoadCompleted", "bb.command.CommandFailed",
"bb.command.CommandExit", "bb.command.CommandCompleted", "bb.cooker.CookerExit",
"bb.event.MultipleProviders", "bb.event.NoProvider", "bb.runqueue.sceneQueueTaskStarted",
"bb.runqueue.runQueueTaskStarted", "bb.runqueue.runQueueTaskFailed", "bb.runqueue.sceneQueueTaskFailed",
"bb.event.BuildBase", "bb.build.TaskStarted", "bb.build.TaskSucceeded", "bb.build.TaskFailedSilent",
"bb.build.TaskProgress", "bb.event.ProcessStarted", "bb.event.ProcessProgress", "bb.event.ProcessFinished"]
def _log_settings_from_server(server):
# Get values of variables which control our output
includelogs, error = server.runCommand(["getVariable", "BBINCLUDELOGS"])
if error:
logger.error("Unable to get the value of BBINCLUDELOGS variable: %s" % error)
raise BaseException(error)
loglines, error = server.runCommand(["getVariable", "BBINCLUDELOGS_LINES"])
if error:
logger.error("Unable to get the value of BBINCLUDELOGS_LINES variable: %s" % error)
raise BaseException(error)
return includelogs, loglines
def main(server, eventHandler, params):
params.updateToServer(server, os.environ.copy())
includelogs, loglines = _log_settings_from_server(server)
ui = TeamCityUI()
helper = uihelper.BBUIHelper()
console = logging.StreamHandler(sys.stdout)
errconsole = logging.StreamHandler(sys.stderr)
format = TeamcityLogFormatter()
if params.options.quiet == 0:
forcelevel = None
elif params.options.quiet > 2:
forcelevel = bb.msg.BBLogFormatter.ERROR
else:
forcelevel = bb.msg.BBLogFormatter.WARNING
console.setFormatter(format)
errconsole.setFormatter(format)
if not bb.msg.has_console_handler(logger):
logger.addHandler(console)
logger.addHandler(errconsole)
if params.options.remote_server and params.options.kill_server:
server.terminateServer()
return
if params.observe_only:
logger.error("Observe-only mode not supported in this UI")
return 1
llevel, debug_domains = bb.msg.constructLogOptions()
server.runCommand(["setEventMask", server.getEventHandle(), llevel, debug_domains, _evt_list])
try:
params.updateFromServer(server)
cmdline = params.parseActions()
if not cmdline:
logger.error("No task given")
return 1
if 'msg' in cmdline and cmdline['msg']:
logger.error(cmdline['msg'])
return 1
cmdline = cmdline['action']
ret, error = server.runCommand(cmdline)
if error:
logger.error("{0}: {1}".format(cmdline, error))
return 1
elif not ret:
logger.error("Couldn't get default commandline: {0}".format(re))
return 1
except xmlrpc.client.Fault as x:
logger.error("XMLRPC Fault getting commandline: {0}".format(x))
return 1
active_process_total = None
is_tasks_running = False
while True:
try:
event = eventHandler.waitEvent(0.25)
if not event:
continue
helper.eventHandler(event)
if isinstance(event, bb.build.TaskBase):
logger.info(event._message)
if isinstance(event, logging.LogRecord):
# Don't report sstate failures as errors, since Yocto will just run the tasks for real
if event.msg == "No suitable staging package found" or (event.msg.startswith(
"Fetcher failure: Unable to find file") and "downloadfilename" in event.msg and "sstate" in event.msg):
event.levelno = bb.msg.BBLogFormatter.WARNING
if event.taskpid != 0:
# For "normal" logging conditions, don't show note logs from tasks
# but do show them if the user has changed the default log level to
# include verbose/debug messages
if event.levelno <= bb.msg.BBLogFormatter.NOTE and (event.levelno < llevel or (
event.levelno == bb.msg.BBLogFormatter.NOTE and llevel != bb.msg.BBLogFormatter.VERBOSE)):
continue
# Prefix task messages with recipe/task
if event.taskpid in helper.running_tasks and event.levelno != bb.msg.BBLogFormatter.PLAIN:
taskinfo = helper.running_tasks[event.taskpid]
event.msg = taskinfo['title'] + ': ' + event.msg
if hasattr(event, 'fn'):
event.msg = event.fn + ': ' + event.msg
logger.handle(event)
if isinstance(event, bb.build.TaskFailedSilent):
logger.warning("Logfile for failed setscene task is %s" % event.logfile)
continue
if isinstance(event, bb.build.TaskFailed):
rt = "{0}-{1}:{2}".format(event.pn, event.pv.replace("AUTOINC", "0"), event.task)
logfile = event.logfile
if not logfile or not os.path.exists(logfile):
TeamCityUI.emit_service_message("buildProblem", description="{0}\nUnknown failure (no log file available)".format(rt))
if not event.task.endswith("_setscene"):
server.runCommand(["stateForceShutdown"])
continue
details = deque(maxlen=loglines)
error_lines = []
if includelogs and not event.errprinted:
with open(logfile, "r") as f:
while True:
line = f.readline()
if not line:
break
line = line.rstrip()
details.append(' | %s' % line)
# TODO: a less stupid check for errors
if (event.task == "do_compile") and ("error:" in line):
error_lines.append(line)
if error_lines:
TeamCityUI.emit_service_message("compilationStarted", compiler=rt)
for line in error_lines:
TeamCityUI.emit_service_message("message", text=line, status="ERROR")
TeamCityUI.emit_service_message("compilationFinished", compiler=rt)
else:
TeamCityUI.emit_service_message("buildProblem", description=rt)
err = "Logfile of failure stored in: %s" % logfile
if details:
ui.block_start("{0} task log".format(rt))
# TeamCity seems to choke on service messages longer than about 63800 characters, so if error
# details is longer than, say, 60000, batch it up into several messages.
first_message = True
while details:
detail_len = 0
batch = deque()
while details and detail_len < 60000:
# TODO: This code doesn't bother to handle lines that themselves are extremely long.
line = details.popleft()
batch.append(line)
detail_len += len(line)
if first_message:
batch.appendleft("Log data follows:")
first_message = False
TeamCityUI.emit_service_message("message", text=err, status="ERROR",
errorDetails="\n".join(batch))
else:
TeamCityUI.emit_service_message("message", text="[continued]", status="ERROR",
errorDetails="\n".join(batch))
ui.block_end()
else:
TeamCityUI.emit_service_message("message", text=err, status="ERROR", errorDetails="")
if not event.task.endswith("_setscene"):
server.runCommand(["stateForceShutdown"])
if isinstance(event, bb.event.ProcessStarted):
if event.processname in ["Initialising tasks", "Checking sstate mirror object availability"]:
active_process_total = event.total
ui.block_start(event.processname)
if isinstance(event, bb.event.ProcessFinished):
if event.processname in ["Initialising tasks", "Checking sstate mirror object availability"]:
ui.progress(event.processname, 100)
ui.block_end()
if isinstance(event, bb.event.ProcessProgress):
if event.processname in ["Initialising tasks",
"Checking sstate mirror object availability"] and active_process_total != 0:
ui.progress(event.processname, event.progress * 100 / active_process_total)
if isinstance(event, bb.event.CacheLoadStarted):
ui.block_start("Loading cache")
if isinstance(event, bb.event.CacheLoadProgress):
if event.total != 0:
ui.progress("Loading cache", math.floor(event.current * 100 / event.total))
if isinstance(event, bb.event.CacheLoadCompleted):
ui.progress("Loading cache", 100)
ui.block_end()
if isinstance(event, bb.event.ParseStarted):
ui.block_start("Parsing recipes and checking upstream revisions")
if isinstance(event, bb.event.ParseProgress):
if event.total != 0:
ui.progress("Parsing recipes", math.floor(event.current * 100 / event.total))
if isinstance(event, bb.event.ParseCompleted):
ui.progress("Parsing recipes", 100)
ui.block_end()
if isinstance(event, bb.command.CommandCompleted):
return
if isinstance(event, bb.command.CommandFailed):
logger.error(str(event))
return 1
if isinstance(event, bb.event.MultipleProviders):
logger.warning(str(event))
continue
if isinstance(event, bb.event.NoProvider):
logger.error(str(event))
continue
if isinstance(event, bb.command.CommandExit):
return
if isinstance(event, bb.cooker.CookerExit):
return
if isinstance(event, bb.runqueue.sceneQueueTaskStarted):
if not is_tasks_running:
is_tasks_running = True
ui.block_start("Running tasks")
if event.stats.total != 0:
ui.progress("Running setscene tasks", (
event.stats.completed + event.stats.active + event.stats.failed + 1) * 100 / event.stats.total)
if isinstance(event, bb.runqueue.runQueueTaskStarted):
if not is_tasks_running:
is_tasks_running = True
ui.block_start("Running tasks")
if event.stats.total != 0:
pseudo_total = event.stats.total - event.stats.skipped
pseudo_complete = event.stats.completed + event.stats.active - event.stats.skipped + event.stats.failed + 1
# TODO: sometimes this gives over 100%
ui.progress("Running runqueue tasks", (pseudo_complete) * 100 / pseudo_total,
" ({0}/{1})".format(pseudo_complete, pseudo_total))
if isinstance(event, bb.runqueue.sceneQueueTaskFailed):
logger.warning(str(event))
continue
if isinstance(event, bb.runqueue.runQueueTaskFailed):
logger.error(str(event))
return 1
if isinstance(event, bb.event.LogExecTTY):
pass
except EnvironmentError as ioerror:
# ignore interrupted io
if ioerror.args[0] == 4:
pass
except Exception as ex:
logger.error(str(ex))
# except KeyboardInterrupt:
# if shutdown == 2:
# mw.appendText("Third Keyboard Interrupt, exit.\n")
# exitflag = True
# if shutdown == 1:
# mw.appendText("Second Keyboard Interrupt, stopping...\n")
# _, error = server.runCommand(["stateForceShutdown"])
# if error:
# print("Unable to cleanly stop: %s" % error)
# if shutdown == 0:
# mw.appendText("Keyboard Interrupt, closing down...\n")
# _, error = server.runCommand(["stateShutdown"])
# if error:
# print("Unable to cleanly shutdown: %s" % error)
# shutdown = shutdown + 1
# pass

View File

@@ -0,0 +1,479 @@
#
# BitBake ToasterUI Implementation
# based on (No)TTY UI Implementation by Richard Purdie
#
# Handling output to TTYs or files (no TTY)
#
# Copyright (C) 2006-2012 Richard Purdie
# Copyright (C) 2013 Intel Corporation
#
# SPDX-License-Identifier: GPL-2.0-only
#
from __future__ import division
import time
import sys
try:
import bb
except RuntimeError as exc:
sys.exit(str(exc))
from bb.ui import uihelper
from bb.ui.buildinfohelper import BuildInfoHelper
import bb.msg
import logging
import os
# pylint: disable=invalid-name
# module properties for UI modules are read by bitbake and the contract should not be broken
featureSet = [bb.cooker.CookerFeatures.HOB_EXTRA_CACHES, bb.cooker.CookerFeatures.BASEDATASTORE_TRACKING, bb.cooker.CookerFeatures.SEND_SANITYEVENTS]
logger = logging.getLogger("ToasterLogger")
interactive = sys.stdout.isatty()
def _log_settings_from_server(server):
# Get values of variables which control our output
includelogs, error = server.runCommand(["getVariable", "BBINCLUDELOGS"])
if error:
logger.error("Unable to get the value of BBINCLUDELOGS variable: %s", error)
raise BaseException(error)
loglines, error = server.runCommand(["getVariable", "BBINCLUDELOGS_LINES"])
if error:
logger.error("Unable to get the value of BBINCLUDELOGS_LINES variable: %s", error)
raise BaseException(error)
consolelogfile, error = server.runCommand(["getVariable", "BB_CONSOLELOG"])
if error:
logger.error("Unable to get the value of BB_CONSOLELOG variable: %s", error)
raise BaseException(error)
return consolelogfile
# create a log file for a single build and direct the logger at it;
# log file name is timestamped to the millisecond (depending
# on system clock accuracy) to ensure it doesn't overlap with
# other log file names
#
# returns (log file, path to log file) for a build
def _open_build_log(log_dir):
format_str = "%(levelname)s: %(message)s"
now = time.time()
now_ms = int((now - int(now)) * 1000)
time_str = time.strftime('build_%Y%m%d_%H%M%S', time.localtime(now))
log_file_name = time_str + ('.%d.log' % now_ms)
build_log_file_path = os.path.join(log_dir, log_file_name)
build_log = logging.FileHandler(build_log_file_path)
logformat = bb.msg.BBLogFormatter(format_str)
build_log.setFormatter(logformat)
bb.msg.addDefaultlogFilter(build_log)
logger.addHandler(build_log)
return (build_log, build_log_file_path)
# stop logging to the build log if it exists
def _close_build_log(build_log):
if build_log:
build_log.flush()
build_log.close()
logger.removeHandler(build_log)
_evt_list = [
"bb.build.TaskBase",
"bb.build.TaskFailed",
"bb.build.TaskFailedSilent",
"bb.build.TaskStarted",
"bb.build.TaskSucceeded",
"bb.command.CommandCompleted",
"bb.command.CommandExit",
"bb.command.CommandFailed",
"bb.cooker.CookerExit",
"bb.event.BuildInit",
"bb.event.BuildCompleted",
"bb.event.BuildStarted",
"bb.event.CacheLoadCompleted",
"bb.event.CacheLoadProgress",
"bb.event.CacheLoadStarted",
"bb.event.ConfigParsed",
"bb.event.DepTreeGenerated",
"bb.event.LogExecTTY",
"bb.event.MetadataEvent",
"bb.event.MultipleProviders",
"bb.event.NoProvider",
"bb.event.ParseCompleted",
"bb.event.ParseProgress",
"bb.event.ParseStarted",
"bb.event.RecipeParsed",
"bb.event.SanityCheck",
"bb.event.SanityCheckPassed",
"bb.event.TreeDataPreparationCompleted",
"bb.event.TreeDataPreparationStarted",
"bb.runqueue.runQueueTaskCompleted",
"bb.runqueue.runQueueTaskFailed",
"bb.runqueue.runQueueTaskSkipped",
"bb.runqueue.runQueueTaskStarted",
"bb.runqueue.sceneQueueTaskCompleted",
"bb.runqueue.sceneQueueTaskFailed",
"bb.runqueue.sceneQueueTaskStarted",
"logging.LogRecord"]
def main(server, eventHandler, params):
# set to a logging.FileHandler instance when a build starts;
# see _open_build_log()
build_log = None
# set to the log path when a build starts
build_log_file_path = None
helper = uihelper.BBUIHelper()
if not params.observe_only:
params.updateToServer(server, os.environ.copy())
params.updateFromServer(server)
# TODO don't use log output to determine when bitbake has started
#
# WARNING: this log handler cannot be removed, as localhostbecontroller
# relies on output in the toaster_ui.log file to determine whether
# the bitbake server has started, which only happens if
# this logger is setup here (see the TODO in the loop below)
console = logging.StreamHandler(sys.stdout)
format_str = "%(levelname)s: %(message)s"
formatter = bb.msg.BBLogFormatter(format_str)
bb.msg.addDefaultlogFilter(console)
console.setFormatter(formatter)
logger.addHandler(console)
logger.setLevel(logging.INFO)
llevel, debug_domains = bb.msg.constructLogOptions()
result, error = server.runCommand(["setEventMask", server.getEventHandle(), llevel, debug_domains, _evt_list])
if not result or error:
logger.error("can't set event mask: %s", error)
return 1
# verify and warn
build_history_enabled = True
inheritlist, _ = server.runCommand(["getVariable", "INHERIT"])
if not "buildhistory" in inheritlist.split(" "):
logger.warning("buildhistory is not enabled. Please enable INHERIT += \"buildhistory\" to see image details.")
build_history_enabled = False
if not "buildstats" in inheritlist.split(" "):
logger.warning("buildstats is not enabled. Please enable INHERIT += \"buildstats\" to generate build statistics.")
if not params.observe_only:
cmdline = params.parseActions()
if not cmdline:
print("Nothing to do. Use 'bitbake world' to build everything, or run 'bitbake --help' for usage information.")
return 1
if 'msg' in cmdline and cmdline['msg']:
logger.error(cmdline['msg'])
return 1
ret, error = server.runCommand(cmdline['action'])
if error:
logger.error("Command '%s' failed: %s" % (cmdline, error))
return 1
elif not ret:
logger.error("Command '%s' failed: returned %s" % (cmdline, ret))
return 1
# set to 1 when toasterui needs to shut down
main.shutdown = 0
interrupted = False
return_value = 0
errors = 0
warnings = 0
taskfailures = []
first = True
buildinfohelper = BuildInfoHelper(server, build_history_enabled,
os.getenv('TOASTER_BRBE'))
# write our own log files into bitbake's log directory;
# we're only interested in the path to the parent directory of
# this file, as we're writing our own logs into the same directory
consolelogfile = _log_settings_from_server(server)
log_dir = os.path.dirname(consolelogfile)
bb.utils.mkdirhier(log_dir)
while True:
try:
event = eventHandler.waitEvent(0.25)
if first:
first = False
# TODO don't use log output to determine when bitbake has started
#
# this is the line localhostbecontroller needs to
# see in toaster_ui.log which it uses to decide whether
# the bitbake server has started...
logger.info("ToasterUI waiting for events")
if event is None:
if main.shutdown > 0:
# if shutting down, close any open build log first
_close_build_log(build_log)
break
continue
helper.eventHandler(event)
# pylint: disable=protected-access
# the code will look into the protected variables of the event; no easy way around this
if isinstance(event, bb.event.HeartbeatEvent):
continue
if isinstance(event, bb.event.ParseStarted):
if not (build_log and build_log_file_path):
build_log, build_log_file_path = _open_build_log(log_dir)
buildinfohelper.store_started_build()
buildinfohelper.save_build_log_file_path(build_log_file_path)
buildinfohelper.set_recipes_to_parse(event.total)
continue
# create a build object in buildinfohelper from either BuildInit
# (if available) or BuildStarted (for jethro and previous versions)
if isinstance(event, (bb.event.BuildStarted, bb.event.BuildInit)):
if not (build_log and build_log_file_path):
build_log, build_log_file_path = _open_build_log(log_dir)
buildinfohelper.save_build_targets(event)
buildinfohelper.save_build_log_file_path(build_log_file_path)
# get additional data from BuildStarted
if isinstance(event, bb.event.BuildStarted):
buildinfohelper.save_build_layers_and_variables()
continue
if isinstance(event, bb.event.ParseProgress):
buildinfohelper.set_recipes_parsed(event.current)
continue
if isinstance(event, bb.event.ParseCompleted):
buildinfohelper.set_recipes_parsed(event.total)
continue
if isinstance(event, (bb.build.TaskStarted, bb.build.TaskSucceeded, bb.build.TaskFailedSilent)):
buildinfohelper.update_and_store_task(event)
logger.info("Logfile for task %s", event.logfile)
continue
if isinstance(event, bb.build.TaskBase):
logger.info(event._message)
if isinstance(event, bb.event.LogExecTTY):
logger.info(event.msg)
continue
if isinstance(event, logging.LogRecord):
if event.levelno == -1:
event.levelno = formatter.ERROR
buildinfohelper.store_log_event(event)
if event.levelno >= formatter.ERROR:
errors = errors + 1
elif event.levelno == formatter.WARNING:
warnings = warnings + 1
# For "normal" logging conditions, don't show note logs from tasks
# but do show them if the user has changed the default log level to
# include verbose/debug messages
if event.taskpid != 0 and event.levelno <= formatter.NOTE:
continue
logger.handle(event)
continue
if isinstance(event, bb.build.TaskFailed):
buildinfohelper.update_and_store_task(event)
logfile = event.logfile
if logfile and os.path.exists(logfile):
bb.error("Logfile of failure stored in: %s" % logfile)
continue
# these events are unprocessed now, but may be used in the future to log
# timing and error informations from the parsing phase in Toaster
if isinstance(event, (bb.event.SanityCheckPassed, bb.event.SanityCheck)):
continue
if isinstance(event, bb.event.CacheLoadStarted):
continue
if isinstance(event, bb.event.CacheLoadProgress):
continue
if isinstance(event, bb.event.CacheLoadCompleted):
continue
if isinstance(event, bb.event.MultipleProviders):
logger.info(str(event))
continue
if isinstance(event, bb.event.NoProvider):
errors = errors + 1
text = str(event)
logger.error(text)
buildinfohelper.store_log_error(text)
continue
if isinstance(event, bb.event.ConfigParsed):
continue
if isinstance(event, bb.event.RecipeParsed):
continue
# end of saved events
if isinstance(event, (bb.runqueue.sceneQueueTaskStarted, bb.runqueue.runQueueTaskStarted, bb.runqueue.runQueueTaskSkipped)):
buildinfohelper.store_started_task(event)
continue
if isinstance(event, bb.runqueue.runQueueTaskCompleted):
buildinfohelper.update_and_store_task(event)
continue
if isinstance(event, bb.runqueue.runQueueTaskFailed):
buildinfohelper.update_and_store_task(event)
taskfailures.append(event.taskstring)
logger.error(str(event))
continue
if isinstance(event, (bb.runqueue.sceneQueueTaskCompleted, bb.runqueue.sceneQueueTaskFailed)):
buildinfohelper.update_and_store_task(event)
continue
if isinstance(event, (bb.event.TreeDataPreparationStarted, bb.event.TreeDataPreparationCompleted)):
continue
if isinstance(event, (bb.event.BuildCompleted, bb.command.CommandFailed)):
errorcode = 0
if isinstance(event, bb.command.CommandFailed):
errors += 1
errorcode = 1
logger.error(str(event))
elif isinstance(event, bb.event.BuildCompleted):
buildinfohelper.scan_image_artifacts()
buildinfohelper.clone_required_sdk_artifacts()
# turn off logging to the current build log
_close_build_log(build_log)
# reset ready for next BuildStarted
build_log = None
# update the build info helper on BuildCompleted, not on CommandXXX
buildinfohelper.update_build_information(event, errors, warnings, taskfailures)
brbe = buildinfohelper.brbe
buildinfohelper.close(errorcode)
# we start a new build info
if params.observe_only:
logger.debug("ToasterUI prepared for new build")
errors = 0
warnings = 0
taskfailures = []
buildinfohelper = BuildInfoHelper(server, build_history_enabled)
else:
main.shutdown = 1
logger.info("ToasterUI build done, brbe: %s", brbe)
break
if isinstance(event, (bb.command.CommandCompleted,
bb.command.CommandFailed,
bb.command.CommandExit)):
if params.observe_only:
errorcode = 0
else:
main.shutdown = 1
continue
if isinstance(event, bb.event.MetadataEvent):
if event.type == "SinglePackageInfo":
buildinfohelper.store_build_package_information(event)
elif event.type == "LayerInfo":
buildinfohelper.store_layer_info(event)
elif event.type == "BuildStatsList":
buildinfohelper.store_tasks_stats(event)
elif event.type == "ImagePkgList":
buildinfohelper.store_target_package_data(event)
elif event.type == "MissedSstate":
buildinfohelper.store_missed_state_tasks(event)
elif event.type == "SDKArtifactInfo":
buildinfohelper.scan_sdk_artifacts(event)
elif event.type == "SetBRBE":
buildinfohelper.brbe = buildinfohelper._get_data_from_event(event)
elif event.type == "TaskArtifacts":
buildinfohelper.scan_task_artifacts(event)
elif event.type == "OSErrorException":
logger.error(event)
else:
logger.error("Unprocessed MetadataEvent %s", event.type)
continue
if isinstance(event, bb.cooker.CookerExit):
# shutdown when bitbake server shuts down
main.shutdown = 1
continue
if isinstance(event, bb.event.DepTreeGenerated):
buildinfohelper.store_dependency_information(event)
continue
logger.warning("Unknown event: %s", event)
return_value += 1
except EnvironmentError as ioerror:
logger.warning("EnvironmentError: %s" % ioerror)
# ignore interrupted io system calls
if ioerror.args[0] == 4: # errno 4 is EINTR
logger.warning("Skipped EINTR: %s" % ioerror)
else:
raise
except KeyboardInterrupt:
if params.observe_only:
print("\nKeyboard Interrupt, exiting observer...")
main.shutdown = 2
if not params.observe_only and main.shutdown == 1:
print("\nSecond Keyboard Interrupt, stopping...\n")
_, error = server.runCommand(["stateForceShutdown"])
if error:
logger.error("Unable to cleanly stop: %s" % error)
if not params.observe_only and main.shutdown == 0:
print("\nKeyboard Interrupt, closing down...\n")
interrupted = True
_, error = server.runCommand(["stateShutdown"])
if error:
logger.error("Unable to cleanly shutdown: %s" % error)
buildinfohelper.cancel_cli_build()
main.shutdown = main.shutdown + 1
except Exception as e:
# print errors to log
import traceback
from pprint import pformat
exception_data = traceback.format_exc()
logger.error("%s\n%s" , e, exception_data)
# save them to database, if possible; if it fails, we already logged to console.
try:
buildinfohelper.store_log_exception("%s\n%s" % (str(e), exception_data))
except Exception as ce:
logger.error("CRITICAL - Failed to to save toaster exception to the database: %s", str(ce))
# make sure we return with an error
return_value += 1
if interrupted and return_value == 0:
return_value += 1
logger.warning("Return value is %d", return_value)
return return_value

View File

@@ -0,0 +1,144 @@
#
# Copyright (C) 2006 - 2007 Michael 'Mickey' Lauer
# Copyright (C) 2006 - 2007 Richard Purdie
#
# SPDX-License-Identifier: GPL-2.0-only
#
"""
Use this class to fork off a thread to recieve event callbacks from the bitbake
server and queue them for the UI to process. This process must be used to avoid
client/server deadlocks.
"""
import collections, logging, pickle, socket, threading
from xmlrpc.server import SimpleXMLRPCServer, SimpleXMLRPCRequestHandler
import bb
logger = logging.getLogger(__name__)
class BBUIEventQueue:
def __init__(self, BBServer, clientinfo=("localhost, 0")):
self.eventQueue = []
self.eventQueueLock = threading.Lock()
self.eventQueueNotify = threading.Event()
self.BBServer = BBServer
self.clientinfo = clientinfo
server = UIXMLRPCServer(self.clientinfo)
self.host, self.port = server.socket.getsockname()
server.register_function( self.system_quit, "event.quit" )
server.register_function( self.send_event, "event.sendpickle" )
server.socket.settimeout(1)
self.EventHandle = None
# the event handler registration may fail here due to cooker being in invalid state
# this is a transient situation, and we should retry a couple of times before
# giving up
for count_tries in range(5):
ret = self.BBServer.registerEventHandler(self.host, self.port)
if isinstance(ret, collections.abc.Iterable):
self.EventHandle, error = ret
else:
self.EventHandle = ret
error = ""
if self.EventHandle is not None:
break
errmsg = "Could not register UI event handler. Error: %s, host %s, "\
"port %d" % (error, self.host, self.port)
bb.warn("%s, retry" % errmsg)
import time
time.sleep(1)
else:
raise Exception(errmsg)
self.server = server
self.t = threading.Thread()
self.t.daemon = True
self.t.run = self.startCallbackHandler
self.t.start()
def getEvent(self):
with bb.utils.lock_timeout(self.eventQueueLock):
if not self.eventQueue:
return None
item = self.eventQueue.pop(0)
if not self.eventQueue:
self.eventQueueNotify.clear()
return item
def waitEvent(self, delay):
self.eventQueueNotify.wait(delay)
return self.getEvent()
def queue_event(self, event):
with bb.utils.lock_timeout(self.eventQueueLock):
self.eventQueue.append(event)
self.eventQueueNotify.set()
def send_event(self, event):
self.queue_event(pickle.loads(event))
def startCallbackHandler(self):
self.server.timeout = 1
bb.utils.set_process_name("UIEventQueue")
while not self.server.quit:
try:
self.server.handle_request()
except Exception as e:
import traceback
logger.error("BBUIEventQueue.startCallbackHandler: Exception while trying to handle request: %s\n%s" % (e, traceback.format_exc()))
self.server.server_close()
def system_quit( self ):
"""
Shut down the callback thread
"""
try:
self.BBServer.unregisterEventHandler(self.EventHandle)
except:
pass
self.server.quit = True
class UIXMLRPCServer (SimpleXMLRPCServer):
def __init__( self, interface ):
self.quit = False
SimpleXMLRPCServer.__init__( self,
interface,
requestHandler=SimpleXMLRPCRequestHandler,
logRequests=False, allow_none=True, use_builtin_types=True)
def get_request(self):
while not self.quit:
try:
sock, addr = self.socket.accept()
sock.settimeout(1)
return (sock, addr)
except socket.timeout:
pass
return (None, None)
def close_request(self, request):
if request is None:
return
SimpleXMLRPCServer.close_request(self, request)
def process_request(self, request, client_address):
if request is None:
return
SimpleXMLRPCServer.process_request(self, request, client_address)

View File

@@ -0,0 +1,69 @@
#
# Copyright (C) 2006 - 2007 Michael 'Mickey' Lauer
# Copyright (C) 2006 - 2007 Richard Purdie
#
# SPDX-License-Identifier: GPL-2.0-only
#
import bb.build
import time
class BBUIHelper:
def __init__(self):
self.needUpdate = False
self.running_tasks = {}
# Running PIDs preserves the order tasks were executed in
self.running_pids = []
self.failed_tasks = []
self.pidmap = {}
self.tasknumber_current = 0
self.tasknumber_total = 0
def eventHandler(self, event):
# PIDs are a bad idea as they can be reused before we process all UI events.
# We maintain a 'fuzzy' match for TaskProgress since there is no other way to match
def removetid(pid, tid):
self.running_pids.remove(tid)
del self.running_tasks[tid]
if self.pidmap[pid] == tid:
del self.pidmap[pid]
self.needUpdate = True
if isinstance(event, bb.build.TaskStarted):
tid = event._fn + ":" + event._task
if event._mc != "default":
self.running_tasks[tid] = { 'title' : "mc:%s:%s %s" % (event._mc, event._package, event._task), 'starttime' : time.time(), 'pid' : event.pid }
else:
self.running_tasks[tid] = { 'title' : "%s %s" % (event._package, event._task), 'starttime' : time.time(), 'pid' : event.pid }
self.running_pids.append(tid)
self.pidmap[event.pid] = tid
self.needUpdate = True
elif isinstance(event, bb.build.TaskSucceeded):
tid = event._fn + ":" + event._task
removetid(event.pid, tid)
elif isinstance(event, bb.build.TaskFailedSilent):
tid = event._fn + ":" + event._task
removetid(event.pid, tid)
# Don't add to the failed tasks list since this is e.g. a setscene task failure
elif isinstance(event, bb.build.TaskFailed):
tid = event._fn + ":" + event._task
removetid(event.pid, tid)
self.failed_tasks.append( { 'title' : "%s %s" % (event._package, event._task)})
elif isinstance(event, bb.runqueue.runQueueTaskStarted) or isinstance(event, bb.runqueue.sceneQueueTaskStarted):
self.tasknumber_current = event.stats.completed + event.stats.active + event.stats.failed
self.tasknumber_total = event.stats.total
self.setscene_current = event.stats.setscene_active + event.stats.setscene_covered + event.stats.setscene_notcovered
self.setscene_total = event.stats.setscene_total
self.needUpdate = True
elif isinstance(event, bb.build.TaskProgress):
if event.pid > 0 and event.pid in self.pidmap:
self.running_tasks[self.pidmap[event.pid]]['progress'] = event.progress
self.running_tasks[self.pidmap[event.pid]]['rate'] = event.rate
self.needUpdate = True
else:
return False
return True
def getTasks(self):
self.needUpdate = False
return (self.running_tasks, self.failed_tasks)