diff options
author | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-04-17 12:15:23 +0100 |
---|---|---|
committer | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-04-17 12:15:23 +0100 |
commit | f20588b4b83195a34ac6aac8066589c6f883218f (patch) | |
tree | 55dbace9a04497a1b339efbcde3c60ba4b3e7aca | |
parent | 43fe89a63bb797129452fb690fd442c78d61805b (diff) | |
download | morph-f20588b4b83195a34ac6aac8066589c6f883218f.tar.gz |
Add _create_source_pool() method and update show-dependencies.
The Morph#_create_source_pool method takes a repo cache and a repo, ref,
filename triplet and resolves all the sources involved in a potential
build of this triplet.
-rwxr-xr-x | morph | 98 | ||||
-rw-r--r-- | tests/show-dependencies.stdout | 4 |
2 files changed, 56 insertions, 46 deletions
@@ -141,6 +141,37 @@ class Morph(cliapp.Application): yield args[0], args[1], args[2] args = args[3:] + def _create_source_pool(self, repo_cache, reponame, ref, filename): + pool = morphlib.sourcepool.SourcePool() + + queue = collections.deque([(reponame, ref, filename)]) + while queue: + reponame, ref, filename = queue.popleft() + + if self.settings['no-git-update']: + repo = repo_cache.get_repo(reponame) + else: + repo = repo_cache.cache_repo(reponame) + repo.update() + absref = repo.resolve_ref(ref) + text = repo.cat(absref, filename) + morphology = morphlib.morph2.Morphology(text) + if morphology['kind'] == 'system': + for stratum in morphology['strata']: + queue.append((reponame, ref, '%s.morph' % stratum)) + elif morphology['kind'] == 'stratum': + if morphology['build-depends']: + for stratum in morphology['build-depends']: + queue.append((reponame, ref, '%s.morph' % stratum)) + for x in morphology['sources']: + queue.append((x['repo'], x['ref'], + '%s.morph' % x['morph'])) + source = morphlib.source.Source(reponame, ref, absref, + morphology, filename) + pool.add(source) + + return pool + def cmd_build(self, args): '''Build a binary from a morphology. @@ -189,8 +220,6 @@ class Morph(cliapp.Application): def cmd_show_dependencies(self, args): '''Dumps the dependency tree of all input morphologies.''' - pool = morphlib.sourcepool.SourcePool() - if not os.path.exists(self.settings['cachedir']): os.mkdir(self.settings['cachedir']) cachedir = os.path.join(self.settings['cachedir'], 'gits') @@ -200,48 +229,29 @@ class Morph(cliapp.Application): cachedir, baseurls, bundle_base_url) # traverse the morphs to list all the sources - queue = collections.deque(self._itertriplets(args)) - while queue: - reponame, ref, filename = queue.popleft() - if self.settings['no-git-update']: - repo = cache.get_repo(reponame) - else: - repo = cache.cache_repo(reponame) - repo.update() - absref = repo.resolve_ref(ref) - text = repo.cat(absref, filename) - morphology = morphlib.morph2.Morphology(text) - if morphology['kind'] == 'system': - for stratum in morphology['strata']: - queue.append((reponame, ref, '%s.morph' % stratum)) - elif morphology['kind'] == 'stratum': - if morphology['build-depends']: - for stratum in morphology['build-depends']: - queue.append((reponame, ref, '%s.morph' % stratum)) - for x in morphology['sources']: - queue.append((x['repo'], x['ref'], - '%s.morph' % x['morph'])) - source = morphlib.source.Source(reponame, ref, absref, - morphology, filename) - pool.add(source) - - env = morphlib.buildenvironment.BuildEnvironment(self.settings) - computer = morphlib.cachekeycomputer.CacheKeyComputer(env) - resolver = morphlib.artifactresolver.ArtifactResolver(computer) - artifacts = resolver.resolve_artifacts(pool) - - self.output.write('dependency graph:\n') - for artifact in sorted(artifacts, key=str): - self.output.write(' %s\n' % artifact) - for dependency in sorted(artifact.dependencies, key=str): - self.output.write(' -> %s\n' % dependency) - - order = morphlib.buildorder.BuildOrder(artifacts) - self.output.write('build order:\n') - for group in order.groups: - self.output.write(' group:\n') - for artifact in group: - self.output.write(' %s\n' % artifact) + for repo, ref, filename in self._itertriplets(args): + repo, ref, filename = args[:3] + pool = self._create_source_pool(cache, repo, ref, filename) + + env = morphlib.buildenvironment.BuildEnvironment(self.settings) + computer = morphlib.cachekeycomputer.CacheKeyComputer(env) + resolver = morphlib.artifactresolver.ArtifactResolver(computer) + artifacts = resolver.resolve_artifacts(pool) + + self.output.write('dependency graph for %s|%s|%s:\n' % + (repo, ref, filename)) + for artifact in sorted(artifacts, key=str): + self.output.write(' %s\n' % artifact) + for dependency in sorted(artifact.dependencies, key=str): + self.output.write(' -> %s\n' % dependency) + + order = morphlib.buildorder.BuildOrder(artifacts) + self.output.write('build order for %s|%s|%s:\n' % + (repo, ref, filename)) + for group in order.groups: + self.output.write(' group:\n') + for artifact in group: + self.output.write(' %s\n' % artifact) def cmd_update_gits(self, args): '''Update cached git repositories. diff --git a/tests/show-dependencies.stdout b/tests/show-dependencies.stdout index 7931ae71..7efd76ca 100644 --- a/tests/show-dependencies.stdout +++ b/tests/show-dependencies.stdout @@ -1,4 +1,4 @@ -dependency graph: +dependency graph for test-repo|master|xfce-core.morph: test-repo|master|cairo.morph|cairo test-repo|master|dbus-glib.morph|dbus-glib -> test-repo|master|dbus.morph|dbus @@ -96,7 +96,7 @@ dependency graph: -> test-repo|master|gtk-stack.morph|gtk-stack -> test-repo|master|libxfce4ui.morph|libxfce4ui -> test-repo|master|xfconf.morph|xfconf -build order: +build order for test-repo|master|xfce-core.morph: group: test-repo|master|freetype.morph|freetype test-repo|master|fontconfig.morph|fontconfig |