summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmorph62
-rw-r--r--morphlib/builder.py99
2 files changed, 74 insertions, 87 deletions
diff --git a/morph b/morph
index 3a0a1f4b..14698ede 100755
--- a/morph
+++ b/morph
@@ -373,6 +373,68 @@ class Morph(cliapp.Application):
# run the command line
cliapp.Application.runcmd(self, argv, *args, **kwargs)
+ # This is in morph so that policy is easily visible, and not embedded
+ # deep down in the call stack.
+ def clean_env(self):
+ '''Create a fresh set of environment variables for a clean build.
+
+ Return a dict with the new environment.
+
+ '''
+
+ path = os.environ['PATH']
+ tools = os.environ.get('BOOTSTRAP_TOOLS')
+ distcc_hosts = os.environ.get('DISTCC_HOSTS')
+
+ # copy a set of white-listed variables from the original env
+ copied_vars = dict.fromkeys([
+ 'TMPDIR',
+ 'LD_PRELOAD',
+ 'LD_LIBRARY_PATH',
+ 'FAKEROOTKEY',
+ 'FAKED_MODE',
+ 'FAKEROOT_FD_BASE',
+ ])
+ for name in copied_vars:
+ copied_vars[name] = os.environ.get(name, None)
+
+ env = {}
+
+ # apply the copied variables to the clean env
+ for name in copied_vars:
+ if copied_vars[name] is not None:
+ env[name] = copied_vars[name]
+
+ env['TERM'] = 'dumb'
+ env['SHELL'] = '/bin/sh'
+ env['USER'] = \
+ env['USERNAME'] = \
+ env['LOGNAME'] = 'tomjon'
+ env['LC_ALL'] = 'C'
+ env['HOME'] = '/tmp'
+
+ if self.settings['keep-path'] or self.settings['bootstrap']:
+ env['PATH'] = path
+ else:
+ env['PATH'] = '/sbin:/usr/sbin:/bin:/usr/bin'
+
+ env['TOOLCHAIN_TARGET'] = '%s-baserock-linux-gnu' % os.uname()[4]
+ env['BOOTSTRAP'] = 'true' if self.settings['bootstrap'] else 'false'
+ if tools is not None:
+ env['BOOTSTRAP_TOOLS'] = tools
+ if distcc_hosts is not None:
+ env['DISTCC_HOSTS'] = distcc_hosts
+
+ if not self.settings['no-ccache']:
+ env['PATH'] = ('/usr/lib/ccache:%s' % env['PATH'])
+# FIXME: This needs to be made working, but it doesn't really, right now:
+# the tempdir is not available inside the staging chroot.
+# env['CCACHE_BASEDIR'] = self.tempdir.dirname
+ if not self.settings['no-distcc']:
+ env['CCACHE_PREFIX'] = 'distcc'
+
+ return env
+
if __name__ == '__main__':
Morph().run()
diff --git a/morphlib/builder.py b/morphlib/builder.py
index 8d7e946d..5bd75e05 100644
--- a/morphlib/builder.py
+++ b/morphlib/builder.py
@@ -154,9 +154,6 @@ class BlobBuilder(object): # pragma: no cover
self.tempdir = tempdir
self.env = env
- self.builddir = os.path.join(self.factory.staging,
- '%s.build' % blob.morph.name)
-
self.logfile = None
self.stage_items = []
self.real_msg = lambda s: None
@@ -276,10 +273,12 @@ class ChunkBuilder(BlobBuilder): # pragma: no cover
return ret
def do_build(self):
+ self.builddir = os.path.join(self.factory.staging,
+ '%s.build' % self.blob.morph.name)
self.msg('Creating build tree at %s' % self.builddir)
self.ex = morphlib.execute.Execute(self.builddir, self.msg)
- self.setup_env()
+ self.ex.env = self.env
self.factory.unpack_sources(self.blob.morph.treeish, self.builddir)
@@ -310,76 +309,6 @@ class ChunkBuilder(BlobBuilder): # pragma: no cover
self.factory.unpack_binary_from_file(chunk_filename)
ldconfig(ex, self.factory.staging)
- def setup_env(self):
- path = self.ex.env['PATH']
- tools = self.ex.env.get('BOOTSTRAP_TOOLS')
- distcc_hosts = self.ex.env.get('DISTCC_HOSTS')
-
- # copy a set of white-listed variables from the original env
- copied_vars = dict.fromkeys([
- 'TMPDIR',
- 'LD_PRELOAD',
- 'LD_LIBRARY_PATH',
- 'FAKEROOTKEY',
- 'FAKED_MODE',
- 'FAKEROOT_FD_BASE',
- ])
- for name in copied_vars:
- copied_vars[name] = self.ex.env.get(name, None)
-
- self.ex.env.clear()
-
- # apply the copied variables to the clean env
- for name in copied_vars:
- if copied_vars[name] is not None:
- self.ex.env[name] = copied_vars[name]
-
- self.ex.env['TERM'] = 'dumb'
- self.ex.env['SHELL'] = '/bin/sh'
- self.ex.env['USER'] = \
- self.ex.env['USERNAME'] = \
- self.ex.env['LOGNAME'] = 'tomjon'
- self.ex.env['LC_ALL'] = 'C'
- self.ex.env['HOME'] = os.path.join(self.tempdir.dirname)
-
- if self.settings['keep-path'] or self.settings['bootstrap']:
- self.ex.env['PATH'] = path
- else:
- bindirs = ['bin']
- path = ':'.join(os.path.join(self.tempdir.dirname, x)
- for x in bindirs)
- self.ex.env['PATH'] = path
-
- self.ex.env['WORKAREA'] = self.tempdir.dirname
- self.ex.env['DESTDIR'] = self.destdir + '/'
- self.ex.env['TOOLCHAIN_TARGET'] = \
- '%s-baserock-linux-gnu' % os.uname()[4]
- self.ex.env['BOOTSTRAP'] = \
- 'true' if self.settings['bootstrap'] else 'false'
- if tools is not None:
- self.ex.env['BOOTSTRAP_TOOLS'] = tools
- if distcc_hosts is not None:
- self.ex.env['DISTCC_HOSTS'] = distcc_hosts
-
- if self.blob.morph.max_jobs:
- max_jobs = int(self.blob.morph.max_jobs)
- logging.debug('max_jobs from morph: %s' % max_jobs)
- else:
- max_jobs = self.settings['max-jobs']
- logging.debug('max_jobs from settings: %s' % max_jobs)
- self.ex.env['MAKEFLAGS'] = '-j%d' % max_jobs
-
- if not self.settings['no-ccache']:
- self.ex.env['PATH'] = ('/usr/lib/ccache:%s' %
- self.ex.env['PATH'])
- self.ex.env['CCACHE_BASEDIR'] = self.tempdir.dirname
- if not self.settings['no-distcc']:
- self.ex.env['CCACHE_PREFIX'] = 'distcc'
-
- logging.debug('Environment for building chunk:')
- for key in sorted(self.ex.env):
- logging.debug(' %s=%s' % (key, self.ex.env[key]))
-
def build_with_system_or_commands(self):
'''Run explicit commands or commands from build system.
@@ -409,38 +338,34 @@ class ChunkBuilder(BlobBuilder): # pragma: no cover
def run_in_parallel(self, what, commands):
self.msg('commands: %s' % what)
with self.build_watch(what):
+ max_jobs = self.blob.morph.max_jobs
+ if max_jobs is None:
+ max_jobs = self.settings['max-jobs']
+ self.ex.env['MAKEFLAGS'] = '-j%s' % max_jobs
self.run_commands(commands)
def run_sequentially(self, what, commands):
self.msg ('commands: %s' % what)
with self.build_watch(what):
- flags = self.ex.env['MAKEFLAGS']
self.ex.env['MAKEFLAGS'] = '-j1'
- logging.debug('Setting MAKEFLAGS=%s' % self.ex.env['MAKEFLAGS'])
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.factory.staging, self.msg)
- ex.env.clear()
- for key in self.ex.env:
- ex.env[key] = self.ex.env[key]
+ ex.env = self.ex.env.copy()
+
assert self.builddir.startswith(self.factory.staging + '/')
assert self.destdir.startswith(self.factory.staging + '/')
builddir = self.builddir[len(self.factory.staging):]
destdir = self.destdir[len(self.factory.staging):]
+ ex.env['DESTDIR'] = destdir
+
for cmd in commands:
- old_destdir = ex.env.get('DESTDIR', None)
- ex.env['DESTDIR'] = destdir
ex.runv(['/usr/sbin/chroot', self.factory.staging, 'sh', '-c',
'cd "$1" && shift && eval "$@"', '--', builddir, cmd])
- if old_destdir is None:
- del ex.env['DESTDIR']
- else:
- ex.env['DESTDIR'] = old_destdir
else:
+ self.ex.env['DESTDIR'] = self.destdir
self.ex.run(commands)
def create_chunks(self):