summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Coldrick <adam.coldrick@codethink.co.uk>2014-07-03 13:39:20 +0000
committerAdam Coldrick <adam.coldrick@codethink.co.uk>2014-07-03 17:59:14 +0000
commit8f16426f64107169d7387b8262b072089f14e4b0 (patch)
treef91954488cd6dd65c26bde285a81142fa7cea0e7
parent63751d06e6d7fd240c69f127fa06d811f3dd438d (diff)
downloadmorph-8f16426f64107169d7387b8262b072089f14e4b0.tar.gz
Adapt traverse_morphs to be able to load chunk morphologies from definitions
This commit adapts the traverse_morphs code to handle keeping track of both the morphology location and the source location for chunks by loading morphologies from a given "morphology_repo" and "morphology_ref" rather than the source repo and ref. The repo and ref of the source is still passed and used as the reference for the chunk and given to the Source object in the source pool.
-rw-r--r--morphlib/app.py76
1 files changed, 54 insertions, 22 deletions
diff --git a/morphlib/app.py b/morphlib/app.py
index fd1536a9..23dcd608 100644
--- a/morphlib/app.py
+++ b/morphlib/app.py
@@ -289,9 +289,11 @@ class Morph(cliapp.Application):
def create_source_pool(self, lrc, rrc, triplet):
pool = morphlib.sourcepool.SourcePool()
- def add_to_pool(reponame, ref, filename, absref, tree, morphology):
+ def add_to_pool(reponame, ref, filename, absref, tree, morphology,
+ morphology_repo, morphology_ref):
source = morphlib.source.Source(reponame, ref, absref, tree,
- morphology, filename)
+ morphology, morphology_repo,
+ morphology_ref, filename)
pool.add(source)
self.traverse_morphs([triplet], lrc, rrc,
@@ -345,47 +347,77 @@ class Morph(cliapp.Application):
resolved_morphologies = {}
while queue:
- reponame, ref, filename = queue.popleft()
- update_repo = update and reponame not in updated_repos
-
- # Resolve the (repo, ref) reference, cache result.
- reference = (reponame, ref)
+ # Get the source and morphology repo names
+ reference = queue.popleft()
+ if len(reference) == 3:
+ source_repo, source_ref, filename = reference
+ morphology_repo = source_repo
+ morphology_ref = source_ref
+ elif len(reference) == 5:
+ source_repo, source_ref, filename, morphology_repo, \
+ morphology_ref = reference
+ else:
+ raise morphlib.Error('malformed morphology reference '
+ 'encountered when traversing '
+ 'morphologies.')
+ update_source_repo = update and source_repo not in updated_repos
+ update_morphology_repo = update and morphology_repo not in \
+ updated_repos
+
+ # Resolve the (source_repo, source_ref) reference, cache result.
+ reference = (source_repo, source_ref)
if not reference in resolved_refs:
resolved_refs[reference] = self.resolve_ref(
- lrc, rrc, reponame, ref, update_repo)
- absref, tree = resolved_refs[reference]
+ lrc, rrc, source_repo, source_ref, update_source_repo)
+ source_absref, source_tree = resolved_refs[reference]
+ updated_repos.add(source_repo)
- updated_repos.add(reponame)
+ # Resolve the (morphology_repo, morphology_ref) reference,
+ # cache result.
+ reference = (morphology_repo, morphology_ref)
+ if not reference in resolved_refs:
+ resolved_refs[reference] = self.resolve_ref(
+ lrc, rrc, morphology_repo,
+ morphology_ref, update_morphology_repo)
+ morphology_absref, morphology_tree = resolved_refs[reference]
+ updated_repos.add(morphology_repo)
# Fetch the (repo, ref, filename) morphology, cache result.
- reference = (reponame, absref, filename)
+ reference = (morphology_repo, morphology_absref, filename)
if not reference in resolved_morphologies:
resolved_morphologies[reference] = \
- morph_factory.get_morphology(reponame, absref, filename)
+ morph_factory.get_morphology(
+ morphology_repo, morphology_absref, filename)
morphology = resolved_morphologies[reference]
- visit(reponame, ref, filename, absref, tree, morphology)
+ visit(source_repo, source_ref, filename, source_absref,
+ source_tree, morphology, morphology_repo, morphology_ref)
if morphology['kind'] == 'cluster':
raise cliapp.AppException(
"Cannot build a morphology of type 'cluster'.")
elif morphology['kind'] == 'system':
queue.extend(
- (s.get('repo') or reponame,
- s.get('ref') or ref,
+ (s.get('repo') or source_repo,
+ s.get('ref') or source_ref,
morphlib.util.sanitise_morphology_path(s['morph']))
for s in morphology['strata'])
elif morphology['kind'] == 'stratum':
if morphology['build-depends']:
queue.extend(
- (s.get('repo') or reponame,
- s.get('ref') or ref,
+ (s.get('repo') or source_repo,
+ s.get('ref') or source_ref,
morphlib.util.sanitise_morphology_path(s['morph']))
for s in morphology['build-depends'])
- queue.extend(
- (c['repo'],
- c['ref'],
- morphlib.util.sanitise_morphology_path(c['morph']))
- for c in morphology['chunks'])
+ for c in morphology['chunks']:
+ path = morphlib.util.sanitise_morphology_path(c['morph'])
+ chunk_morphology_repo = morphology_repo
+ chunk_morphology_ref = morphology_ref
+ if c['morph'] != path:
+ chunk_morphology_repo = c['repo']
+ chunk_morphology_ref = c['ref']
+ queue.append(
+ (c['repo'], c['ref'], path,
+ chunk_morphology_repo, chunk_morphology_ref))
def cache_repo_and_submodules(self, cache, url, ref, done):
subs_to_process = set()