diff options
-rw-r--r-- | morphlib/bins.py | 3 | ||||
-rw-r--r-- | morphlib/builder.py | 47 | ||||
-rwxr-xr-x | tests/hello-chunk.script | 2 | ||||
-rwxr-xr-x | tests/hello-stratum.script | 2 |
4 files changed, 34 insertions, 20 deletions
diff --git a/morphlib/bins.py b/morphlib/bins.py index 993ae3ad..3381bc28 100644 --- a/morphlib/bins.py +++ b/morphlib/bins.py @@ -79,7 +79,8 @@ def create_chunk(rootdir, chunk_filename, regexps): include.remove(rootdir) for filename in reversed(include): if os.path.isdir(filename): - os.rmdir(filename) + if not os.listdir(filename): + os.rmdir(filename) else: os.remove(filename) diff --git a/morphlib/builder.py b/morphlib/builder.py index f44c2d88..4b2603bf 100644 --- a/morphlib/builder.py +++ b/morphlib/builder.py @@ -38,7 +38,6 @@ class BinaryBlob(object): self.settings = None self.msg = None self.cache_prefix = None - self.filename = None self.tempdir = None self.built = None @@ -51,6 +50,9 @@ class BinaryBlob(object): def build(self): raise NotImplemented() + def filename(self, name): + return '%s.%s.%s' % (self.cache_prefix, self.morph.kind, name) + def prepare_binary_metadata(self, **kwargs): '''Add metadata to a binary about to be built.''' @@ -132,8 +134,21 @@ class Chunk(BinaryBlob): self.prepare_binary_metadata() - self.msg('Creating binary for %s' % self.morph.name) - morphlib.bins.create_chunk(self.destdir, self.filename, ['.']) + if self.morph.chunks: + ret = {} + for chunk_name in self.morph.chunks: + patterns = self.morph.chunks[chunk_name] + self.msg('Creating chunk %s' % chunk_name) + filename = self.filename(chunk_name) + morphlib.bins.create_chunk(self.destdir, filename, patterns) + ret[chunk_name] = filename + # FIXME: check that destdir is empty + return ret + else: + self.msg('Creating chunk %s' % self.morph.name) + filename = self.filename(self.morph.name) + morphlib.bins.create_chunk(self.destdir, filename, ['.']) + return { self.morph.name: filename } class Stratum(BinaryBlob): @@ -152,7 +167,9 @@ class Stratum(BinaryBlob): morphlib.bins.unpack_chunk(filename, self.destdir) self.prepare_binary_metadata() self.msg('Creating binary for %s' % self.morph.name) - morphlib.bins.create_stratum(self.destdir, self.filename) + filename = self.filename(self.morph.name) + morphlib.bins.create_stratum(self.destdir, filename) + return { self.morph.name: filename } class System(BinaryBlob): @@ -251,8 +268,10 @@ append root=/dev/sda1 init=/bin/sh quiet rw self.ex.runv(['kpartx', '-d', image_name], as_root=True) # Move image file to cache. - self.ex.runv(['mv', image_name, self.filename]) + filename = self.filename(self.morph.name) + self.ex.runv(['mv', image_name, filename]) + return { self.morph.name: filename } class Builder(object): @@ -290,27 +309,21 @@ class Builder(object): blob.settings = self.settings blob.msg = self.msg blob.cache_prefix = self.cachedir.name(dict_key) - blob.filename = '%s.%s' % (blob.cache_prefix, morph.kind) blob.tempdir = self.tempdir - if os.path.exists(blob.filename): - self.msg('%s %s already cached at %s' % - (morph.kind, morph.name, blob.filename)) - return blob.filename - blob.built = {} for needed_repo, needed_ref, needed_name in blob.needs_built(): needed_filename = '%s.morph' % needed_name needed_cached = self.build(needed_repo, needed_ref, needed_filename) - blob.built[needed_name] = needed_cached + blob.built.update(needed_cached) self.msg('Building %s %s' % (morph.kind, morph.name)) - blob.build() - assert os.path.exists(blob.filename) - self.msg('%s %s cached at %s' % - (morph.kind, morph.name, blob.filename)) - return blob.filename + built = blob.build() + for filename in built: + self.msg('%s %s cached at %s' % + (morph.kind, built[filename], filename)) + return built def complete_dict_key(self, dict_key, name, repo, ref): '''Fill in default fields of a cache's dict key.''' diff --git a/tests/hello-chunk.script b/tests/hello-chunk.script index eb48f79f..5a9f7d59 100755 --- a/tests/hello-chunk.script +++ b/tests/hello-chunk.script @@ -23,7 +23,7 @@ tar -C "$DATADIR" -xf tests/hello-chunk.tar.gz ./morph --no-default-configs build hello master hello.morph \ --git-base-url "file://$DATADIR/" \ --cachedir="$DATADIR" -for chunk in "$DATADIR/"*.chunk +for chunk in "$DATADIR/"*.chunk.* do echo "$chunk:" tar -tf "$chunk" | LC_ALL=C sort | sed '/^\.\/./s:^\./::' diff --git a/tests/hello-stratum.script b/tests/hello-stratum.script index 40bebfa1..49127bf1 100755 --- a/tests/hello-stratum.script +++ b/tests/hello-stratum.script @@ -24,4 +24,4 @@ tar -C "$DATADIR" -xf tests/hello-chunk.tar.gz ./morph --no-default-configs build hello master hello-stratum.morph \ --git-base-url "file://$DATADIR/" \ --cachedir="$DATADIR" -tar -tf "$DATADIR/"*.stratum | LC_ALL=C sort | sed '/^\.\/./s:^\./::' +tar -tf "$DATADIR/"*.stratum.* | LC_ALL=C sort | sed '/^\.\/./s:^\./::' |