summaryrefslogtreecommitdiff
path: root/morphlib
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-09-29 16:18:24 +0100
committerLars Wirzenius <liw@liw.fi>2011-09-29 16:18:24 +0100
commit48e7ff4982d62413be05f3cde694afadd162872a (patch)
tree035db0d4b3a8a3087c476ad33235a7dca2897ec4 /morphlib
parent3995c472c744010385af43e2ef9a82a23beeba0f (diff)
downloadmorph-48e7ff4982d62413be05f3cde694afadd162872a.tar.gz
Build strata recursively.
If a chunk is missing, it will be built.
Diffstat (limited to 'morphlib')
-rw-r--r--morphlib/builder.py63
-rw-r--r--morphlib/execute.py2
-rw-r--r--morphlib/execute_tests.py3
3 files changed, 63 insertions, 5 deletions
diff --git a/morphlib/builder.py b/morphlib/builder.py
index 05373ad2..328ec365 100644
--- a/morphlib/builder.py
+++ b/morphlib/builder.py
@@ -16,10 +16,28 @@
import logging
import os
+import StringIO
+import urlparse
import morphlib
+class NoMorphs(Exception):
+
+ def __init__(self, repo, ref):
+ Exception.__init__(self,
+ 'Cannot find any morpologies at %s:%s' %
+ (repo, ref))
+
+
+class TooManyMorphs(Exception):
+
+ def __init__(self, repo, ref, morphs):
+ Exception.__init__(self,
+ 'Too many morphologies at %s:%s: %s' %
+ (repo, ref, ', '.join(morphs)))
+
+
class Builder(object):
'''Build binary objects for Baserock.
@@ -49,6 +67,7 @@ class Builder(object):
def build_chunk(self, morph, repo, ref):
'''Build a chunk from a morphology.'''
logging.debug('Building chunk')
+ self.msg('Building chunk %s' % morph.name)
filename = self.get_cached_name('chunk', repo, ref)
if os.path.exists(filename):
self.msg('Chunk already exists: %s %s' % (repo, ref))
@@ -68,12 +87,12 @@ class Builder(object):
'''Export sources from git into the ``self._build`` directory.'''
logging.debug('Creating build tree at %s' % self._build)
+ os.mkdir(self._build)
tarball = self.tempdir.join('sources.tar')
self.ex.runv(['git', 'archive',
'--output', tarball,
'--remote', repo,
ref])
- os.mkdir(self._build)
self.ex.runv(['tar', '-C', self._build, '-xf', tarball])
os.remove(tarball)
@@ -90,11 +109,21 @@ class Builder(object):
def build_stratum(self, morph):
'''Build a stratum from a morphology.'''
+
+ for chunk_name, source in morph.sources.iteritems():
+ repo = source['repo']
+ ref = source['ref']
+ chunk_morph = self.get_morph_from_git(repo, ref)
+ self.build_chunk(chunk_morph, repo, ref)
+
os.mkdir(self._inst)
self.ex = morphlib.execute.Execute(self.tempdir.dirname, self.msg)
for chunk_name in morph.sources:
- chunk_repo = self.settings['chunk-repo']
- chunk_ref = self.settings['chunk-ref']
+ source = morph.sources[chunk_name]
+ chunk_repo = source['repo']
+ chunk_ref = source['ref']
+ logging.debug('Looking for chunk at repo=%s ref=%s' %
+ (chunk_repo, chunk_ref))
filename = self.get_cached_name('chunk', chunk_repo, chunk_ref)
self.unpack_chunk(filename)
self.create_stratum(morph)
@@ -140,9 +169,35 @@ class Builder(object):
def get_git_commit_id(self, repo, ref):
'''Return the full SHA-1 commit id for a repo+ref.'''
if repo and ref:
- ex = morphlib.execute.Execute(repo, self.msg)
+ path = self.get_repo_dir(repo)
+ ex = morphlib.execute.Execute(path, self.msg)
out = ex.runv(['git', 'rev-list', '-n1', ref])
return out.strip()
else:
return ''
+ def get_morph_from_git(self, repo, ref):
+ '''Return a morphology from a git repository.'''
+ # FIXME: This implementation assume a local repo.
+
+ path = self.get_repo_dir(repo)
+ ex = morphlib.execute.Execute(path, self.msg)
+ out = ex.runv(['git', 'ls-tree', '--name-only', '-z', ref])
+ names = [x for x in out.split('\0') if x]
+ morphs = [x for x in names if x.endswith('.morph')]
+ if len(morphs) == 0:
+ raise NoMorphs(repo, ref)
+ if len(morphs) > 1:
+ raise TooManyMorphs(repo, ref, morphs)
+ out = ex.runv(['git', 'cat-file', 'blob', '%s:%s' % (ref, morphs[0])])
+
+ f = StringIO.StringIO(out)
+ f.name = morphs[0]
+ morph = morphlib.morphology.Morphology(f,
+ self.settings['git-base-url'])
+ return morph
+
+ def get_repo_dir(self, repo):
+ scheme, netlock, path, params, query, frag = urlparse.urlparse(repo)
+ return path
+
diff --git a/morphlib/execute.py b/morphlib/execute.py
index 9a279591..cd2cc79a 100644
--- a/morphlib/execute.py
+++ b/morphlib/execute.py
@@ -74,7 +74,7 @@ class Execute(object):
self.msg('# %s' % ' '.join(argv))
p = subprocess.Popen(argv, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
+ stderr=subprocess.PIPE, cwd=self.dirname)
out, err = p.communicate()
logging.debug('Exit code: %d' % p.returncode)
diff --git a/morphlib/execute_tests.py b/morphlib/execute_tests.py
index 8a9f9bf4..dffc5a7f 100644
--- a/morphlib/execute_tests.py
+++ b/morphlib/execute_tests.py
@@ -49,3 +49,6 @@ class ExecuteTests(unittest.TestCase):
self.assertRaises(morphlib.execute.CommandFailure,
self.e.runv, ['false'])
+ def test_runv_sets_working_directory(self):
+ self.assertEqual(self.e.runv(['pwd']), '/\n')
+