BitBake side of shell message function support
cover BitBake side of shell message function support
I'm finally sending out the patches to support the output of bbwarn, bberror etc. output actually going to the console. This is the BitBake side of the changes to implement it.
The following changes since commit fbb9c6f5538084e125b58118a86968908e6f895b:
fetch2: Add fetch parameter to checkstatus (2015-07-09 17:59:29 +0100)
are available in the git repository at:
git://git.yoctoproject.org/poky-contrib paule/bb-shell-logging
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=paule/bb-shell-logging
Paul Eggleton (1):
lib/bb: set up infrastructure for shell message functions
lib/bb/build.py | 50 +++++++++++++++++++++++++++++++++++++++++++------- lib/bb/process.py | 25 ++++++++++++++++++++++--- 2 files changed, 65 insertions(+), 10 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/1 lib/bb: set up infrastructure for shell message functions
Create a fifo under ${T} for each running task that can be used by the task to send events back to BitBake. The purpose of this is to allow OpenEmbedded's logging.bbclass (which provides shell function equivalents for bb.warn(), bb.note() etc.) to have those functions trigger the appropriate events within BitBake so that messages are shown through the BitBake UI rather than just in the task log; to do that we just call the python functions.
Part of the fix for [YOCTO #5275].
--- lib/bb/build.py | 50 +++++++++++++++++++++++++++++++++++++++++++------- lib/bb/process.py | 25 ++++++++++++++++++++++--- 2 files changed, 65 insertions(+), 10 deletions(-)
lib/bb/build.py +43 -7
@@ -329,14 +329,50 @@ exit $? else: logfile = sys.stdout - bb.debug(2, "Executing shell function %s" % func) + def readfifo(data): + lines = data.split('\0') + for line in lines: + splitval = line.split(' ', 1) + cmd = splitval[0] + if len(splitval) > 1: + value = splitval[1] + else: + value = '' + if cmd == 'bbplain': + bb.plain(value) + elif cmd == 'bbnote': + bb.note(value) + elif cmd == 'bbwarn': + bb.warn(value) + elif cmd == 'bberror': + bb.error(value) + elif cmd == 'bbfatal': + # The caller will call exit themselves, so bb.error() is + # what we want here rather than bb.fatal() + bb.error(value) + elif cmd == 'bbdebug': + splitval = value.split(' ', 1) + level = int(splitval[0]) + value = splitval[1] + bb.debug(level, value) - try: - with open(os.devnull, 'r+') as stdin: - bb.process.run(cmd, shell=False, stdin=stdin, log=logfile) - except bb.process.CmdError: - logfn = d.getVar('BB_LOGFILE', True) - raise FuncFailed(func, logfn) + tempdir = d.getVar('T', True) + fifopath = os.path.join(tempdir, 'fifo.%s' % os.getpid()) + if os.path.exists(fifopath): + os.unlink(fifopath) + os.mkfifo(fifopath) + with open(fifopath, 'r+') as fifo: + try: + bb.debug(2, "Executing shell function %s" % func) + + try: + with open(os.devnull, 'r+') as stdin: + bb.process.run(cmd, shell=False, stdin=stdin, log=logfile, extrafiles=[(fifo,readfifo)]) + except bb.process.CmdError: + logfn = d.getVar('BB_LOGFILE', True) + raise FuncFailed(func, logfn) + finally: + os.unlink(fifopath) bb.debug(2, "Shell function %s finished" % func)
lib/bb/process.py +22 -3
@@ -64,7 +64,7 @@ class Popen(subprocess.Popen): options.update(kwargs) subprocess.Popen.__init__(self, *args, **options) -def _logged_communicate(pipe, log, input): +def _logged_communicate(pipe, log, input, extrafiles): if pipe.stdin: if input is not None: pipe.stdin.write(input)
@@ -79,6 +79,19 @@ def _logged_communicate(pipe, log, input): if pipe.stderr is not None: bb.utils.nonblockingfd(pipe.stderr.fileno()) rin.append(pipe.stderr) + for fobj, _ in extrafiles: + bb.utils.nonblockingfd(fobj.fileno()) + rin.append(fobj) + + def readextras(): + for fobj, func in extrafiles: + try: + data = fobj.read() + except IOError as err: + if err.errno == errno.EAGAIN or err.errno == errno.EWOULDBLOCK: + data = None + if data is not None: + func(data) try: while pipe.poll() is None:
@@ -100,15 +113,21 @@ def _logged_communicate(pipe, log, input): if data is not None: errdata.append(data) log.write(data) + + readextras() + finally: log.flush() + + readextras() + if pipe.stdout is not None: pipe.stdout.close() if pipe.stderr is not None: pipe.stderr.close() return ''.join(outdata), ''.join(errdata) -def run(cmd, input=None, log=None, **options): +def run(cmd, input=None, log=None, extrafiles=[], **options): """Convenience function to run a command and return its output, raising an exception when the command fails"""
@@ -124,7 +143,7 @@ def run(cmd, input=None, log=None, **options): raise CmdError(cmd, exc) if log: - stdout, stderr = _logged_communicate(pipe, log, input) + stdout, stderr = _logged_communicate(pipe, log, input, extrafiles) else: stdout, stderr = pipe.communicate(input)
Signature · 1 line
2.1.0