summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--morphlib/builder.py59
-rwxr-xr-xtests/build-chunk.script2
-rwxr-xr-xtests/build-stratum.script2
-rwxr-xr-xtests/build-system.script2
-rwxr-xr-xtests/missing-ref.script2
-rwxr-xr-xtests/rebuild-cached-stratum.script64
-rw-r--r--tests/rebuild-cached-stratum.stdout8
-rwxr-xr-xtests/setup_once36
8 files changed, 140 insertions, 35 deletions
diff --git a/morphlib/builder.py b/morphlib/builder.py
index 86785e68..4f7dc432 100644
--- a/morphlib/builder.py
+++ b/morphlib/builder.py
@@ -46,9 +46,6 @@ class BinaryBlob(object):
# Stopwatch to measure build times
self.build_watch = morphlib.stopwatch.Stopwatch()
- def dict_key(self):
- return {}
-
def needs_built(self):
return []
@@ -485,10 +482,9 @@ class Builder(object):
raise Exception('Unknown kind of morphology: %s' % morph.kind)
self.dump_memory_profile('after creating Chunk/Stratum/...')
- dict_key = blob.dict_key()
- self.complete_dict_key(dict_key, morph.name, repo, ref)
- logging.debug('completed dict_key:\n%s' % repr(dict_key))
- self.dump_memory_profile('after completing cache key')
+ cache_id = self.get_cache_id(repo, ref, filename)
+ logging.debug('cachae id: %s' % repr(cache_id))
+ self.dump_memory_profile('after computing cache id')
blob.builddir = self.tempdir.join('%s.build' % morph.name)
blob.destdir = self.tempdir.join('%s.inst' % morph.name)
@@ -497,7 +493,7 @@ class Builder(object):
os.mkdir(blob.staging)
blob.settings = self.settings
blob.msg = self.msg
- blob.cache_prefix = self.cachedir.name(dict_key)
+ blob.cache_prefix = self.cachedir.name(cache_id)
blob.tempdir = self.tempdir
blob.dump_memory_profile = self.dump_memory_profile
@@ -553,19 +549,6 @@ class Builder(object):
self.msg('Unpacking chunk %s into staging' % chunk_name)
morphlib.bins.unpack_binary(chunk_filename, staging_dir)
- def complete_dict_key(self, dict_key, name, repo, ref):
- '''Fill in default fields of a cache's dict key.'''
-
- if repo and ref:
- abs_ref = morphlib.git.get_commit_id(repo, ref)
- else:
- abs_ref = ''
-
- dict_key['name'] = name
- dict_key['arch'] = morphlib.util.arch()
- dict_key['repo'] = repo
- dict_key['ref'] = abs_ref
-
def get_morph_from_git(self, repo, ref, filename):
morph_text = morphlib.git.get_morph_text(repo, ref, filename)
f = StringIO.StringIO(morph_text)
@@ -574,3 +557,37 @@ class Builder(object):
self.settings['git-base-url'])
return morph
+ def get_cache_id(self, repo, ref, morph_filename):
+ logging.debug('get_cache_id(%s, %s, %s)' %
+ (repo, ref, morph_filename))
+ morph = self.get_morph_from_git(repo, ref, morph_filename)
+ if morph.kind == 'chunk':
+ kids = []
+ elif morph.kind == 'stratum':
+ kids = []
+ for source in morph.sources:
+ kid_repo = source['repo']
+ kid_ref = source['ref']
+ kid_filename = (source['morph']
+ if 'morph' in source
+ else source['name'])
+ kid_filename = '%s.morph' % kid_filename
+ kid_cache_id = self.get_cache_id(kid_repo, kid_ref,
+ kid_filename)
+ kids.append(kid_cache_id)
+ elif morph.kind == 'system':
+ kids = []
+ for stratum in morph.strata:
+ kid_filename = '%s.morph' % stratum
+ kid_cache_id = self.get_cache_id(repo, ref, kid_filename)
+ kids.append(kid_cache_id)
+ else:
+ raise NotImplementedError('unknown morph kind %s' % morph.kind)
+ dict_key = {
+ 'name': morph.name,
+ 'arch': morphlib.util.arch(),
+ 'ref': morphlib.git.get_commit_id(repo, ref),
+ 'kids': ''.join(self.cachedir.key(k) for k in kids),
+ }
+ return dict_key
+
diff --git a/tests/build-chunk.script b/tests/build-chunk.script
index a4e1fef6..01fbf8f5 100755
--- a/tests/build-chunk.script
+++ b/tests/build-chunk.script
@@ -21,7 +21,7 @@ set -e
cache="$DATADIR/build-chunk-cache"
log="$DATADIR/build-chunk-morph.log"
-./morph --no-default-configs build repo farrokh hello.morph \
+./morph --no-default-configs build chunk-repo farrokh hello.morph \
--git-base-url="file://$DATADIR" \
--cachedir="$cache" --keep-path --no-distcc \
--log="$log" || cat "$log" 1>&2
diff --git a/tests/build-stratum.script b/tests/build-stratum.script
index bd938860..dadda81f 100755
--- a/tests/build-stratum.script
+++ b/tests/build-stratum.script
@@ -21,7 +21,7 @@ set -e
cache="$DATADIR/build-stratum-cache"
log="$DATADIR/build-stratum-morph.log"
-./morph --no-default-configs build repo farrokh hello-stratum.morph \
+./morph --no-default-configs build morphs-repo master hello-stratum.morph \
--git-base-url="file://$DATADIR" \
--cachedir="$cache" --keep-path --no-distcc \
--log="$log" || cat "$log" 1>&2
diff --git a/tests/build-system.script b/tests/build-system.script
index c96662cc..1553b85a 100755
--- a/tests/build-system.script
+++ b/tests/build-system.script
@@ -21,7 +21,7 @@ set -e
cache="$DATADIR/build-system-cache"
log="$DATADIR/build-system-morph.log"
-./morph --no-default-configs build repo farrokh hello-system.morph \
+./morph --no-default-configs build morphs-repo master hello-system.morph \
--git-base-url="file://$DATADIR" \
--cachedir="$cache" --keep-path --no-distcc \
--log="$log" || cat "$log" 1>&2
diff --git a/tests/missing-ref.script b/tests/missing-ref.script
index 978f50fa..0c4f29f7 100755
--- a/tests/missing-ref.script
+++ b/tests/missing-ref.script
@@ -20,7 +20,7 @@
set -e
cache="$DATADIR/build-chunk-cache"
-./morph --no-default-configs build repo non-existent-branch hello.morph \
+./morph --no-default-configs build chunk-repo non-existent-branch hello.morph \
--git-base-url="file://$DATADIR" \
--cachedir="$cache" --keep-path --no-distcc
diff --git a/tests/rebuild-cached-stratum.script b/tests/rebuild-cached-stratum.script
new file mode 100755
index 00000000..2802dd54
--- /dev/null
+++ b/tests/rebuild-cached-stratum.script
@@ -0,0 +1,64 @@
+#!/bin/sh
+#
+# Does a cached stratum get rebuilt if its chunk changes?
+# This tests a bug that is currently in morph, where the stratum does
+# not get rebuilt in that case. Later on, the test will guard against
+# regressions.
+#
+# Copyright (C) 2011 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 -e
+
+cache="$DATADIR/rebuild-cached-stratum-cache"
+log="$DATADIR/rebuild-cached-stratum-morph.log"
+
+# Make a branch in the chunk repo where we can make our own modifications.
+(cd "$DATADIR/chunk-repo" &&
+ git checkout --quiet farrokh &&
+ git checkout --quiet -b rebuild-cached-stratum)
+
+# Make a branch in the morphs repo and modify the stratum to refer to
+# the new chunk branch.
+(cd "$DATADIR/morphs-repo" &&
+ git checkout --quiet -b rebuild-cached-stratum &&
+ sed -i 's/farrokh/rebuild-cached-stratum/' hello-stratum.morph &&
+ git commit --quiet -m "rebuild-cached-stratum" -a)
+
+# Build the first time.
+./morph --no-default-configs \
+ build morphs-repo rebuild-cached-stratum hello-stratum.morph \
+ --git-base-url="file://$DATADIR" \
+ --cachedir="$cache" --keep-path --no-distcc \
+ --log="$log" || cat "$log" 1>&2
+echo "first build:"
+(cd "$cache" && ls *.chunk.* *.stratum.* | sed 's/^[^.]*\./ /' |
+ LC_ALL=C sort)
+
+# Change the chunk.
+(cd "$DATADIR/chunk-repo" &&
+ echo >> hello.c &&
+ git commit --quiet -am change)
+
+# Rebuild.
+./morph --no-default-configs \
+ build morphs-repo rebuild-cached-stratum hello-stratum.morph \
+ --git-base-url="file://$DATADIR" \
+ --cachedir="$cache" --keep-path --no-distcc \
+ --log="$log" || cat "$log" 1>&2
+echo "second build:"
+(cd "$cache" && ls *.chunk.* *.stratum.* | sed 's/^[^.]*\./ /' |
+ LC_ALL=C sort)
+
diff --git a/tests/rebuild-cached-stratum.stdout b/tests/rebuild-cached-stratum.stdout
new file mode 100644
index 00000000..eee106f5
--- /dev/null
+++ b/tests/rebuild-cached-stratum.stdout
@@ -0,0 +1,8 @@
+first build:
+ chunk.hello
+ stratum.hello-stratum
+second build:
+ chunk.hello
+ chunk.hello
+ stratum.hello-stratum
+ stratum.hello-stratum
diff --git a/tests/setup_once b/tests/setup_once
index e969c1a3..0fa19fc4 100755
--- a/tests/setup_once
+++ b/tests/setup_once
@@ -1,12 +1,15 @@
#!/bin/sh
#
-# Create a git repository for tests. The repository will contain a simple
-# "hello, world" C program, and two branches ("master", "farrokh"), with
-# the master branch containing just a README. The two branches are there
+# Create git repositories for tests. The chunk repository will contain a
+# simple "hello, world" C program, and two branches ("master", "farrokh"),
+# with the master branch containing just a README. The two branches are there
# so that we can test building a branch that hasn't been checked out.
# The branches are different so that we know that if the wrong branch
# is uses, the build will fail.
#
+# The stratum repository contains a single branch, "master", with a
+# stratum and a system morphology that include the chunk above.
+#
# Copyright (C) 2011 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
@@ -25,9 +28,11 @@
set -e
-repo="$DATADIR/repo"
-mkdir "$repo"
-cd "$repo"
+# Create chunk repository.
+
+chunkrepo="$DATADIR/chunk-repo"
+mkdir "$chunkrepo"
+cd "$chunkrepo"
git init --quiet
cat <<EOF > README
@@ -64,6 +69,19 @@ cat <<EOF > hello.morph
EOF
git add hello.morph
+git commit --quiet -m "add a hello world program and morph"
+
+git checkout --quiet master
+
+
+
+# Create morph repository.
+
+morphsrepo="$DATADIR/morphs-repo"
+mkdir "$morphsrepo"
+cd "$morphsrepo"
+git init --quiet
+
cat <<EOF > hello-stratum.morph
{
"name": "hello-stratum",
@@ -71,7 +89,7 @@ cat <<EOF > hello-stratum.morph
"sources": [
{
"name": "hello",
- "repo": "repo",
+ "repo": "chunk-repo",
"ref": "farrokh"
}
]
@@ -91,7 +109,5 @@ cat <<EOF > hello-system.morph
EOF
git add hello-system.morph
-git commit --quiet -m "add a hello world program and morphs"
-
-git checkout --quiet master
+git commit --quiet -m "add morphs"