diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2013-02-22 11:45:16 +0000 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2013-03-13 15:20:03 +0000 |
commit | a20a6bdf6ed75c6bd5c06a25961e0c6bec93bdd6 (patch) | |
tree | 4602606c5659ed54a79fc2f1e9e858fbf7b2516f | |
parent | 18b162cd4556eb8c63767916cd376d87630db1b7 (diff) | |
download | morph-a20a6bdf6ed75c6bd5c06a25961e0c6bec93bdd6.tar.gz |
Don't install bootstrapped chunks when building artifacts in other strata
When building a stratum artifact it's easy to only include chunks that
were built in 'staging' mode. Constructing the staging area doesn't use
that code path, though, so we need an extra hack to filter out those
artifacts while building.
It may be neater to express stratum build-depends as actual
dependencies on the stratum artifact, rather than each of its
constituent chunks as we do now.
-rw-r--r-- | morphlib/buildcommand.py | 12 | ||||
-rwxr-xr-x | tests.build/bootstrap-mode.script | 127 | ||||
-rw-r--r-- | tests.build/bootstrap-mode.stdout | 9 |
3 files changed, 128 insertions, 20 deletions
diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py index d602b5ea..9f6a0470 100644 --- a/morphlib/buildcommand.py +++ b/morphlib/buildcommand.py @@ -346,6 +346,15 @@ class BuildCommand(object): filename=filename) staging_area.install_artifact(f) + # Nasty hack to avoid installing chunks built in 'bootstrap' mode in a + # different stratum when constructing staging areas. + def is_stratum(self, a): + return a.source.morphology['kind'] == 'stratum' + + def in_same_stratum(self, a, b): + return len(filter(self.is_stratum, a.dependencies)) == \ + len(filter(self.is_stratum, b.dependencies)) + def install_dependencies(self, staging_area, artifacts, target_artifact): '''Install chunk artifacts into staging area. @@ -360,6 +369,9 @@ class BuildCommand(object): for artifact in artifacts: if artifact.source.morphology['kind'] != 'chunk': continue + if artifact.source.build_mode == 'bootstrap': + if not self.in_same_stratum(artifact, target_artifact): + continue self.app.status(msg='[%(name)s] Installing chunk %(chunk_name)s', name=target_artifact.name, chunk_name=artifact.name) diff --git a/tests.build/bootstrap-mode.script b/tests.build/bootstrap-mode.script index 02c74dfe..f4ff0a36 100755 --- a/tests.build/bootstrap-mode.script +++ b/tests.build/bootstrap-mode.script @@ -22,44 +22,135 @@ set -eu -# Add a chunk in hello-stratum that is built in bootstrap mode +# Create a fake 'compiler' chunk to go into build-essential stratum +mkdir -p "$DATADIR/cc-repo" +cd "$DATADIR/cc-repo" + +cat <<EOF > "morph-test-cc" +#!/bin/sh +echo "I'm a compiler!" +EOF +chmod +x morph-test-cc + +cat <<EOF > "stage1-cc.morph" +{ + "name": "stage1-cc", + "kind": "chunk", + "install-commands": [ + "install -d \"\$DESTDIR\$PREFIX/bin\"", + "install -m 755 morph-test-cc \"\$DESTDIR\$PREFIX/bin/morph-test-cc\"" + ] +} +EOF + +cat <<EOF > "cc.morph" +{ + "name": "cc", + "kind": "chunk", + "configure-commands": [ + "[ -e ../tools/bin/morph-test-cc ]" + ], + "install-commands": [ + "install -d \"\$DESTDIR\$PREFIX/bin\"", + "install -m 755 morph-test-cc \"\$DESTDIR\$PREFIX/bin/morph-test-cc\"" + ] +} +EOF + +git init -q +git add morph-test-cc cc.morph stage1-cc.morph +git commit -q -m "Create compiler chunk" + +# Require 'cc' in hello-chunk. We should have the second version available +# but *not* the first one. +cd "$DATADIR/chunk-repo" +git checkout -q farrokh +cat <<EOF > "hello.morph" +{ + "name": "hello", + "kind": "chunk", + "configure-commands": [ + "[ ! -e ../tools/bin/morph-test-cc ]", + "[ -e ../usr/bin/morph-test-cc ]" + ], + "build-commands": [ + "../usr/bin/morph-test-cc > hello" + ], + "install-commands": [ + "install -d \"\$DESTDIR\$PREFIX/bin\"", + "install hello \"\$DESTDIR\$PREFIX/bin/hello\"" + ] +} +EOF +git add hello.morph +git commit -q -m "Make 'hello' require our mock compiler" + +# Add 'build-essential' stratum and make hello-stratum depend upon it. Only +# the *second* 'cc' chunk should make it into the build-essential stratum +# artifact, and neither should make it into the system. cd "$DATADIR/morphs-repo" -cat <<EOF > "hello-stratum.morph" +cat <<EOF > "build-essential.morph" { - "name": "hello-stratum", + "name": "build-essential", "kind": "stratum", "chunks": [ { - "name": "stage1-hello", - "repo": "test:chunk-repo", - "ref": "farrokh", + "name": "stage1-cc", + "repo": "test:cc-repo", + "ref": "master", "build-depends": [], - "build-mode": "bootstrap" + "build-mode": "bootstrap", + "prefix": "/tools" }, { + "name": "cc", + "repo": "test:cc-repo", + "ref": "master", + "build-depends": [ + "stage1-cc" + ], + "build-mode": "test" + } + ] +} +EOF + +cat <<EOF > "hello-stratum.morph" +{ + "name": "hello-stratum", + "kind": "stratum", + "build-depends": [ + { + "morph": "build-essential", + "repo": "test:morphs-repo", + "ref": "master" + } + ], + "chunks": [ + { "name": "hello", "repo": "test:chunk-repo", "ref": "farrokh", - "build-depends": [ - "stage1-hello" - ], + "build-depends": [], "build-mode": "test" } ] } EOF -git add hello-stratum.morph -git commit -q -m "Add bootstrap chunk in hello-stratum" -cd "$DATADIR/chunk-repo" -git checkout -q farrokh -sed -e "s/\"hello\"/\"stage1-hello\"/g" hello.morph > stage1-hello.morph -git add stage1-hello.morph -git commit -q -m "Add stage1-hello morphology for bootstrapping test" +git add build-essential.morph hello-stratum.morph hello-system.morph +git commit -q -m "Add fake build-essential stratum" "$SRCDIR/scripts/test-morph" build-morphology \ test:morphs-repo master hello-system -system=$(ls "$DATADIR/cache/artifacts/"*hello-system-rootfs) +cd "$DATADIR/cache/artifacts" +echo "build-essential stratum:" +stratum=$(ls *.stratum.build-essential) +cat $stratum | sed 's/[a-f0-9]\{64\}/xxxx/g' +echo +echo +echo "hello-system:" +system=$(ls *hello-system-rootfs) tar tf "$system" | LC_ALL=C sort | sed '/^\.\/./s:^\./::' diff --git a/tests.build/bootstrap-mode.stdout b/tests.build/bootstrap-mode.stdout index 3d5201ee..329cdd78 100644 --- a/tests.build/bootstrap-mode.stdout +++ b/tests.build/bootstrap-mode.stdout @@ -1,10 +1,15 @@ +build-essential stratum: +["xxxx.chunk.cc"] + +hello-system: ./ baserock/ baserock/hello-stratum.meta baserock/hello-system-rootfs.meta baserock/hello.meta -bin/ -bin/hello etc/ etc/fstab etc/os-release +usr/ +usr/bin/ +usr/bin/hello |