summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richardipsum@fastmail.co.uk>2014-10-05 20:23:58 +0100
committerRichard Ipsum <richard.ipsum@codethink.co.uk>2014-10-09 10:34:49 +0100
commit78e3b858bb15e5df66a3b1c7c286643726d45388 (patch)
treeeb33aef7333ecc8b2ca3485223fe1eaeeab3dfdb
parent6fdb886894dd320494fb386ecb6fe9f89ce874aa (diff)
downloadmorph-78e3b858bb15e5df66a3b1c7c286643726d45388.tar.gz
Tidy up artifact resolving
This patch started off as an attempt to address the comment in find_root_artifacts, though this patch doesn't impose an ordering on the list of artifacts as the comment suggested. The artifact resolver now returns a list of root artifacts which may make it easier to add multi-system builds to morph.
-rw-r--r--morphlib/artifactresolver.py6
-rw-r--r--morphlib/buildcommand.py52
2 files changed, 24 insertions, 34 deletions
diff --git a/morphlib/artifactresolver.py b/morphlib/artifactresolver.py
index 5deb25b7..8c8b37d0 100644
--- a/morphlib/artifactresolver.py
+++ b/morphlib/artifactresolver.py
@@ -52,7 +52,11 @@ class ArtifactResolver(object):
self._added_artifacts = None
self._source_pool = None
- def resolve_artifacts(self, source_pool):
+ def resolve_root_artifacts(self, source_pool): #pragma: no cover
+ return [a for a in self._resolve_artifacts(source_pool)
+ if not a.dependents]
+
+ def _resolve_artifacts(self, source_pool):
self._source_pool = source_pool
self._added_artifacts = set()
diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py
index edd2f0c5..c58466c2 100644
--- a/morphlib/buildcommand.py
+++ b/morphlib/buildcommand.py
@@ -142,6 +142,21 @@ class BuildCommand(object):
for spec in src.morphology['chunks']):
raise morphlib.Error('No non-bootstrap chunks found.')
+ def _compute_cache_keys(self, root_artifact):
+ arch = root_artifact.source.morphology['arch']
+ self.app.status(msg='Creating build environment for %(arch)s',
+ arch=arch, chatty=True)
+ build_env = self.new_build_env(arch)
+
+ self.app.status(msg='Computing cache keys', chatty=True)
+ ckc = morphlib.cachekeycomputer.CacheKeyComputer(build_env)
+
+ for source in set(a.source for a in root_artifact.walk()):
+ source.cache_key = ckc.compute_key(source)
+ source.cache_id = ckc.get_cache_id(source)
+
+ root_artifact.build_env = build_env
+
def resolve_artifacts(self, srcpool):
'''Resolve the artifacts that will be built for a set of sources'''
@@ -149,38 +164,20 @@ class BuildCommand(object):
ar = morphlib.artifactresolver.ArtifactResolver()
self.app.status(msg='Resolving artifacts', chatty=True)
- artifacts = ar.resolve_artifacts(srcpool)
+ root_artifacts = ar.resolve_root_artifacts(srcpool)
- self.app.status(msg='Computing build order', chatty=True)
- 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
+ # Validate root artifacts to give a more useful error message
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
- # done before that happens, but we also don't want to expose
- # the root artifact until it's finalised.
+ root_artifact = root_artifacts[0]
self.app.status(msg='Validating root artifact', chatty=True)
self._validate_root_artifact(root_artifact)
- arch = root_artifact.source.morphology['arch']
- self.app.status(msg='Creating build environment for %(arch)s',
- arch=arch, chatty=True)
- build_env = self.new_build_env(arch)
+ self._compute_cache_keys(root_artifact)
- self.app.status(msg='Computing cache keys', chatty=True)
- ckc = morphlib.cachekeycomputer.CacheKeyComputer(build_env)
- for source in set(a.source for a in artifacts):
- source.cache_key = ckc.compute_key(source)
- source.cache_id = ckc.get_cache_id(source)
-
- root_artifact.build_env = build_env
return root_artifact
def _validate_cross_morphology_references(self, srcpool):
@@ -250,17 +247,6 @@ class BuildCommand(object):
other.morphology['kind'],
wanted))
- 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
- is known already since that's the one the user asked us to build.
-
- '''
-
- return [a for a in artifacts if not a.dependents]
-
@staticmethod
def get_ordered_sources(artifacts):
ordered_sources = []