summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2014-09-26 16:10:47 (GMT)
committerSam Thursfield <sam.thursfield@codethink.co.uk>2014-09-26 16:10:47 (GMT)
commit8229cfb750223a7f98229300396cec96fa31ae4f (patch)
tree6aab2dc78689283583251675a195567b370a3660
parent68c222588dd415d3e55385bea9563434f8243329 (diff)
downloadmorph-sam/distbuild-fixes.tar.gz
Serialise morphologies in a new waysam/distbuild-fixes
-rw-r--r--distbuild/serialise.py45
-rw-r--r--distbuild/serialise_tests.py50
2 files changed, 26 insertions, 69 deletions
diff --git a/distbuild/serialise.py b/distbuild/serialise.py
index 9b38c84..4c3dfb3 100644
--- a/distbuild/serialise.py
+++ b/distbuild/serialise.py
@@ -22,22 +22,12 @@ import morphlib
import logging
-morphology_attributes = [
- 'needs_artifact_metadata_cached',
-]
-
-
def serialise_artifact(artifact):
'''Serialise an Artifact object and its dependencies into string form.'''
def encode_morphology(morphology):
- result = {}
- for key in morphology.keys():
- result[key] = morphology[key]
- for x in morphology_attributes:
- result['__%s' % x] = getattr(morphology, x)
- return result
-
+ return morphology.data
+
def encode_source(source, artifacts):
source_dic = {
'name': source.name,
@@ -119,30 +109,7 @@ def deserialise_artifact(encoded):
'''
def decode_morphology(le_dict):
- '''Convert a dict into something that kinda acts like a Morphology.
-
- As it happens, we don't need the full Morphology so we cheat.
- Cheating is good.
-
- '''
-
- class FakeMorphology(dict):
-
- def get_commands(self, which):
- '''Get commands to run from a morphology or build system'''
- if self[which] is None:
- attr = '_'.join(which.split('-'))
- bs = morphlib.buildsystem.lookup_build_system(
- self['build-system'])
- return getattr(bs, attr)
- else:
- return self[which]
-
- morphology = FakeMorphology(le_dict)
- for x in morphology_attributes:
- setattr(morphology, x, le_dict['__%s' % x])
- del morphology['__%s' % x]
- return morphology
+ return morphlib.morphology.Morphology(le_dict)
def decode_source(le_dict):
'''Convert a dict into a Source object.
@@ -167,8 +134,8 @@ def deserialise_artifact(encoded):
break
else:
raise ValueError(
- "Didn't find source %s in %s sources generated for %s." %
- le_dict['name']. len(sources), le_dict['filename'])
+ "Didn't find source %s for %s." % (le_dict['name'],
+ le_dict['filename']))
source.cache_id = le_dict['cache_id']
source.cache_key = le_dict['cache_key']
@@ -215,7 +182,7 @@ def deserialise_artifact(encoded):
key = artifacts[artifact_id].name
sources[source_id].artifacts[key] = artifacts[artifact_id]
- sources[source_id].dependencies = [artifacts[aid] for aid in
+ sources[source_id].dependencies = [artifacts_dict[aid] for aid in
source_dict['dependencies']]
return artifacts[artifacts_dict['_root']]
diff --git a/distbuild/serialise_tests.py b/distbuild/serialise_tests.py
index 8e0a941..db32a7c 100644
--- a/distbuild/serialise_tests.py
+++ b/distbuild/serialise_tests.py
@@ -22,21 +22,16 @@ import distbuild
import morphlib
-class MockMorphology(object):
-
- def __init__(self, name, kind):
- self.dict = {
- 'name': name,
- 'kind': kind,
- }
- self.needs_staging_area = None
- self.needs_artifact_metadata_cached = None
-
- def keys(self):
- return self.dict.keys()
-
- def __getitem__(self, key):
- return self.dict[key]
+def make_morphology(name, kind):
+ m = morphlib.morphology.Morphology({
+ 'name': name,
+ 'kind': kind,
+ })
+ if kind == 'system':
+ m['strata'] = []
+ loader = morphlib.morphloader.MorphologyLoader()
+ loader.set_defaults(m)
+ return m
class MockSource(object):
@@ -48,7 +43,7 @@ class MockSource(object):
self.original_ref = '%s.source.original_ref' % name
self.sha1 = '%s.source.sha1' % name
self.tree = '%s.source.tree' % name
- self.morphology = MockMorphology(name, kind)
+ self.morphology = make_morphology(name, kind)
self.filename = '%s.source.filename' % name
self.cache_id = {
'blip': '%s.blip' % name,
@@ -63,7 +58,7 @@ class MockSource(object):
-def mock_artifact(name, kind):
+def make_artifact(name, kind):
source = MockSource(name, kind)
artifact = morphlib.artifact.Artifact(source, name)
source.artifacts = {name: artifact}
@@ -73,10 +68,10 @@ def mock_artifact(name, kind):
class SerialisationTests(unittest.TestCase):
def setUp(self):
- self.art1 = mock_artifact('name1', 'chunk')
- self.art2 = mock_artifact('name2', 'chunk')
- self.art3 = mock_artifact('name3', 'stratum')
- self.art4 = mock_artifact('name4', 'system')
+ self.art1 = make_artifact('name1', 'chunk')
+ self.art2 = make_artifact('name2', 'chunk')
+ self.art3 = make_artifact('name3', 'stratum')
+ self.art4 = make_artifact('name4', 'system')
def assertEqualMorphologies(self, a, b):
self.assertEqual(sorted(a.keys()), sorted(b.keys()))
@@ -84,11 +79,6 @@ class SerialisationTests(unittest.TestCase):
a_values = [a[k] for k in keys]
b_values = [b[k] for k in keys]
self.assertEqual(a_values, b_values)
- self.assertEqual(a.needs_staging_area, b.needs_staging_area)
- self.assertEqual(a.needs_artifact_metadata_cached,
- b.needs_artifact_metadata_cached)
- self.assertEqual(a.needs_staging_area,
- b.needs_staging_area)
def assertEqualSources(self, a, b):
self.assertEqual(a.repo, b.repo)
@@ -102,8 +92,8 @@ class SerialisationTests(unittest.TestCase):
def assertEqualArtifacts(self, a, b):
self.assertEqualSources(a.source, b.source)
self.assertEqual(a.name, b.name)
- self.assertEqual(a.cache_id, b.cache_id)
- self.assertEqual(a.cache_key, b.cache_key)
+ self.assertEqual(a.source.cache_id, b.source.cache_id)
+ self.assertEqual(a.source.cache_key, b.source.cache_key)
self.assertEqual(len(a.source.dependencies),
len(b.source.dependencies))
for i in range(len(a.source.dependencies)):
@@ -116,7 +106,7 @@ class SerialisationTests(unittest.TestCase):
self.assertEqualArtifacts(artifact, decoded)
def key(a):
- return a.cache_key
+ return a.source.cache_key
objs = {}
queue = [decoded]
@@ -127,7 +117,7 @@ class SerialisationTests(unittest.TestCase):
self.assertTrue(obj is objs[k])
else:
objs[k] = obj
- queue.extend(obj.dependencies)
+ queue.extend(obj.source.dependencies)
def test_returns_string(self):
encoded = distbuild.serialise_artifact(self.art1)