From 11fa2bc851ed07282134258ea58843a8fd63f8fb Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Fri, 6 Jul 2012 10:56:17 +0000 Subject: ChunkBuilder: write output of build to cache --- morphlib/builder2.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'morphlib') diff --git a/morphlib/builder2.py b/morphlib/builder2.py index 301890b2..1feb3669 100644 --- a/morphlib/builder2.py +++ b/morphlib/builder2.py @@ -250,7 +250,10 @@ class ChunkBuilder(BuilderBase): builddir = self.staging_area.builddir(self.artifact.source) self.get_sources(builddir) destdir = self.staging_area.destdir(self.artifact.source) - self.run_commands(builddir, destdir) + with self.local_artifact_cache.put_source_metadata( + self.artifact.source, self.artifact.cache_key, + 'build-log') as log: + self.run_commands(builddir, destdir, log) except: self.do_unmounts(mounted) raise @@ -335,7 +338,7 @@ class ChunkBuilder(BuilderBase): os.utime(pathname, (now, now)) os.utime(dirname, (now, now)) - def run_commands(self, builddir, destdir): # pragma: no cover + def run_commands(self, builddir, destdir, logfile): # pragma: no cover m = self.artifact.source.morphology bs = morphlib.buildsystem.lookup_build_system(m['build-system']) @@ -361,7 +364,10 @@ class ChunkBuilder(BuilderBase): self.build_env.env['MAKEFLAGS'] = '-j%s' % max_jobs else: self.build_env.env['MAKEFLAGS'] = '-j1' - self.runcmd(['sh', '-c', cmd], cwd=relative_builddir) + self.runcmd(['sh', '-c', cmd], + cwd=relative_builddir, + stdout=logfile, + stderr=logfile) def assemble_chunk_artifacts(self, destdir): # pragma: no cover built_artifacts = [] -- cgit v1.2.1 From eb7609d885733e857480a311fa9bce2ebaa7d92f Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Fri, 6 Jul 2012 12:43:35 +0000 Subject: ChunkBuilder: dump build log on error --- morphlib/builder2.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'morphlib') diff --git a/morphlib/builder2.py b/morphlib/builder2.py index 1feb3669..b9679d99 100644 --- a/morphlib/builder2.py +++ b/morphlib/builder2.py @@ -23,6 +23,8 @@ from collections import defaultdict import tarfile import traceback +import cliapp + import morphlib from morphlib.artifactcachereference import ArtifactCacheReference @@ -356,6 +358,7 @@ class ChunkBuilder(BuilderBase): cmds = self.get_commands(key, m, bs) if cmds: self.app.status(msg='Running %(key)s', key=key) + logfile.write('# %s\n' % step) for cmd in cmds: if in_parallel: max_jobs = self.artifact.source.morphology['max-jobs'] @@ -364,10 +367,23 @@ class ChunkBuilder(BuilderBase): self.build_env.env['MAKEFLAGS'] = '-j%s' % max_jobs else: self.build_env.env['MAKEFLAGS'] = '-j1' - self.runcmd(['sh', '-c', cmd], - cwd=relative_builddir, - stdout=logfile, - stderr=logfile) + try: + # flushing is needed because writes from python and + # writes from being the output in Popen have different + # buffers, but flush handles both + logfile.write('# # %s\n' % cmd) + logfile.flush() + self.runcmd(['sh', '-c', cmd], + cwd=relative_builddir, + stdout=logfile, + stderr=logfile) + logfile.flush() + except cliapp.AppException, e: + logfile.flush() + with open(logfile.name, 'r') as readlog: + self.app.output.write("%s failed\n" % step) + shutil.copyfileobj(readlog, self.app.output) + raise e def assemble_chunk_artifacts(self, destdir): # pragma: no cover built_artifacts = [] -- cgit v1.2.1 From 6cf82f80411ac0b6f1961e1739a31e31aa9b0382 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Fri, 6 Jul 2012 14:18:07 +0000 Subject: ChunkBuilder: runcmd, redirect err to out Data buffers can get confused if two file handles are writing to the same file, python's subprocess module has subprocess.STDOUT for this. --- morphlib/builder2.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'morphlib') diff --git a/morphlib/builder2.py b/morphlib/builder2.py index b9679d99..41583149 100644 --- a/morphlib/builder2.py +++ b/morphlib/builder2.py @@ -22,6 +22,7 @@ import time from collections import defaultdict import tarfile import traceback +import subprocess import cliapp @@ -376,7 +377,7 @@ class ChunkBuilder(BuilderBase): self.runcmd(['sh', '-c', cmd], cwd=relative_builddir, stdout=logfile, - stderr=logfile) + stderr=subprocess.STDOUT) logfile.flush() except cliapp.AppException, e: logfile.flush() -- cgit v1.2.1