diff options
author | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-02-11 12:02:13 +0000 |
---|---|---|
committer | Lars Wirzenius <lars.wirzenius@codethink.co.uk> | 2013-02-11 12:02:13 +0000 |
commit | aa644f02e326f1bc67d77e32c772dee91f876fc0 (patch) | |
tree | aea172d51ab8a8c8fa794ea4c6ab0df59b3b4d3c | |
parent | 592b73aaba34962c0bda1e89ca807d5f1275f620 (diff) | |
parent | aa2f9210ef5e623b1331049c83d429f14a17771a (diff) | |
download | morph-aa644f02e326f1bc67d77e32c772dee91f876fc0.tar.gz |
Merge remote-tracking branch 'origin/samthursfield/morph-name-equals-filename'
-rw-r--r-- | morphlib/morphologyfactory.py | 5 | ||||
-rw-r--r-- | morphlib/morphologyfactory_tests.py | 56 | ||||
-rwxr-xr-x | tests/name-clash.script | 66 |
3 files changed, 37 insertions, 90 deletions
diff --git a/morphlib/morphologyfactory.py b/morphlib/morphologyfactory.py index 6625d375..d23f55a4 100644 --- a/morphlib/morphologyfactory.py +++ b/morphlib/morphologyfactory.py @@ -86,6 +86,11 @@ class MorphologyFactory(object): raise morphlib.Error("Error parsing %s: %s" % (filename, str(e))) + if filename != morphology['name'] + '.morph': + raise morphlib.Error( + "Name %s does not match basename of morphology file %s" % + (morphology['name'], filename)) + method_name = '_check_and_tweak_%s' % morphology['kind'] if hasattr(self, method_name): method = getattr(self, method_name) diff --git a/morphlib/morphologyfactory_tests.py b/morphlib/morphologyfactory_tests.py index 56c6fc57..16d9af69 100644 --- a/morphlib/morphologyfactory_tests.py +++ b/morphlib/morphologyfactory_tests.py @@ -29,10 +29,10 @@ class FakeRemoteRepoCache(object): def cat_file(self, reponame, sha1, filename): if filename.endswith('.morph'): return '''{ - "name": "remote-foo", + "name": "%s", "kind": "chunk", "build-system": "bar" - }''' + }''' % filename[:-len('.morph')] return 'text' def ls_tree(self, reponame, sha1): @@ -42,30 +42,34 @@ class FakeLocalRepo(object): morphologies = { 'chunk.morph': '''{ - "name": "local-foo", + "name": "chunk", "kind": "chunk", "build-system": "bar" }''', 'chunk-split.morph': '''{ - "name": "local-foo", + "name": "chunk-split", "kind": "chunk", "build-system": "bar", "chunks": { - "local-foo-runtime": [], - "local-foo-devel": [] + "chunk-split-runtime": [], + "chunk-split-devel": [] } }''', 'stratum.morph': '''{ - "name": "foo-stratum", + "name": "stratum", "kind": "stratum" }''', 'system.morph': '''{ - "name": "foo-system", + "name": "system", "kind": "system", "system-kind": "%(system_kind)s", "arch": "%(arch)s" }''', 'parse-error.morph': '''{ "name"''', + 'name-mismatch.morph': '''{ + "name": "fred", + "kind": "stratum" + }''', } def __init__(self): @@ -81,10 +85,10 @@ class FakeLocalRepo(object): return self.morphologies[filename] % values elif filename.endswith('.morph'): return '''{ - "name": "local-foo", + "name": "%s", "kind": "chunk", "build-system": "bar" - }''' + }''' % filename[:-len('.morph')] return 'text' def ls_tree(self, sha1): @@ -118,7 +122,7 @@ class MorphologyFactoryTests(unittest.TestCase): raise CatFileError('reponame', 'ref', 'filename') def localmorph(self, *args): - return ['foo.morph'] + return ['chunk.morph'] def nolocalmorph(self, *args): if args[-1].endswith('.morph'): @@ -129,7 +133,7 @@ class MorphologyFactoryTests(unittest.TestCase): return ['configure.in'] def remotemorph(self, *args): - return ['foo.morph'] + return ['remote-chunk.morph'] def noremotemorph(self, *args): if args[-1].endswith('.morph'): @@ -142,21 +146,21 @@ class MorphologyFactoryTests(unittest.TestCase): def test_gets_morph_from_local_repo(self): self.lr.ls_tree = self.localmorph morph = self.mf.get_morphology('reponame', 'sha1', - 'foo.morph') - self.assertEqual('local-foo', morph['name']) + 'chunk.morph') + self.assertEqual('chunk', morph['name']) def test_gets_morph_from_remote_repo(self): self.rrc.ls_tree = self.remotemorph self.lrc.has_repo = self.doesnothaverepo morph = self.mf.get_morphology('reponame', 'sha1', - 'foo.morph') - self.assertEqual('remote-foo', morph['name']) + 'remote-chunk.morph') + self.assertEqual('remote-chunk', morph['name']) def test_autodetects_local_morphology(self): self.lr.cat = self.nolocalmorph self.lr.ls_tree = self.autotoolsbuildsystem morph = self.mf.get_morphology('reponame', 'sha1', - 'assumed-local.morph') + 'assumed-local.morph') self.assertEqual('assumed-local', morph['name']) def test_autodetects_remote_morphology(self): @@ -179,11 +183,15 @@ class MorphologyFactoryTests(unittest.TestCase): self.assertRaises(AutodetectError, self.mf.get_morphology, 'reponame', 'sha1', 'unreached.morph') + def test_raises_error_when_name_mismatches(self): + self.assertRaises(morphlib.Error, self.mf.get_morphology, + 'reponame', 'sha1', 'name-mismatch.morph') + def test_looks_locally_with_no_remote(self): self.lr.ls_tree = self.localmorph morph = self.lmf.get_morphology('reponame', 'sha1', - 'foo.morph') - self.assertEqual('local-foo', morph['name']) + 'chunk.morph') + self.assertEqual('chunk', morph['name']) def test_autodetects_locally_with_no_remote(self): self.lr.cat = self.nolocalmorph @@ -199,27 +207,27 @@ class MorphologyFactoryTests(unittest.TestCase): def test_sets_builds_artifacts_for_simple_chunk(self): morph = self.mf.get_morphology('reponame', 'sha1', 'chunk.morph') - self.assertEqual(morph.builds_artifacts, ['local-foo']) + self.assertEqual(morph.builds_artifacts, ['chunk']) def test_sets_builds_artifacts_for_split_chunk(self): morph = self.mf.get_morphology('reponame', 'sha1', 'chunk-split.morph') self.assertEqual(morph.builds_artifacts, - ['local-foo-runtime', 'local-foo-devel']) + ['chunk-split-runtime', 'chunk-split-devel']) def test_sets_builds_artifacts_for_stratum(self): morph = self.mf.get_morphology('reponame', 'sha1', 'stratum.morph') - self.assertEqual(morph.builds_artifacts, ['foo-stratum']) + self.assertEqual(morph.builds_artifacts, ['stratum']) def test_sets_builds_artifacts_for_x86_64_system(self): self.lr.arch = 'x86_64' morph = self.mf.get_morphology('reponame', 'sha1', 'system.morph') - self.assertEqual(morph.builds_artifacts, ['foo-system-rootfs']) + self.assertEqual(morph.builds_artifacts, ['system-rootfs']) def test_sets_builds_artifacts_for_arm_system(self): self.lr.arch = 'armv7' morph = self.mf.get_morphology('reponame', 'sha1', 'system.morph') self.assertEqual(sorted(morph.builds_artifacts), - sorted(['foo-system-rootfs', 'foo-system-kernel'])) + sorted(['system-rootfs', 'system-kernel'])) def test_sets_needs_staging_for_chunk(self): morph = self.mf.get_morphology('reponame', 'sha1', 'chunk.morph') diff --git a/tests/name-clash.script b/tests/name-clash.script deleted file mode 100755 index b1df563c..00000000 --- a/tests/name-clash.script +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2012 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. - - -## When there are two chunks with the same "name" set in the morphology, -## only the first built should be used. This can cause build failures when -## the wrong name is set and could be a vector for including dodgy data in -## a system. - -set -eu - -( cd "$DATADIR/chunk-repo" - git checkout --quiet farrokh - cat >goodbye <<EOF -#!/bin/sh -echo Goodbye world, muahahahaha -EOF - git add goodbye - - # add a morph with the same "name" but different commands - cat >goodbye.morph <<EOF -{ - "name": "hello", - "kind": "chunk", - "build-system": "dummy", - "install-commands": [ - "install -d \\"\$DESTDIR\\"/bin", - "install goodbye \\"\$DESTDIR\\"/bin/hello" - ] -} -EOF - git add goodbye.morph - - git commit --quiet -m "add a totally safe script" -) - -# build the dodgy chunk -"$SRCDIR/scripts/test-morph" build-morphology \ - test:chunk-repo farrokh goodbye - -# build a stratum -"$SRCDIR/scripts/test-morph" build-morphology \ - test:morphs-repo master hello-stratum - -# unpack it and check the contents -INSTDIR="$DATADIR"/unpack -mkdir -p "$INSTDIR" -"$SRCDIR/scripts/assemble-stratum" --cachedir "$DATADIR/cache" \ - "$DATADIR/cache/artifacts/"*hello-stratum \ - "$DATADIR/stratum.tar" hello-stratum -tar -C "$INSTDIR" -xhf "$DATADIR/stratum.tar" -test "$("$INSTDIR"/bin/hello)" = "hello, world" |