summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-02-13 16:54:10 (GMT)
committerBaserock Gerrit <gerrit@baserock.org>2016-02-25 18:23:06 (GMT)
commit472dbbbbfa07e67c02a98e9f4ee50fc86ad32b7e (patch)
treea88c20d609a71128b4ec463a215ad17f21eb850c
parentc1aa6a47e792cfa61b67eccee401fcb77cd57591 (diff)
downloadmorph-472dbbbbfa07e67c02a98e9f4ee50fc86ad32b7e.tar.gz
Error when different names in system/strata
Now is an error when the name of a stratum in a system is different from the name of the stratum in the stratum file. Example of the error message: ERROR: Name 'build-essential-foo' doesn't match 'build-essential' in morphology: strata/build-essential.morph We are forcing the error here instead of a warning because this problem makes Morph create broken systems. https://storyboard.baserock.org/#!/story/15 Change-Id: Ifbe8d98e64a768e4e238d2213ffaf575789dd9e2
-rw-r--r--morphlib/sourceresolver.py31
1 files changed, 25 insertions, 6 deletions
diff --git a/morphlib/sourceresolver.py b/morphlib/sourceresolver.py
index 2346d2d..204fdb7 100644
--- a/morphlib/sourceresolver.py
+++ b/morphlib/sourceresolver.py
@@ -107,6 +107,14 @@ class MorphologyReferenceNotFoundError(SourceResolverError):
% (filename, reference_file))
+class MorphologyNameError(SourceResolverError):
+ def __init__(self, name_in_morphology, name, filename):
+ SourceResolverError.__init__(self,
+ "Name '%s' doesn't match '%s' in "
+ "morphology: %s"
+ % (name_in_morphology, name, filename))
+
+
# Callers may want to give the user a special error message if we hit an
# InvalidRefError in the definitions.git repo. Currently a separate exception
# type seems the easiest way to do that, but adding enough detail to the
@@ -300,15 +308,19 @@ class SourceResolver(object):
system_filenames,
visit,
predefined_split_rules):
- definitions_queue = collections.deque(system_filenames)
+ # Initialise definitions_queue with tuples (name, filename).
+ # We don't need system's filename, so use 'None'
+ definitions_queue = collections.deque((None, f)
+ for f in system_filenames)
chunk_queue = set()
def get_morphology(filename):
return self._get_morphology(resolved_morphologies,
definitions_checkout_dir, morph_loader,
filename)
+
while definitions_queue:
- filename = definitions_queue.popleft()
+ name, filename = definitions_queue.popleft()
morphology = get_morphology(filename)
@@ -323,13 +335,20 @@ class SourceResolver(object):
raise cliapp.AppException(
"Cannot build a morphology of type 'cluster'.")
elif morphology['kind'] == 'system':
- definitions_queue.extend(
- sanitise_morphology_path(s['morph'])
+ # name is not mandatory, use 'None' if not definied.
+ definitions_queue.extend((s.get('name'),
+ sanitise_morphology_path(s['morph']))
for s in morphology['strata'])
elif morphology['kind'] == 'stratum':
+ # If we have the name of the stratum, fail if it doesn't
+ # match with the one set in the stratum file.
+ if name and name != morphology.get('name'):
+ raise MorphologyNameError(morphology['name'], name,
+ filename)
if morphology['build-depends']:
- definitions_queue.extend(
- sanitise_morphology_path(s['morph'])
+ # build-depends don't have names. Use 'None' as name.
+ definitions_queue.extend((None,
+ sanitise_morphology_path(s['morph']))
for s in morphology['build-depends'])
for c in morphology['chunks']:
if 'morph' in c: