diff options
author | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-06-28 12:29:25 +0100 |
---|---|---|
committer | Benjamin Schubert <ben.c.schubert@gmail.com> | 2019-07-01 22:38:39 +0100 |
commit | 160f0a59ebe853aa75103e06a679fce1e224f741 (patch) | |
tree | 7e21764a258c32fba017b2910f4761476f658a2b | |
parent | d0e92427acc75b23b8183d807b6fbdf71f3ec26a (diff) | |
download | buildstream-160f0a59ebe853aa75103e06a679fce1e224f741.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.py | 4 | ||||
-rw-r--r-- | src/buildstream/_context.py | 2 | ||||
-rw-r--r-- | src/buildstream/_project.py | 2 | ||||
-rw-r--r-- | src/buildstream/_yaml.pxd | 1 | ||||
-rw-r--r-- | src/buildstream/_yaml.pyx | 20 | ||||
-rw-r--r-- | src/buildstream/element.py | 2 | ||||
-rw-r--r-- | tests/elements/filter/basic/element_plugins/dynamic.py | 2 |
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 cc31e982a..35ed95e11 100644 --- a/src/buildstream/_context.py +++ b/src/buildstream/_context.py @@ -441,7 +441,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 af15bdc45..f3efd8ba9 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 46f642578..10ed76df4 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) @@ -273,6 +283,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] @@ -365,6 +381,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 1a5439fda..581fe725f 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 |