summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <ben.c.schubert@gmail.com>2019-06-28 12:29:25 +0100
committerBenjamin Schubert <ben.c.schubert@gmail.com>2019-07-09 16:55:54 +0100
commit18937bf6419a01e5ca8420858abd8fd79c5413c5 (patch)
tree62e32b869e4b613d285e003c1e180a05e5296b04
parentda8e7c5b91a0625570b8220005d08c554533bcc5 (diff)
downloadbuildstream-18937bf6419a01e5ca8420858abd8fd79c5413c5.tar.gz
_cachekey: Remove the 'node_sanitization' done before the json string
Since ujson already sorts the keys, we just need to be able to jsonify Nodes sensibly. This is done by implementing __json__ on the 'Node' base class. This does not break the cache keys.
-rw-r--r--src/buildstream/_cachekey.py4
-rw-r--r--src/buildstream/_context.py2
-rw-r--r--src/buildstream/_project.py2
-rw-r--r--src/buildstream/_yaml.pxd1
-rw-r--r--src/buildstream/_yaml.pyx20
-rw-r--r--src/buildstream/element.py2
-rw-r--r--tests/elements/filter/basic/element_plugins/dynamic.py2
7 files changed, 26 insertions, 7 deletions
diff --git a/src/buildstream/_cachekey.py b/src/buildstream/_cachekey.py
index e56b582fa..89d47671e 100644
--- a/src/buildstream/_cachekey.py
+++ b/src/buildstream/_cachekey.py
@@ -22,7 +22,6 @@ import hashlib
import ujson
-from . import _yaml
# Internal record of the size of a cache key
_CACHEKEY_SIZE = len(hashlib.sha256().hexdigest())
@@ -63,6 +62,5 @@ def is_key(key):
# (str): An sha256 hex digest of the given value
#
def generate_key(value):
- ordered = _yaml.node_sanitize(value)
- ustring = ujson.dumps(ordered, sort_keys=True, escape_forward_slashes=False).encode('utf-8')
+ ustring = ujson.dumps(value, sort_keys=True, escape_forward_slashes=False).encode('utf-8')
return hashlib.sha256(ustring).hexdigest()
diff --git a/src/buildstream/_context.py b/src/buildstream/_context.py
index 60bc9ae9b..97956cc6f 100644
--- a/src/buildstream/_context.py
+++ b/src/buildstream/_context.py
@@ -429,7 +429,7 @@ class Context():
if self._cache_key is None:
# Anything that alters the build goes into the unique key
- self._cache_key = _cachekey.generate_key(_yaml.new_empty_node())
+ self._cache_key = _cachekey.generate_key({})
return self._cache_key
diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py
index cc57a16fa..72cf6306a 100644
--- a/src/buildstream/_project.py
+++ b/src/buildstream/_project.py
@@ -230,7 +230,7 @@ class Project():
# Anything that alters the build goes into the unique key
# (currently nothing here)
- self._cache_key = _cachekey.generate_key(_yaml.new_empty_node())
+ self._cache_key = _cachekey.generate_key({})
return self._cache_key
diff --git a/src/buildstream/_yaml.pxd b/src/buildstream/_yaml.pxd
index 48bed1dea..45d2d351a 100644
--- a/src/buildstream/_yaml.pxd
+++ b/src/buildstream/_yaml.pxd
@@ -28,6 +28,7 @@ cdef class Node:
cdef public int column
cpdef Node copy(self)
+ cpdef object strip_node_info(self)
cdef bint _shares_position_with(self, Node target)
cdef bint _walk_find(self, Node target, list path) except *
diff --git a/src/buildstream/_yaml.pyx b/src/buildstream/_yaml.pyx
index d68f64772..82262f60b 100644
--- a/src/buildstream/_yaml.pyx
+++ b/src/buildstream/_yaml.pyx
@@ -29,6 +29,7 @@ from collections.abc import Mapping, Sequence
from copy import deepcopy
from ruamel import yaml
+
from ._exceptions import LoadError, LoadErrorReason
@@ -83,6 +84,12 @@ cdef class Node:
cpdef Node copy(self):
raise NotImplementedError()
+ cpdef object strip_node_info(self):
+ raise NotImplementedError()
+
+ def __json__(self):
+ raise ValueError("Nodes should not be allowed when jsonify-ing data", self)
+
cdef class ScalarNode(Node):
@@ -132,6 +139,9 @@ cdef class ScalarNode(Node):
return None
return str(self.value)
+ cpdef object strip_node_info(self):
+ return self.value
+
cdef bint _walk_find(self, Node target, list path) except *:
return self._shares_position_with(target)
@@ -270,6 +280,12 @@ cdef class MappingNode(Node):
cpdef object values(self):
return self.value.values()
+ cpdef object strip_node_info(self):
+ cdef str key
+ cdef Node value
+
+ return {key: value.strip_node_info() for key, value in self.value.items()}
+
def __delitem__(self, str key):
del self.value[key]
@@ -362,6 +378,10 @@ cdef class SequenceNode(Node):
cpdef list as_str_list(self):
return [node.as_str() for node in self.value]
+ cpdef object strip_node_info(self):
+ cdef Node value
+ return [value.strip_node_info() for value in self.value]
+
cdef bint _walk_find(self, Node target, list path) except *:
cdef int i
cdef Node v
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index c49a56d09..3030bccc5 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -2166,7 +2166,7 @@ class Element(Plugin):
'environment': cache_env,
'sources': [s._get_unique_key(workspace is None) for s in self.__sources],
'workspace': '' if workspace is None else workspace.get_key(self._get_project()),
- 'public': self.__public,
+ 'public': self.__public.strip_node_info(),
'cache': 'CASCache'
}
diff --git a/tests/elements/filter/basic/element_plugins/dynamic.py b/tests/elements/filter/basic/element_plugins/dynamic.py
index eb462ceb1..1ec7d4dd3 100644
--- a/tests/elements/filter/basic/element_plugins/dynamic.py
+++ b/tests/elements/filter/basic/element_plugins/dynamic.py
@@ -11,7 +11,7 @@ class DynamicElement(Element):
pass
def get_unique_key(self):
- return {'split-rules': self.split_rules}
+ return {'split-rules': self.split_rules.strip_node_info()}
def configure_sandbox(self, sandbox):
pass