summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmorph21
-rw-r--r--morphlib/builder.py40
-rw-r--r--morphlib/git.py12
3 files changed, 54 insertions, 19 deletions
diff --git a/morph b/morph
index 229d96b3..38e13ff2 100755
--- a/morph
+++ b/morph
@@ -380,6 +380,27 @@ class Morph(cliapp.Application):
self.output.write('%s\n' % msg)
self.output.flush()
+ def runcmd(self, argv, *args, **kwargs):
+ # check which msg function to use
+ msg = self.msg
+ if 'msg' in kwargs:
+ msg = kwargs['msg']
+ del kwargs['msg']
+
+ # convert the command line arguments into a string
+ commands = [argv] + list(args)
+ for command in commands:
+ if isinstance(command, list):
+ for i in xrange(0, len(command)):
+ command[i] = str(command[i])
+ commands = [' '.join(command) for command in commands]
+
+ # print the command line
+ msg('# %s' % ' | '.join(commands))
+
+ # run the command line
+ cliapp.Application.runcmd(self, argv, *args, **kwargs)
+
if __name__ == '__main__':
Morph().run()
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)