summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2015-07-02 15:59:59 +0000
committerBaserock Gerrit <gerrit@baserock.org>2015-10-15 14:24:51 +0000
commit6655ef761d77c3234c3cf775bf5ee38bd3f43b0c (patch)
tree639a003ff47d2e4be3c2816e46d1287151947353
parentb8b8de2b123ff96e6469196934359485bcd06b04 (diff)
downloadmorph-6655ef761d77c3234c3cf775bf5ee38bd3f43b0c.tar.gz
Error on duplicate chunks
This commit makes it an error for a system to contain duplicate chunk sources, example error message below, ERROR: Multiple `syslinux' chunks detected: upstream:syslinux|d715b39c0801ecea5e52f9029cea7c76320f93cf|strata/bsp-x86_both-tools/syslinux.morph|syslinux upstream:syslinux|2aab8555987b547b617cbb887e61083fece01541|strata/bsp-x86_64-generic/syslinux.morph|syslinux Multiple `nasm' chunks detected: upstream:nasm|78bdad3d14fb875d5f2062957e326ba2a9e4ccb0|strata/bsp-x86_64-generic/nasm.morph|nasm upstream:nasm|78bdad3d14fb875d5f2062957e326ba2a9e4ccb0|strata/bsp-x86_both-tools/nasm.morph|nasm Change-Id: I1d1539a46ce6eb098d3a559295ab9a08d6d2865c
-rw-r--r--morphlib/sourceresolver.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/morphlib/sourceresolver.py b/morphlib/sourceresolver.py
index 1056af16..108adc14 100644
--- a/morphlib/sourceresolver.py
+++ b/morphlib/sourceresolver.py
@@ -457,6 +457,32 @@ class SourceResolver(object):
repo, ref, filename, buildsystem, visit,
predefined_split_rules)
+class DuplicateChunkError(morphlib.Error):
+
+ def _make_msg(self, (name, sources)): # pragma: no cover
+ return ("Multiple `%s' chunks detected:\n\t%s"
+ % (name, '\n\t'.join((str(s) for s in sources))))
+
+ def __init__(self, duplicate_chunks): # pragma: no cover
+ msgs = (self._make_msg(dup) for dup in duplicate_chunks.iteritems())
+ msg = '\n'.join(msgs)
+
+ super(DuplicateChunkError, self).__init__(msg)
+
+def _find_duplicate_chunks(sourcepool): #pragma: no cover
+ ''' Searches the sourcepool for duplicate chunks
+ returns a dictionary of any duplicates keyed on chunk source name,
+ the value of each item is a list of duplicate chunk sources
+ '''
+
+ chunk_sources = ((s.name, s) for s in sourcepool
+ if s.morphology['kind'] == 'chunk')
+
+ chunk_sources_by_name = collections.defaultdict(list)
+ for (name, source) in chunk_sources:
+ chunk_sources_by_name[name].append(source)
+
+ return {k: v for (k, v) in chunk_sources_by_name.iteritems() if len(v) > 1}
def create_source_pool(lrc, rrc, repo, ref, filenames, cachedir,
original_ref=None, update_repos=True,
@@ -493,4 +519,10 @@ def create_source_pool(lrc, rrc, repo, ref, filenames, cachedir,
resolver.traverse_morphs(repo, ref, filenames,
visit=add_to_pool,
definitions_original_ref=original_ref)
+
+ # No two chunks may have the same name
+ duplicate_chunks = _find_duplicate_chunks(pool)
+ if duplicate_chunks:
+ raise DuplicateChunkError(duplicate_chunks)
+
return pool