diff options
Diffstat (limited to 'morphlib/builder2.py')
-rw-r--r-- | morphlib/builder2.py | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/morphlib/builder2.py b/morphlib/builder2.py index 28a5e0ba..c7d25e1a 100644 --- a/morphlib/builder2.py +++ b/morphlib/builder2.py @@ -259,31 +259,53 @@ class ChunkBuilder(BuilderBase): def build_and_cache(self): # pragma: no cover with self.build_watch('overall-build'): - - builddir, destdir = \ - self.staging_area.chroot_open(self.artifact.source) + mounted = self.do_mounts() log_name = None try: + builddir = self.staging_area.builddir(self.artifact.source) self.get_sources(builddir) + destdir = self.staging_area.destdir(self.artifact.source) with self.local_artifact_cache.put_source_metadata( self.artifact.source, self.artifact.cache_key, 'build-log') as log: log_name = log.real_filename self.run_commands(builddir, destdir, log) except: - self.staging_area.chroot_close() + self.do_unmounts(mounted) if log_name: with open(log_name) as f: for line in f: logging.error('OUTPUT FROM FAILED BUILD: %s' % line.rstrip('\n')) raise - self.staging_area.chroot_close() + self.do_unmounts(mounted) built_artifacts = self.assemble_chunk_artifacts(destdir) self.save_build_times() return built_artifacts + to_mount = ( + ('proc', 'proc', 'none'), + ('dev/shm', 'tmpfs', 'none'), + ) + + def do_mounts(self): # pragma: no cover + mounted = [] + if not self.setup_mounts: + return mounted + for mount_point, mount_type, source in ChunkBuilder.to_mount: + logging.debug('Mounting %s in staging area' % mount_point) + path = os.path.join(self.staging_area.dirname, mount_point) + if not os.path.exists(path): + os.makedirs(path) + self.app.runcmd(['mount', '-t', mount_type, source, path]) + mounted.append(path) + return mounted + + def do_unmounts(self, mounted): # pragma: no cover + for path in mounted: + logging.debug('Unmounting %s in staging area' % path) + morphlib.fsutils.unmount(self.app.runcmd, path) def get_sources(self, srcdir): # pragma: no cover '''Get sources from git to a source directory, for building.''' |