summaryrefslogtreecommitdiff
path: root/morph
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-01-12 14:30:38 +0000
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-01-16 11:34:39 +0000
commit0f14928fb700d14ed1ebb8675c26b263bf2bc58c (patch)
tree87ffb529e00cc58565235425a2aae7c3880f2a74 /morph
parent41ee528492db9bd41604311b100da5a871098b3a (diff)
downloadmorph-0f14928fb700d14ed1ebb8675c26b263bf2bc58c.tar.gz
Introduce the "show-dependencies" command and BuildDependencyGraph.
The "show-dependencies" command takes a series of build tuples and dumps the resulting dependency graph (including strata and chunks at the moment) to the standard output. It also dumps the resulting build order which is a list of groups. These groups indicate which chunks and strata can be built in parallel and are not dependent on each other.
Diffstat (limited to 'morph')
-rwxr-xr-xmorph41
1 files changed, 41 insertions, 0 deletions
diff --git a/morph b/morph
index f557baa9..360b9a7f 100755
--- a/morph
+++ b/morph
@@ -25,6 +25,7 @@ import logging
import os
import shutil
import tempfile
+import urlparse
import morphlib
@@ -149,6 +150,46 @@ class Morph(cliapp.Application):
self.msg('not testing %s %s (not a system)' %
(morph.kind, morph.name))
+ def cmd_show_dependencies(self, args):
+ '''Dumps the dependency tree of all input morphologies.'''
+
+ while len(args) >= 3:
+ # read the build tuple from the command line
+ repo, ref, filename = args[:3]
+ args = args[3:]
+
+ # resolve the URL to the repository
+ base_url = self.settings['git-base-url']
+ if not base_url.endswith('/'):
+ base_url += '/'
+ repo = urlparse.urljoin(base_url, repo)
+
+ # load the morphology corresponding to the build tuple
+ loader = morphlib.morphologyloader.MorphologyLoader(self.settings)
+ morphology = loader.load(repo, ref, filename)
+
+ # create a dependency graph for the morphology
+ graph = \
+ morphlib.builddependencygraph.BuildDependencyGraph(loader,
+ morphology)
+ graph.resolve()
+
+ # print the graph
+ self.output.write('dependency tree:\n')
+ for node in graph.nodes:
+ self.output.write(' %s\n' % node)
+ for dep in node.dependencies:
+ self.output.write(' -> %s\n' % dep)
+
+ # compute a build order from the graph
+ order = graph.build_order()
+ self.output.write('build order:\n')
+ for group in order:
+ self.output.write(' group:\n')
+ for morphology in group:
+ self.output.write(' %s (%s)\n' % (morphology.name,
+ morphology.kind))
+
def msg(self, msg):
'''Show a message to the user about what is going on.'''
logging.debug(msg)