From 370588a06395f5c90c8fab115cb9748be105d664 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 15 Feb 2012 16:36:06 +0000 Subject: Build non-bootstrap chunks inside a staging chroot This adds options --staging-filler and --staging-chroot. The wisdom of these options needs to be re-considered at some point, but for now they're OK. --- morphlib/builder.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'morphlib/builder.py') diff --git a/morphlib/builder.py b/morphlib/builder.py index 53b330d0..e93c8e79 100644 --- a/morphlib/builder.py +++ b/morphlib/builder.py @@ -362,7 +362,7 @@ class ChunkBuilder(BlobBuilder): def run_in_parallel(self, what, commands): self.msg('commands: %s' % what) with self.build_watch(what): - self.ex.run(commands) + self.run_commands(commands) def run_sequentially(self, what, commands): self.msg ('commands: %s' % what) @@ -370,10 +370,32 @@ class ChunkBuilder(BlobBuilder): flags = self.ex.env['MAKEFLAGS'] self.ex.env['MAKEFLAGS'] = '-j1' logging.debug('Setting MAKEFLAGS=%s' % self.ex.env['MAKEFLAGS']) - self.ex.run(commands) + self.run_commands(commands) self.ex.env['MAKEFLAGS'] = flags logging.debug('Restore MAKEFLAGS=%s' % self.ex.env['MAKEFLAGS']) + def run_commands(self, commands): + if self.settings['staging-chroot']: + ex = morphlib.execute.Execute(self.staging, self.msg) + ex.env.clear() + for key in self.ex.env: + ex.env[key] = self.ex.env[key] + assert self.builddir.startswith(self.staging + '/') + builddir = self.builddir[len(self.staging):] + for cmd in commands: + script = os.path.join(self.staging, 'temp.sh') + with open(script, 'w') as f: + f.write('#!/bin/sh\n') + f.write('set -ex\n') + f.write('cd %s\n' % builddir) + f.write('%s\n' % cmd) + os.chmod(script, 0555) + chroot_cmd = '/usr/sbin/chroot %s ./temp.sh' % self.staging + ex.run([chroot_cmd]) + os.remove(script) + else: + self.ex.run(commands) + def create_chunks(self): chunks = [] with self.build_watch('create-chunks'): @@ -657,9 +679,10 @@ class Builder(object): logging.debug('cache id: %s' % repr(cache_id)) self.dump_memory_profile('after computing cache id') - builder.builddir = self.tempdir.join('%s.build' % blob.morph.name) - builder.destdir = self.tempdir.join('%s.inst' % blob.morph.name) builder.staging = self.tempdir.join('staging') + s = builder.staging + builder.builddir = os.path.join(s, '%s.build' % blob.morph.name) + builder.destdir = os.path.join(s, '%s.inst' % blob.morph.name) builder.settings = self.settings builder.real_msg = self.msg builder.cache_prefix = self.cachedir.name(cache_id) -- cgit v1.2.1