summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Coldrick <adam@sotk.co.uk>2015-05-06 20:43:13 +0000
committerBaserock Gerrit <gerrit@baserock.org>2015-05-08 08:09:52 +0000
commitf9a0607b654ee1adb85f4c1bfedd3571a22ac21a (patch)
tree1d8b32ed5793f71c090883b9fa9c97a410f6ca11
parent4c0d2a9f9c3b71345d1a59a403c81d2795917a75 (diff)
downloadmorph-f9a0607b654ee1adb85f4c1bfedd3571a22ac21a.tar.gz
Raise an error if a stratum build-depends on itself
If a stratum build-depends on itself, the build graph calculation gets stuck in an infinite loop as it adds the same stratum to the queue of morphologies to inspect over and over again. This commit causes MorphologyLoader.validate_stratum to raise an error if a stratum contains itself in it's build-depends, as depending on itself makes no sense and will cause the above problem. Change-Id: I76df5b7d63d010ae3b17f72bfa39b273e74279dd
-rw-r--r--morphlib/morphloader.py11
-rw-r--r--morphlib/morphloader_tests.py14
2 files changed, 25 insertions, 0 deletions
diff --git a/morphlib/morphloader.py b/morphlib/morphloader.py
index 47cb03d7..0c69baac 100644
--- a/morphlib/morphloader.py
+++ b/morphlib/morphloader.py
@@ -195,6 +195,14 @@ class EmptySystemError(MorphologyValidationError):
self, 'System %(system_name)s has no strata.' % locals())
+class DependsOnSelfError(MorphologyValidationError):
+
+ def __init__(self, name, filename):
+ msg = ("Stratum %(name)s build-depends on itself (%(filename)s)"
+ % locals())
+ MorphologyValidationError.__init__(self, msg)
+
+
class MultipleValidationErrors(MorphologyValidationError):
def __init__(self, name, errors):
@@ -536,6 +544,9 @@ class MorphologyLoader(object):
raise InvalidTypeError(
'build-depends', list, type(morph['build-depends']),
morph['name'])
+ for dep in morph['build-depends']:
+ if dep['morph'] == morph.filename:
+ raise DependsOnSelfError(morph['name'], morph.filename)
else:
for spec in morph['chunks']:
if spec.get('build-mode') in ['bootstrap', 'test']:
diff --git a/morphlib/morphloader_tests.py b/morphlib/morphloader_tests.py
index f9fa2a34..db1872a8 100644
--- a/morphlib/morphloader_tests.py
+++ b/morphlib/morphloader_tests.py
@@ -225,6 +225,20 @@ build-system: dummy
morphlib.morphloader.EmptyRefError):
self.loader.validate(m)
+ def test_fails_to_validate_stratum_which_build_depends_on_self(self):
+ text = '''\
+name: bad-stratum
+kind: stratum
+build-depends:
+- morph: strata/bad-stratum.morph
+chunks:
+- name: chunk
+ repo: test:repo
+ ref: foo'''
+ self.assertRaises(
+ morphlib.morphloader.DependsOnSelfError,
+ self.loader.load_from_string, text, 'strata/bad-stratum.morph')
+
def test_fails_to_validate_system_with_obsolete_system_kind_field(self):
m = morphlib.morphology.Morphology({
'kind': 'system',