summaryrefslogtreecommitdiff
path: root/morphlib/buildenvironment.py
diff options
context:
space:
mode:
Diffstat (limited to 'morphlib/buildenvironment.py')
-rw-r--r--morphlib/buildenvironment.py59
1 files changed, 36 insertions, 23 deletions
diff --git a/morphlib/buildenvironment.py b/morphlib/buildenvironment.py
index d9e3210f..e6dccb04 100644
--- a/morphlib/buildenvironment.py
+++ b/morphlib/buildenvironment.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012 Codethink Limited
+# Copyright (C) 2012-2013 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -13,6 +13,8 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+import copy
+import cliapp
import os
import morphlib
@@ -20,18 +22,40 @@ import morphlib
class BuildEnvironment():
- def __init__(self, settings, arch=None):
+ '''Represents the build environment for an artifact
+
+ This should be as consistent as possible across builds, but some
+ artifacts will require tweaks. The intention of this object is
+ to create one once and call populate() to create an initial state
+ and when changes are required, call clone() to get another instance
+ which can be modified.
+
+ '''
+
+ def __init__(self, settings, target, arch=None):
+ '''Create a new BuildEnvironment object'''
+
+ self.extra_path = []
+ self.target = target
self.arch = morphlib.util.arch() if arch is None else arch
self.env = self._clean_env(settings)
_osenv = os.environ
- _default_path = '/sbin:/usr/sbin:/bin:/usr/bin'
- _override_term = 'dumb'
+ _ccache_path = '/usr/lib/ccache'
+ _override_home = '/tmp'
+ _override_locale = 'C'
_override_shell = '/bin/sh'
+ _override_term = 'dumb'
_override_username = 'tomjon'
- _override_locale = 'C'
- _override_home = '/tmp'
- _ccache_path = '/usr/lib/ccache'
+
+ def get_bootstrap_target(self, target):
+ '''Set 'vendor' field of the given machine triplet as 'bootstrap' '''
+
+ parts = target.split('-')
+ if len(parts) < 2:
+ raise morphlib.Error('Failed to parse machine triplet returned by '
+ 'host compiler: %s' % target)
+ return '-'.join([parts[0], 'bootstrap'] + parts[2:])
def _clean_env(self, settings):
'''Create a fresh set of environment variables for a clean build.
@@ -40,11 +64,8 @@ class BuildEnvironment():
'''
- path = self._osenv['PATH']
-
# copy a set of white-listed variables from the original env
copied_vars = dict.fromkeys([
- 'BOOTSTRAP_TOOLS',
'DISTCC_HOSTS',
'LD_PRELOAD',
'LD_LIBRARY_PATH',
@@ -62,10 +83,6 @@ class BuildEnvironment():
if copied_vars[name] is not None:
env[name] = copied_vars[name]
- if settings['bootstrap'] or not settings['staging-chroot']:
- if 'TMPDIR' in self._osenv:
- env['TMPDIR'] = self._osenv['TMPDIR']
-
env['TERM'] = self._override_term
env['SHELL'] = self._override_shell
env['USER'] = \
@@ -74,17 +91,13 @@ class BuildEnvironment():
env['LC_ALL'] = self._override_locale
env['HOME'] = self._override_home
- if settings['keep-path'] or settings['bootstrap']:
- env['PATH'] = path
- else:
- env['PATH'] = self._default_path
+ env['BUILD'] = self.target
+ env['TARGET'] = self.target
+ env['TARGET_STAGE1'] = self.get_bootstrap_target(self.target)
+ env['TARGET_GCC_CONFIG'] = ''
- env['TOOLCHAIN_TARGET'] = settings['toolchain-target']
- env['CFLAGS'] = settings['target-cflags']
- env['PREFIX'] = settings['prefix']
- env['BOOTSTRAP'] = 'true' if settings['bootstrap'] else 'false'
if not settings['no-ccache']:
- env['PATH'] = ('%s:%s' % (self._ccache_path, env['PATH']))
+ self.extra_path.append(self._ccache_path)
# FIXME: we should set CCACHE_BASEDIR so any objects that refer to their
# current directory get corrected. This improve the cache hit rate
# env['CCACHE_BASEDIR'] = self.tempdir.dirname