summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Ipsum <richard.ipsum@codethink.co.uk>2014-02-27 15:39:40 +0000
committerRichard Ipsum <richard.ipsum@codethink.co.uk>2014-02-27 15:40:15 +0000
commit9f4d21489bf4c54fe9ab3f67384676f0ce4df546 (patch)
tree63bdadd3eb37a71128ed7502b62ae72ad382ff3b
parenta2798f6228d700ad491b5345381680027b897ca3 (diff)
downloadmorph-9f4d21489bf4c54fe9ab3f67384676f0ce4df546.tar.gz
try serialise/deserialise source's artifacts
-rw-r--r--distbuild/serialise.py39
-rw-r--r--morphlib/buildcommand.py3
-rw-r--r--morphlib/builder2.py6
-rw-r--r--morphlib/localartifactcache.py1
-rw-r--r--morphlib/plugins/distbuild_plugin.py2
5 files changed, 50 insertions, 1 deletions
diff --git a/distbuild/serialise.py b/distbuild/serialise.py
index 060833b1..caf8398b 100644
--- a/distbuild/serialise.py
+++ b/distbuild/serialise.py
@@ -19,6 +19,7 @@
import json
import morphlib
+import logging
morphology_attributes = [
@@ -36,6 +37,21 @@ def serialise_artifact(artifact):
for x in morphology_attributes:
result['__%s' % x] = getattr(morphology, x)
return result
+
+ def encode_artifact(artifact):
+ artifact_dic = {
+ # source? - that will be constructed during deserialisation
+ 'name': artifact.name,
+ 'cache_id': artifact.cache_id,
+ 'cache_key': artifact.cache_key,
+ 'dependencies': artifact.dependencies,
+ 'dependants': artifact.dependants,
+ 'metadata_version': artifact.metadata_version,
+ }
+
+ def encode_artifacts(artifacts):
+ return {name: encode_artifact(artifact)
+ for (name, artifact) in artifacts.iteritems()}
def encode_source(source):
source_dic = {
@@ -46,6 +62,7 @@ def serialise_artifact(artifact):
'tree': source.tree,
'morphology': encode_morphology(source.morphology),
'filename': source.filename,
+ 'artifacts': encode_artifacts(source.artifacts),
}
if source.morphology['kind'] == 'chunk':
source_dic['build_mode'] = source.build_mode
@@ -121,7 +138,17 @@ def deserialise_artifact(encoded):
setattr(morphology, x, le_dict['__%s' % x])
del morphology['__%s' % x]
return morphology
-
+
+ def unserialise_source_artifacts(source, artifacts_dict):
+ '''Convert this dict into a list of artifacts'''
+ return {a['name']: Artifact(source,
+ a['name'],
+ a['cache_id'],
+ a['cache_key'],
+ a['dependencies'],
+ a['dependents'],
+ a['metadata_version']) for a in artifacts_dict}
+
def unserialise_source(le_dict):
'''Convert a dict into a Source object.'''
@@ -132,6 +159,10 @@ def deserialise_artifact(encoded):
le_dict['tree'],
morphology,
le_dict['filename'])
+
+ source.artifacts = unserialise_source_artifacts(source,
+ le_dict['artifacts'])
+
if morphology['kind'] == 'chunk':
source.build_mode = le_dict['build_mode']
source.prefix = le_dict['prefix']
@@ -151,6 +182,9 @@ def deserialise_artifact(encoded):
artifact.arch = le_dict['arch']
return artifact
+ with open('/tmp/%s', 'w') as f:
+ f.write(encoded)
+
le_dicts = json.loads(encoded)
cache_keys = [k for k in le_dicts.keys() if k != '_root']
artifacts = {}
@@ -162,5 +196,8 @@ def deserialise_artifact(encoded):
artifact = artifacts[cache_key]
artifact.dependencies = [artifacts[k] for k in le_dict['dependencies']]
+ thing = artifacts[le_dicts['_root']]
+ logging.debug('thing.basename(): %s' % thing.basename())
+
return artifacts[le_dicts['_root']]
diff --git a/morphlib/buildcommand.py b/morphlib/buildcommand.py
index 137c63b4..6ca8ed80 100644
--- a/morphlib/buildcommand.py
+++ b/morphlib/buildcommand.py
@@ -178,6 +178,9 @@ class BuildCommand(object):
artifact.cache_key = ckc.compute_key(artifact)
artifact.cache_id = ckc.get_cache_id(artifact)
+ logging.debug('artifact.cache_key: %s\tartifact.cache_id: %s'
+ % artifact.cache_key, artifact.cache_id)
+
root_artifact.build_env = build_env
return root_artifact
diff --git a/morphlib/builder2.py b/morphlib/builder2.py
index 2dca738c..1de8b453 100644
--- a/morphlib/builder2.py
+++ b/morphlib/builder2.py
@@ -423,6 +423,9 @@ class ChunkBuilder(BuilderBase):
built_artifacts = []
filenames = []
source = self.artifact.source
+
+ logging.debug('source: %s' % source)
+
split_rules = source.split_rules
def filepaths(destdir):
@@ -459,6 +462,9 @@ class ChunkBuilder(BuilderBase):
parentify(file_paths +
['baserock/%s.meta' % chunk_artifact_name])
+ logging.debug('chunk_artifact.basename(): %s'
+ % chunk_artifact.basename())
+
with self.local_artifact_cache.put(chunk_artifact) as f:
self.write_metadata(destdir, chunk_artifact_name,
parented_paths)
diff --git a/morphlib/localartifactcache.py b/morphlib/localartifactcache.py
index 341bbb56..1a923544 100644
--- a/morphlib/localartifactcache.py
+++ b/morphlib/localartifactcache.py
@@ -50,6 +50,7 @@ class LocalArtifactCache(object):
def put(self, artifact):
filename = self.artifact_filename(artifact)
+ logging.debug('Artifact cache put() has filename: ', filename)
return morphlib.savefile.SaveFile(filename, mode='w')
def put_artifact_metadata(self, artifact, name):
diff --git a/morphlib/plugins/distbuild_plugin.py b/morphlib/plugins/distbuild_plugin.py
index b6e48be5..ed65d20a 100644
--- a/morphlib/plugins/distbuild_plugin.py
+++ b/morphlib/plugins/distbuild_plugin.py
@@ -87,6 +87,8 @@ class WorkerBuild(cliapp.Plugin):
serialized = sys.stdin.readline()
artifact = distbuild.deserialise_artifact(serialized)
+
+ logging.debug("artifact.basename(): %s" % artifact.basename())
bc = morphlib.buildcommand.BuildCommand(self.app)