diff options
author | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-02-08 19:35:26 +0000 |
---|---|---|
committer | Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> | 2012-02-08 19:35:26 +0000 |
commit | bb262854bc53882a4d0c2e81e3e21a2ed1025986 (patch) | |
tree | 23dab6fcbd23aab200fb0aa7274e9e430296a910 /morphlib | |
parent | c163d09ab436b6c219dc17f371f29c35d0c1d0da (diff) | |
download | morph-bb262854bc53882a4d0c2e81e3e21a2ed1025986.tar.gz |
Extract chunk submodule repos into the build directory directly.
This change requires the latest version of cliapp to be installed.
Rather than creating an archive from the cached git repositories,
moving this tarball archive into the cache and then extracting it from
there into the build directory, we now directly extract the sources into
the build directory.
We also recursively extract all submodules into the corresponding paths
inside the build directory. (Recursing has not been tested yet,
however.)
Diffstat (limited to 'morphlib')
-rw-r--r-- | morphlib/builder.py | 40 | ||||
-rw-r--r-- | morphlib/git.py | 12 |
2 files changed, 33 insertions, 19 deletions
diff --git a/morphlib/builder.py b/morphlib/builder.py index a9004a33..1b2afa44 100644 --- a/morphlib/builder.py +++ b/morphlib/builder.py @@ -55,7 +55,8 @@ def ldconfig(ex, rootdir): class BlobBuilder(object): - def __init__(self, blob): + def __init__(self, app, blob): + self.app = app self.blob = blob # The following MUST get set by the caller. @@ -219,7 +220,7 @@ class ChunkBuilder(BlobBuilder): self.ex = morphlib.execute.Execute(self.builddir, self.msg) self.setup_env() - self.create_source_and_tarball() + self.prepare_build_directory() os.mkdir(self.destdir) if self.blob.morph.build_system: @@ -305,19 +306,21 @@ class ChunkBuilder(BlobBuilder): for key in sorted(self.ex.env): logging.debug(' %s=%s' % (key, self.ex.env[key])) - def create_source_and_tarball(self): - self.msg('Creating source tree and tarball') - with self.build_watch('create-source-tarball'): - self.dump_memory_profile('before creating source and tarball ' - 'for chunk') - tarball = self.cache_prefix + '.src.tar' - morphlib.git.export_sources(self.blob.morph.treeish, tarball, - msg=self.msg) - self.dump_memory_profile('after exporting sources') - os.mkdir(self.builddir) - self.ex.runv(['tar', '-C', self.builddir, '-xf', tarball]) - self.dump_memory_profile('after creating source and tarball ' - 'for chunk') + def prepare_build_directory(self): + os.mkdir(self.builddir) + + def extract_treeish(treeish, destdir): + self.msg('Extracting %s into %s' % + (treeish.repo, self.builddir)) + + morphlib.git.archive_and_extract( + self.app, treeish, destdir, self.msg) + + for submodule in treeish.submodules: + directory = os.path.join(destdir, submodule.path) + extract_treeish(submodule.treeish, directory) + + extract_treeish(self.blob.morph.treeish, self.builddir) def build_using_buildsystem(self): bs_name = self.blob.morph.build_system @@ -515,6 +518,7 @@ class Builder(object): def __init__(self, tempdir, app, morph_loader, source_manager): self.tempdir = tempdir + self.app = app self.real_msg = app.msg self.settings = app.settings self.dump_memory_profile = app.dump_memory_profile @@ -619,11 +623,11 @@ class Builder(object): def create_blob_builder(self, blob): if isinstance(blob, morphlib.blobs.Stratum): - builder = StratumBuilder(blob) + builder = StratumBuilder(self.app, blob) elif isinstance(blob, morphlib.blobs.Chunk): - builder = ChunkBuilder(blob) + builder = ChunkBuilder(self.app, blob) elif isinstance(blob, morphlib.blobs.System): - builder = SystemBuilder(blob) + builder = SystemBuilder(self.app, blob) else: raise TypeError('Blob %s has unknown type %s' % (str(blob), type(blob))) diff --git a/morphlib/git.py b/morphlib/git.py index e64fecb9..0b774229 100644 --- a/morphlib/git.py +++ b/morphlib/git.py @@ -87,7 +87,11 @@ class Treeish(object): binascii.unhexlify(ref) ex = morphlib.execute.Execute(self.repo, self.msg) ex.runv(['git', 'rev-list', '--no-walk', ref]) - self.sha1=ref + self.sha1 = ref + # NOTE this is a hack, but we really don't want to add + # conditionals all over the place in order to handle + # situations where we only have a .sha1, do we? + self.ref = ref except (TypeError, morphlib.execute.CommandFailure): raise InvalidReferenceError(self.original_repo, ref) @@ -238,3 +242,9 @@ def add_remote(gitdir, name, url, msg=logging.debug): def update_remote(gitdir, name, msg=logging.debug): ex = morphlib.execute.Execute(gitdir, msg=msg) return ex.runv(['git', 'remote', 'update', name]) + +def archive_and_extract(app, treeish, destdir, msg=logging.debug): + return app.runcmd(['git', 'archive', treeish.ref], + ['tar', '-C', destdir, '-xv'], + cwd=treeish.repo, + msg=msg) |