summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2017-07-07 09:08:32 +0200
committerJürg Billeter <j@bitron.ch>2017-07-14 14:13:51 +0200
commit4d56bf0b5f85ef72082027dfe794a2d69c63cae3 (patch)
tree4fee426f1f37486d705c5dbf5e01c83b92cc104c
parent0fc743f19a95b789651108981570f6239d1c01c7 (diff)
downloadbuildstream-4d56bf0b5f85ef72082027dfe794a2d69c63cae3.tar.gz
element.py: Add __calculate_cache_key()
-rw-r--r--buildstream/element.py64
1 files changed, 37 insertions, 27 deletions
diff --git a/buildstream/element.py b/buildstream/element.py
index dbdae352c..d26561529 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -716,16 +716,16 @@ class Element(Plugin):
return True
- # _get_cache_key():
+ # __calculate_cache_key():
#
- # Returns the cache key, calculating it if necessary
+ # Calculates the cache key
#
# Returns:
# (str): A hex digest cache key for this Element, or None
#
# None is returned if information for the cache key is missing.
#
- def _get_cache_key(self):
+ def __calculate_cache_key(self, dependencies):
# It is not really necessary to check if the Source object's
# local mirror has the ref cached locally or not, it's only important
@@ -735,34 +735,44 @@ class Element(Plugin):
if self._consistency() == Consistency.INCONSISTENT:
return None
- if self.__cache_key is None:
+ # No cache keys for dependencies which have no cache keys
+ if None in dependencies:
+ return None
- # No cache keys for dependencies which have no cache keys
+ # Filter out nocache variables from the element's environment
+ cache_env = {
+ key: value
+ for key, value in self.node_items(self.__environment)
+ if key not in self.__env_nocache
+ }
+
+ context = self.get_context()
+ project = self.get_project()
+ return utils._generate_key({
+ 'context': context._get_cache_key(),
+ 'project': project._get_cache_key(),
+ 'element': self.get_unique_key(),
+ 'environment': cache_env,
+ 'sources': [s.get_unique_key() for s in self.__sources],
+ 'dependencies': dependencies,
+ 'public': self.__public
+ })
+
+ # _get_cache_key():
+ #
+ # Returns the cache key, calculating it if necessary
+ #
+ # Returns:
+ # (str): A hex digest cache key for this Element, or None
+ #
+ # None is returned if information for the cache key is missing.
+ #
+ def _get_cache_key(self):
+ if self.__cache_key is None:
dependencies = [
e._get_cache_key() for e in self.dependencies(Scope.BUILD)
]
- for dep in dependencies:
- if dep is None:
- return None
-
- # Filter out nocache variables from the element's environment
- cache_env = {
- key: value
- for key, value in self.node_items(self.__environment)
- if key not in self.__env_nocache
- }
-
- context = self.get_context()
- project = self.get_project()
- self.__cache_key = utils._generate_key({
- 'context': context._get_cache_key(),
- 'project': project._get_cache_key(),
- 'element': self.get_unique_key(),
- 'environment': cache_env,
- 'sources': [s.get_unique_key() for s in self.__sources],
- 'dependencies': dependencies,
- 'public': self.__public
- })
+ self.__cache_key = self.__calculate_cache_key(dependencies)
return self.__cache_key