summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xscripts/find-artifacts96
-rwxr-xr-xtests.branching/add-then-edit.script61
-rwxr-xr-xtests.branching/add-then-edit.setup40
-rw-r--r--tests.branching/add-then-edit.stdout1
4 files changed, 122 insertions, 76 deletions
diff --git a/scripts/find-artifacts b/scripts/find-artifacts
index bd2c02c8..bf6425ea 100755
--- a/scripts/find-artifacts
+++ b/scripts/find-artifacts
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright (C) 2011-2012 Codethink Limited
+# Copyright (C) 2011-2013 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -31,86 +31,27 @@ path = os.path.dirname(os.path.dirname(__file__))
sys.path.append(path)
import morphlib
-# MountableImage yanked from the TrebuchetPlugin and modified slightly
-class MountableImage(object):
- '''Mountable image (deals with decompression).
-
- Note, this is a read-only mount in the sense that the decompressed
- image is not then recompressed after, instead any changes are discarded.
-
- '''
- def __init__(self, app, artifact_path):
- self.app = app
- self.artifact_path = artifact_path
-
- def setup(self, path):
- (tempfd, self.temp_path) = \
- tempfile.mkstemp(dir=self.app.settings['tempdir'])
-
- try:
- with os.fdopen(tempfd, "wb") as outfh:
- infh = gzip.open(path, "rb")
- morphlib.util.copyfileobj(infh, outfh)
- infh.close()
- except:
- os.unlink(self.temp_path)
- raise
- part = morphlib.fsutils.setup_device_mapping(self.app.runcmd,
- self.temp_path)
- mount_point = tempfile.mkdtemp(dir=self.app.settings['tempdir'])
- morphlib.fsutils.mount(self.app.runcmd, part, mount_point)
- self.mount_point = mount_point
- return mount_point
-
- def cleanup(self, path, mount_point):
- try:
- morphlib.fsutils.unmount(self.app.runcmd, mount_point)
- except:
- pass
- try:
- morphlib.fsutils.undo_device_mapping(self.app.runcmd, path)
- except:
- pass
- try:
- os.rmdir(mount_point)
- os.unlink(path)
- except:
- pass
-
- def __enter__(self):
- return self.setup(self.artifact_path)
-
- def __exit__(self, exctype, excvalue, exctraceback):
- self.cleanup(self.temp_path, self.mount_point)
-
-
-class FindArtifacts(cliapp.Application):
-
- def add_settings(self):
- self.settings.string(['cachedir'], 'The directory morph writes its '
- 'cache to')
- self.settings.string(['tempdir'], 'A temporary directory to mount the '
- 'system image in')
+class FindArtifacts(morphlib.app.Morph):
def process_args(self, args):
artifacts_dir = os.path.join(self.settings['cachedir'], 'artifacts')
# args[0] is the path to the built image.
- # Mount the image
- mount_point = None
- with MountableImage(self, args[0]) as mount_point:
- # For each meta file:
- metadir = os.path.join(mount_point, 'factory-run', 'baserock')
- metaglob = os.path.join(metadir, '*.meta')
- for metafile in glob.iglob(metaglob):
- metafilepath = os.path.join(metadir, metafile)
- # Read the file as JSON and extract the kind and cache-key
- with open(metafilepath) as openedmetafile:
- metajson = json.load(openedmetafile)
- cache_key = metajson['cache-key']
-
- # Grab every file in the artifact cache which matches the
- # cache-key
+ artifact = args[0]
+
+ def find_artifacts(dirname):
+ metadirs = [
+ os.path.join(dirname, 'factory', 'baserock'),
+ os.path.join(dirname, 'baserock')
+ ]
+ existing_metadirs = [x for x in metadirs if os.path.isdir(x)]
+ if not existing_metadirs:
+ raise NotASystemArtifactError(artifact)
+ metadir = existing_metadirs[0]
+ for basename in glob.glob(os.path.join(metadir, '*.meta')):
+ metafile = os.path.join(metadir, basename)
+ metadata = json.load(open(metafile))
+ cache_key = metadata['cache-key']
artifact_glob = os.path.join(artifacts_dir, cache_key) + '*'
found_artifacts = glob.glob(artifact_glob)
if not found_artifacts:
@@ -120,4 +61,7 @@ class FindArtifacts(cliapp.Application):
for cached_file in found_artifacts:
self.output.write(cached_file + "\n")
+ morphlib.bins.call_in_artifact_directory(self, artifact,
+ find_artifacts)
+
FindArtifacts().run()
diff --git a/tests.branching/add-then-edit.script b/tests.branching/add-then-edit.script
new file mode 100755
index 00000000..40ee7161
--- /dev/null
+++ b/tests.branching/add-then-edit.script
@@ -0,0 +1,61 @@
+#!/bin/sh
+#
+# Copyright (C) 2013 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+## Test the workflow of adding a new chunk to a stratum then editing it
+
+set -eu
+
+cd "$DATADIR/workspace"
+"$SRCDIR/scripts/test-morph" init
+"$SRCDIR/scripts/test-morph" branch test:morphs "me/add-then-edit"
+
+cd "me/add-then-edit"
+
+# add a chunk
+cd test:morphs
+
+## Sub-optimally, to alter the stratum, you have to `morph edit` it first
+"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum
+
+git apply <<'EOF'
+diff --git a/hello-stratum.morph b/hello-stratum.morph
+index 3b7be17..c79a9af 100644
+--- a/hello-stratum.morph
++++ b/hello-stratum.morph
+@@ -7,6 +7,12 @@
+ "repo": "test:hello",
+ "ref": "master",
+ "build-depends": []
++ },
++ {
++ "name": "goodbye",
++ "repo": "test:goodbye",
++ "ref": "master",
++ "build-depends": []
+ }
+ ]
+ }
+EOF
+
+"$SRCDIR/scripts/test-morph" edit hello-system hello-stratum goodbye
+
+# check whether the stratum still contains the goodbye chunk
+grep -qFe goodbye hello-stratum.morph
+
+# check whether edit has cloned the repository to the right branch
+git --git-dir="../test:goodbye/.git" rev-parse --abbrev-ref HEAD
diff --git a/tests.branching/add-then-edit.setup b/tests.branching/add-then-edit.setup
new file mode 100755
index 00000000..7dbe28c0
--- /dev/null
+++ b/tests.branching/add-then-edit.setup
@@ -0,0 +1,40 @@
+#!/bin/sh
+# Copyright (C) 2013 Codethink Limited
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+set -eu
+
+# Create goodbye chunk
+mkdir "$DATADIR/goodbye"
+cd "$DATADIR/goodbye"
+
+cat >goodbye <<'EOF'
+#!/bin/sh
+echo goodbye
+EOF
+chmod +x goodbye
+
+cat >goodbye.morph <<'EOF'
+{
+ "name": "goodbye",
+ "kind": "chunk",
+ "install-commands": [
+ "install goodbye \"$DESTDIR$PREFIX/bin/goodbye\""
+ ]
+}
+EOF
+git init .
+git add goodbye.morph goodbye
+git commit -m "Initial commit"
diff --git a/tests.branching/add-then-edit.stdout b/tests.branching/add-then-edit.stdout
new file mode 100644
index 00000000..e0950ab5
--- /dev/null
+++ b/tests.branching/add-then-edit.stdout
@@ -0,0 +1 @@
+me/add-then-edit