diff options
author | Tiago Gomes <tiago.gomes@codethink.co.uk> | 2015-08-13 15:07:50 +0000 |
---|---|---|
committer | Tiago Gomes <tiago.gomes@codethink.co.uk> | 2015-09-01 15:19:06 +0000 |
commit | f68a622ea0ab438f699fcd5e29f6c4167c59029e (patch) | |
tree | 96b5141c4783bce51c3ce2901dbebc7fa5383e69 /morphlib/builder.py | |
parent | 29d6b3d36e40317ab72bd543b7d644161906b723 (diff) | |
download | morph-f68a622ea0ab438f699fcd5e29f6c4167c59029e.tar.gz |
Improve build loggingtiagogomes/improve-debugging
Change-Id: If9a6b17797166c295f3c597cc6d17226d45957e7
Diffstat (limited to 'morphlib/builder.py')
-rw-r--r-- | morphlib/builder.py | 45 |
1 files changed, 14 insertions, 31 deletions
diff --git a/morphlib/builder.py b/morphlib/builder.py index 0e2142b3..378d8e97 100644 --- a/morphlib/builder.py +++ b/morphlib/builder.py @@ -282,27 +282,10 @@ class ChunkBuilder(BuilderBase): logpath = cache.get_source_metadata_filename( self.source, self.source.cache_key, 'build-log') - _, temppath = tempfile.mkstemp(dir=os.path.dirname(logpath)) - - try: - self.get_sources(builddir) - self.run_commands(temppath, stdout) - self.create_devices(destdir) - - os.rename(temppath, logpath) - except BaseException as e: - logging.error('Caught exception: %s' % str(e)) - logging.info('Cleaning up staging area') - if os.path.isfile(temppath): - with open(temppath) as f: - for line in f: - logging.error('BUILD OUTPUT: %s' % - line.rstrip('\n')) - - os.rename(temppath, logpath) - else: - logging.error("Couldn't find build log at %s", temppath) - raise + self.get_sources(builddir) + self.run_commands(stdout) + self.create_devices(destdir) + os.rename("%s.build-log" % self.staging_area.staging_dir, logpath) built_artifacts = self.assemble_chunk_artifacts(destdir) @@ -337,6 +320,7 @@ class ChunkBuilder(BuilderBase): ('strip', False), ('post-strip', False), ] + build_output = [] for step, in_parallel in steps: with self.build_watch(step): key = '%s-commands' % step @@ -344,9 +328,8 @@ class ChunkBuilder(BuilderBase): if not cmds: continue - with open(logfilepath, 'a') as log: - self.app.status(msg='Running %(key)s', key=key) - log.write('### %s ###\n' % key.upper()) + self.app.status(msg='Running %(key)s', key=key) + build_output.append('### %s ###\n' % key.upper()) for cmd in cmds: if cmd is False: cmd = "false" @@ -367,31 +350,31 @@ class ChunkBuilder(BuilderBase): stdout.flush() with open(os.devnull) as devnull: - exit_code = self.runcmd(['sh', '-x', '-c', cmd], + exit_code, out, err = self.runcmd(['sh', '-x', '-c', cmd], extra_env=extra_env, cwd=relative_builddir, stdin=devnull, stdout=stdout or subprocess.PIPE, stderr=subprocess.STDOUT, - logfile=logfilepath, ccache_dir=ccache_dir) + build_output.append(out) if stdout: stdout.flush() + for line in ''.join(build_output).splitlines(): + logging.debug('[Build output] %s' % line) + if exit_code != 0: if not stdout: - with open(logfilepath, 'r') as log: - shutil.copyfileobj(log, self.app.output) + self.app.output.write(''.join(build_output)) self.app.output.write("\n") - shutil.copyfile( - logfilepath, - self.staging_area.dirname + '.log') raise cliapp.AppException( "In staging area %s: %s failed (exit_code=%s)" % (self.staging_area.dirname, step, exit_code)) + def write_system_integration_commands(self, destdir, integration_commands, artifact_name): # pragma: no cover |