buildroot: log bubblewrap's output

In case that bubblewrap fails to, e.g. because it fails to execute
the runner, it will print an error message to stderr. Currently,
this output is not capture and thus not logged. To fix that, the
`BuildRoot.run` method now takes a monitor object and will stream
stdout/stderr to the log via the monitor.
This commit is contained in:
Christian Kellner 2020-08-26 15:01:54 +02:00 committed by David Rheinsberg
parent 3bf5d26c7a
commit 96a5499ed9
3 changed files with 28 additions and 10 deletions

View file

@ -110,7 +110,7 @@ class BuildRoot(contextlib.AbstractContextManager):
if self._exitstack:
self._exitstack.enter_context(api)
def run(self, argv, binds=None, readonly_binds=None):
def run(self, argv, monitor, binds=None, readonly_binds=None):
"""Runs a command in the buildroot.
Takes the command and arguments, as well as bind mounts to mirror
@ -194,6 +194,22 @@ class BuildRoot(contextlib.AbstractContextManager):
cmd += ["--", f"/run/osbuild/lib/runners/{self._runner}"]
cmd += argv
return subprocess.run(cmd,
check=False,
stdin=subprocess.DEVNULL)
proc = subprocess.Popen(cmd,
bufsize=0,
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding="utf-8",
close_fds=True)
while True:
txt = proc.stdout.read(4096)
if not txt:
break
monitor.log(txt)
txt, _ = proc.communicate()
monitor.log(txt)
return proc

View file

@ -88,6 +88,7 @@ class Stage:
build_root.register_api(src)
r = build_root.run([f"/run/osbuild/lib/stages/{self.name}"],
monitor,
binds=[os.fspath(tree) + ":/run/osbuild/tree"],
readonly_binds=ro_binds)
@ -146,6 +147,7 @@ class Assembler:
build_root.register_api(rls)
r = build_root.run([f"/run/osbuild/lib/assemblers/{self.name}"],
monitor,
binds=binds,
readonly_binds=ro_binds)