summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rwxr-xr-xtests.build/build-system-cpan.script24
-rwxr-xr-xtests.build/build-system-python-distutils.script25
-rwxr-xr-xtests.build/prefix.script87
-rw-r--r--tests.build/prefix.stdout8
15 files changed, 190 insertions, 18 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)
diff --git a/tests.build/build-system-cpan.script b/tests.build/build-system-cpan.script
index 19e45e42..b1823eb5 100755
--- a/tests.build/build-system-cpan.script
+++ b/tests.build/build-system-cpan.script
@@ -54,7 +54,29 @@ git add hello.morph
git commit --quiet -m 'convert hello into a perl cpan project'
-"$SRCDIR/scripts/test-morph" build-morphology --prefix=/ \
+# Set 'prefix' of hello to something custom
+cd "$DATADIR/morphs-repo"
+cat <<EOF > hello-stratum.morph
+{
+ "name": "hello-stratum",
+ "kind": "stratum",
+ "chunks": [
+ {
+ "name": "hello",
+ "repo": "test:chunk-repo",
+ "ref": "farrokh",
+ "build-depends": [],
+ "build-mode": "test",
+ "prefix": "/"
+ }
+ ]
+}
+EOF
+git add hello-stratum.morph
+git commit -q -m "Set custom install prefix for hello"
+
+
+"$SRCDIR/scripts/test-morph" build-morphology \
test:morphs-repo master hello-system
for chunk in "$DATADIR/cache/artifacts/"*.chunk.*
diff --git a/tests.build/build-system-python-distutils.script b/tests.build/build-system-python-distutils.script
index cebb9f84..a0469528 100755
--- a/tests.build/build-system-python-distutils.script
+++ b/tests.build/build-system-python-distutils.script
@@ -51,7 +51,30 @@ git add hello.morph
git commit --quiet -m 'convert hello into a python project'
-"$SRCDIR/scripts/test-morph" build-morphology --prefix= \
+
+# Set 'prefix' of hello to something custom
+cd "$DATADIR/morphs-repo"
+cat <<EOF > hello-stratum.morph
+{
+ "name": "hello-stratum",
+ "kind": "stratum",
+ "chunks": [
+ {
+ "name": "hello",
+ "repo": "test:chunk-repo",
+ "ref": "farrokh",
+ "build-depends": [],
+ "build-mode": "test",
+ "prefix": ""
+ }
+ ]
+}
+EOF
+git add hello-stratum.morph
+git commit -q -m "Set custom install prefix for hello"
+
+
+"$SRCDIR/scripts/test-morph" build-morphology \
test:morphs-repo master hello-system
for chunk in "$DATADIR/cache/artifacts/"*.chunk.*
diff --git a/tests.build/prefix.script b/tests.build/prefix.script
new file mode 100755
index 00000000..e9b8ecd2
--- /dev/null
+++ b/tests.build/prefix.script
@@ -0,0 +1,87 @@
+#!/bin/sh
+#
+# Copyright (C) 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
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+## Honour 'prefix' attribute for chunks within stratum morphs
+
+set -eu
+
+# Create two chunks which print out PATH and PREFIX from their environment.
+cd "$DATADIR/chunk-repo"
+git checkout -q master
+cat <<\EOF > xyzzy.morph
+{
+ "name": "xyzzy",
+ "kind": "chunk",
+ "configure-commands": [
+ "echo First chunk: prefix $PREFIX"
+ ]
+}
+EOF
+
+cat <<\EOF > plugh.morph
+{
+ "name": "plugh",
+ "kind": "chunk",
+ "configure-commands": [
+ "echo Second chunk: prefix $PREFIX",
+ "echo Path: $(echo $PATH | grep -o '/plover')"
+ ]
+}
+EOF
+
+git add xyzzy.morph
+git add plugh.morph
+git commit -q -m "Add chunks"
+
+# Change stratum to include those two chunks, and use a custom install prefix
+cd "$DATADIR/morphs-repo"
+cat <<EOF > hello-stratum.morph
+{
+ "name": "hello-stratum",
+ "kind": "stratum",
+ "chunks": [
+ {
+ "name": "xyzzy",
+ "repo": "test:chunk-repo",
+ "ref": "master",
+ "build-depends": [],
+ "build-mode": "test",
+ "prefix": "/plover"
+ },
+ {
+ "name": "plugh",
+ "repo": "test:chunk-repo",
+ "ref": "master",
+ "build-mode": "test",
+ "build-depends": [
+ "xyzzy"
+ ]
+ }
+ ]
+}
+EOF
+git add hello-stratum.morph
+git commit -q -m "Update stratum"
+
+"$SRCDIR/scripts/test-morph" build-morphology \
+ test:morphs-repo master hello-system
+
+cd "$DATADIR/cache/artifacts"
+first_chunk=$(ls -1 *.chunk.xyzzy | cut -c -64)
+second_chunk=$(ls -1 *.chunk.plugh | cut -c -64)
+cat $first_chunk.build-log $second_chunk.build-log
diff --git a/tests.build/prefix.stdout b/tests.build/prefix.stdout
new file mode 100644
index 00000000..80c18fae
--- /dev/null
+++ b/tests.build/prefix.stdout
@@ -0,0 +1,8 @@
+# configure
+# # echo First chunk: prefix $PREFIX
+First chunk: prefix /plover
+# configure
+# # echo Second chunk: prefix $PREFIX
+Second chunk: prefix /usr
+# # echo Path: $(echo $PATH | grep -o '/plover')
+Path: /plover