summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2013-12-18 18:33:58 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2014-01-15 17:38:08 +0000
commitb1ae48ff49dcbd34fb9a9a4eac62868b9195f9ef (patch)
tree3a4dbfbcc42fffde59584da650dc05035e47e64b
parent623a908220316a8064d3187597b255f5056b1478 (diff)
downloadmorph-b1ae48ff49dcbd34fb9a9a4eac62868b9195f9ef.tar.gz
BuildCommand: Validate multiple root morphologies
When you attempt to build a stratum or chunk, the ArtifactResolver can return multiple root artifacts, since the root source produces multiple artifacts. Rather than having the BuildCommand complain that there's multiple root artifacts, it now validates all the produced artifacts too, since that will validate the kinds of artifacts produced, and give a more useful error message, that you're trying to build a stratum or chunk directly. If all the produced artifacts validate, then an exception is raised to signal that it got multiple artifacts, when it only expected one.
-rw-r--r--morphlib/buildcommand.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py
index 4b3b2108..6485f510 100644
--- a/morphlib/buildcommand.py
+++ b/morphlib/buildcommand.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2011-2013 Codethink Limited
+# Copyright (C) 2011-2014 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
@@ -22,6 +22,14 @@ import tempfile
import morphlib
+class MultipleRootArtifactsError(morphlib.Error):
+
+ def __init__(self, artifacts):
+ self.msg = ('System build has multiple root artifacts: %r'
+ % [a.name for a in artifacts])
+ self.artifacts = artifacts
+
+
class BuildCommand(object):
'''High level logic for building.
@@ -142,7 +150,15 @@ class BuildCommand(object):
artifacts = ar.resolve_artifacts(srcpool)
self.app.status(msg='Computing build order', chatty=True)
- root_artifact = self._find_root_artifact(artifacts)
+ root_artifacts = self._find_root_artifacts(artifacts)
+ if len(root_artifacts) > 1:
+ # Validate root artifacts, since validation covers errors
+ # such as trying to build a chunk or stratum directly,
+ # and this is one cause for having multiple root artifacts
+ for root_artifact in root_artifacts:
+ self._validate_root_artifact(root_artifact)
+ raise MultipleRootArtifactsError(root_artifacts)
+ root_artifact = root_artifacts[0]
# Validate the root artifact here, since it's a costly function
# to finalise it, so any pre finalisation validation is better
@@ -231,8 +247,8 @@ class BuildCommand(object):
other.morphology['kind'],
wanted))
- def _find_root_artifact(self, artifacts):
- '''Find the root artifact among a set of artifacts in a DAG.
+ def _find_root_artifacts(self, artifacts):
+ '''Find all the root artifacts among a set of artifacts in a DAG.
It would be nice if the ArtifactResolver would return its results in a
more useful order to save us from needing to do this -- the root object
@@ -240,13 +256,7 @@ class BuildCommand(object):
'''
- maybe = set(artifacts)
- for a in artifacts:
- for dep in a.dependencies:
- if dep in maybe:
- maybe.remove(dep)
- assert len(maybe) == 1
- return maybe.pop()
+ return [a for a in artifacts if not a.dependents]
def build_in_order(self, root_artifact):
'''Build everything specified in a build order.'''