summaryrefslogtreecommitdiff
path: root/morphlib
diff options
context:
space:
mode:
authorLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-07-06 15:40:22 +0100
committerLars Wirzenius <lars.wirzenius@codethink.co.uk>2012-07-06 15:40:22 +0100
commitbc0ba7cd2898b4d805525824bba55fba795379d6 (patch)
tree93075b840aead8f83ae011dda4e7ea9e6a45cbc0 /morphlib
parentad6cae07ae5320abd44b35e06a9a241c273bafe4 (diff)
parent6cf82f80411ac0b6f1961e1739a31e31aa9b0382 (diff)
downloadmorph-bc0ba7cd2898b4d805525824bba55fba795379d6.tar.gz
Merge remote branch 'origin/baserock/feature/S2995-write-build-logs-to-cache'
Diffstat (limited to 'morphlib')
-rw-r--r--morphlib/builder2.py29
1 files changed, 26 insertions, 3 deletions
diff --git a/morphlib/builder2.py b/morphlib/builder2.py
index 301890b2..41583149 100644
--- a/morphlib/builder2.py
+++ b/morphlib/builder2.py
@@ -22,6 +22,9 @@ import time
from collections import defaultdict
import tarfile
import traceback
+import subprocess
+
+import cliapp
import morphlib
from morphlib.artifactcachereference import ArtifactCacheReference
@@ -250,7 +253,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 +341,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'])
@@ -353,6 +359,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']
@@ -361,7 +368,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)
+ 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=subprocess.STDOUT)
+ 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 = []