summaryrefslogtreecommitdiff
path: root/morphlib
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2013-02-25 10:13:34 +0000
committerSam Thursfield <sam.thursfield@codethink.co.uk>2013-03-13 15:20:02 +0000
commit0cc3de60d6282d22108ea59f169a0749be5e59ea (patch)
tree2bef9ed79c0b4d9e128b3095e72ccce4a525a532 /morphlib
parent84807d4d7c23f45d4f0a0f87e6c7ba7ba7470936 (diff)
downloadmorph-0cc3de60d6282d22108ea59f169a0749be5e59ea.tar.gz
Add 'prefix' property for chunks within strata
Morph no longer supports setting the prefix using the --prefix argument / setting. This was only used in tests and during bootstrap. If a chunk build-depends on a chunk within a stratum which has a custom prefix, that prefix is appended to the PATH in the build environment.
Diffstat (limited to 'morphlib')
-rwxr-xr-xmorphlib/app.py5
-rw-r--r--morphlib/artifact.py14
-rw-r--r--morphlib/artifact_tests.py12
-rw-r--r--morphlib/artifactresolver.py1
-rw-r--r--morphlib/buildcommand.py13
-rw-r--r--morphlib/buildenvironment.py1
-rw-r--r--morphlib/buildenvironment_tests.py6
-rw-r--r--morphlib/cachekeycomputer.py5
-rw-r--r--morphlib/cachekeycomputer_tests.py1
-rw-r--r--morphlib/morph2.py2
-rw-r--r--morphlib/stagingarea.py4
11 files changed, 48 insertions, 16 deletions
diff --git a/morphlib/app.py b/morphlib/app.py
index d3136b43..b5379c83 100755
--- a/morphlib/app.py
+++ b/morphlib/app.py
@@ -41,7 +41,6 @@ defaults = {
],
'cachedir': os.path.expanduser('~/.cache/morph'),
'max-jobs': morphlib.util.make_concurrency(),
- 'prefix': '/usr',
'build-ref-prefix': 'baserock/builds'
}
@@ -117,10 +116,6 @@ class Morph(cliapp.Application):
self.settings.boolean(['no-distcc'],
'do not use distcc (default: true)',
group=group_build, default=True)
- self.settings.string(['prefix'],
- 'build chunks with prefix PREFIX',
- metavar='PREFIX', default=defaults['prefix'],
- group=group_build)
self.settings.boolean(['push-build-branches'],
'always push temporary build branches to the '
'remote repository',
diff --git a/morphlib/artifact.py b/morphlib/artifact.py
index 5f084384..82680709 100644
--- a/morphlib/artifact.py
+++ b/morphlib/artifact.py
@@ -61,6 +61,20 @@ class Artifact(object):
self.name,
metadata_name)
+ def get_dependency_prefix_set(self):
+ '''Collects all install prefixes of this artifact's build dependencies
+
+ If any of the build dependencies of a chunk artifact are installed
+ to non-standard prefixes, we need to add those prefixes to the
+ PATH of the current artifact.
+
+ '''
+ result = set()
+ for d in self.dependencies:
+ if d.source.morphology['kind'] == 'chunk':
+ result.add(d.source.prefix)
+ return result
+
def __str__(self): # pragma: no cover
return '%s|%s' % (self.source, self.name)
diff --git a/morphlib/artifact_tests.py b/morphlib/artifact_tests.py
index 1d9e6cca..8edbbde2 100644
--- a/morphlib/artifact_tests.py
+++ b/morphlib/artifact_tests.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
@@ -14,6 +14,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+import copy
import unittest
import morphlib
@@ -78,3 +79,12 @@ class ArtifactTests(unittest.TestCase):
self.assertEqual(self.artifact.dependencies, [self.other])
self.assertEqual(self.other.dependents, [self.artifact])
self.assertTrue(self.artifact.depends_on(self.other))
+
+ def test_get_dependency_prefix(self):
+ self.artifact.add_dependency(self.other)
+ self.artifact.source.prefix = '/bar'
+ self.other.source = copy.copy(self.artifact.source)
+ self.other.source.prefix = '/foo'
+
+ prefix_set = self.artifact.get_dependency_prefix_set()
+ self.assertEqual(prefix_set, set(['/foo']))
diff --git a/morphlib/artifactresolver.py b/morphlib/artifactresolver.py
index 76178b35..186d5357 100644
--- a/morphlib/artifactresolver.py
+++ b/morphlib/artifactresolver.py
@@ -222,6 +222,7 @@ class ArtifactResolver(object):
# Resolve now to avoid a search for the parent morphology later
chunk_source.build_mode = info['build-mode']
+ chunk_source.prefix = info['prefix']
build_depends = info.get('build-depends', None)
diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py
index 2de71d8f..d602b5ea 100644
--- a/morphlib/buildcommand.py
+++ b/morphlib/buildcommand.py
@@ -230,6 +230,10 @@ class BuildCommand(object):
setup_mounts = False
if artifact.source.morphology['kind'] == 'chunk':
build_mode = artifact.source.build_mode
+ extra_env = {'PREFIX': artifact.source.prefix}
+
+ dep_prefix_set = artifact.get_dependency_prefix_set()
+ extra_path = [os.path.join(d, 'bin') for d in dep_prefix_set]
if build_mode not in ['bootstrap', 'staging', 'test']:
raise morphlib.Error(
@@ -237,7 +241,8 @@ class BuildCommand(object):
(artifact.name, build_mode))
use_chroot = build_mode=='staging'
- staging_area = self.create_staging_area(use_chroot)
+ staging_area = self.create_staging_area(
+ use_chroot, extra_env=extra_env, extra_path=extra_path)
self.install_fillers(staging_area)
self.install_dependencies(staging_area, deps, artifact)
else:
@@ -312,13 +317,15 @@ class BuildCommand(object):
copy(self.rac.get_artifact_metadata(artifact, 'meta'),
self.lac.put_artifact_metadata(artifact, 'meta'))
- def create_staging_area(self, use_chroot=True):
+ def create_staging_area(self, use_chroot=True, extra_env={},
+ extra_path=[]):
'''Create the staging area for building a single artifact.'''
self.app.status(msg='Creating staging area')
staging_dir = tempfile.mkdtemp(dir=self.app.settings['tempdir'])
staging_area = morphlib.stagingarea.StagingArea(
- self.app, staging_dir, self.build_env, use_chroot, {})
+ self.app, staging_dir, self.build_env, use_chroot, extra_env,
+ extra_path)
return staging_area
def remove_staging_area(self, staging_area):
diff --git a/morphlib/buildenvironment.py b/morphlib/buildenvironment.py
index 6ba950ff..e6dccb04 100644
--- a/morphlib/buildenvironment.py
+++ b/morphlib/buildenvironment.py
@@ -91,7 +91,6 @@ class BuildEnvironment():
env['LC_ALL'] = self._override_locale
env['HOME'] = self._override_home
- env['PREFIX'] = settings['prefix']
env['BUILD'] = self.target
env['TARGET'] = self.target
env['TARGET_STAGE1'] = self.get_bootstrap_target(self.target)
diff --git a/morphlib/buildenvironment_tests.py b/morphlib/buildenvironment_tests.py
index 03799190..1995923b 100644
--- a/morphlib/buildenvironment_tests.py
+++ b/morphlib/buildenvironment_tests.py
@@ -33,7 +33,11 @@ class BuildEnvironmentTests(unittest.TestCase):
self.fake_env = {
'PATH': '/fake_bin',
}
- self.default_path = 'no:such:path'
+
+ def new_build_env(self, settings=None, target=None, **kws):
+ settings = settings or self.settings
+ target = target or self.target
+ return buildenvironment.BuildEnvironment(settings, target, **kws)
def new_build_env(self, settings=None, target=None, **kws):
settings = settings or self.settings
diff --git a/morphlib/cachekeycomputer.py b/morphlib/cachekeycomputer.py
index 4573ad0d..244257a0 100644
--- a/morphlib/cachekeycomputer.py
+++ b/morphlib/cachekeycomputer.py
@@ -27,8 +27,8 @@ class CacheKeyComputer(object):
self._calculated = {}
def _filterenv(self, env):
- keys = ["LOGNAME", "PREFIX", "TARGET", "TARGET_STAGE1",
- "TARGET_GCC_CONFIG", "USER", "USERNAME"]
+ keys = ["LOGNAME", "TARGET", "TARGET_STAGE1", "TARGET_GCC_CONFIG",
+ "USER", "USERNAME"]
return dict([(k, env[k]) for k in keys])
def compute_key(self, artifact):
@@ -88,6 +88,7 @@ class CacheKeyComputer(object):
kind = artifact.source.morphology['kind']
if kind == 'chunk':
keys['build-mode'] = artifact.source.build_mode
+ keys['prefix'] = artifact.source.prefix
keys['tree'] = artifact.source.tree
elif kind in ('system', 'stratum'):
morphology = artifact.source.morphology
diff --git a/morphlib/cachekeycomputer_tests.py b/morphlib/cachekeycomputer_tests.py
index 1dba80c2..ec4c9d22 100644
--- a/morphlib/cachekeycomputer_tests.py
+++ b/morphlib/cachekeycomputer_tests.py
@@ -105,7 +105,6 @@ class CacheKeyComputerTests(unittest.TestCase):
m.builds_artifacts = [m['name']]
self.build_env = DummyBuildEnvironment({
"LOGNAME": "foouser",
- "PREFIX": "/baserock",
"TARGET": "dummy-baserock-linux-gnu",
"TARGET_STAGE1": "dummy-baserock-linux-gnu",
"TARGET_GCC_CONFIG": "",
diff --git a/morphlib/morph2.py b/morphlib/morph2.py
index 728fa533..a8e1d7d3 100644
--- a/morphlib/morph2.py
+++ b/morphlib/morph2.py
@@ -159,6 +159,8 @@ class Morphology(object):
self._set_default_value(source, 'build-depends', None)
if 'build-mode' not in source:
self._set_default_value(source, 'build-mode', 'staging')
+ if 'prefix' not in source:
+ self._set_default_value(source, 'prefix', '/usr')
def _parse_size(self, size):
if isinstance(size, basestring):
diff --git a/morphlib/stagingarea.py b/morphlib/stagingarea.py
index 24b72867..de29eede 100644
--- a/morphlib/stagingarea.py
+++ b/morphlib/stagingarea.py
@@ -51,9 +51,9 @@ class StagingArea(object):
self.env.update(extra_env)
if use_chroot:
- path = build_env.extra_path + self._base_path
+ path = extra_path + build_env.extra_path + self._base_path
else:
- rel_path = build_env.extra_path
+ rel_path = extra_path + build_env.extra_path
full_path = [os.path.normpath(dirname + p) for p in rel_path]
path = full_path + os.environ['PATH'].split(':')
self.env['PATH'] = ':'.join(path)