diff options
-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 2bebc4845..363ec3a30 100644 --- a/src/buildstream/_context.py +++ b/src/buildstream/_context.py @@ -444,7 +444,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 d959e93c9..f4df1bc32 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -2162,7 +2162,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(), } self.__cache_key_dict['fatal-warnings'] = sorted(project._fatal_warnings) 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 |