diff options
author | Jürg Billeter <j@bitron.ch> | 2017-07-07 07:34:15 +0200 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2017-07-14 10:26:34 +0200 |
commit | 4c3bdeb55589f4621da197552de5406ee2e91dfa (patch) | |
tree | c7586197727ce19df57153602af46306fac77863 | |
parent | a1e91e861b2ff830e08c6ef175fc3c6d130e9a06 (diff) | |
download | buildstream-4c3bdeb55589f4621da197552de5406ee2e91dfa.tar.gz |
element.py: Calculate weak cache key in addition to strong cache key
Weak cache keys include names of direct build dependencies but do not
include cache keys of dependencies.
-rw-r--r-- | buildstream/element.py | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/buildstream/element.py b/buildstream/element.py index d26561529..65573bc48 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -62,6 +62,20 @@ class Scope(Enum): """ +class _KeyStrength(Enum): + """Strength of cache key""" + + STRONG = 1 + """Includes strong cache keys of all build dependencies and their + runtime dependencies. + """ + + WEAK = 2 + """Includes names of direct build dependencies but does not include + cache keys of dependencies. + """ + + class Element(Plugin): """Element() @@ -89,6 +103,7 @@ class Element(Plugin): self.__build_dependencies = [] # Direct build dependency Elements self.__sources = [] # List of Sources self.__cache_key = None # Our cached cache key + self.__weak_cache_key = None # Our cached weak cache key self.__artifacts = artifacts # Artifact cache self.__cached = None # Whether we have a cached artifact self.__built = False # Element was locally built @@ -640,6 +655,7 @@ class Element(Plugin): def _force_inconsistent(self): self.__cached = None self.__cache_key = None + self.__weak_cache_key = None for source in self.__sources: source._force_inconsistent() @@ -762,19 +778,34 @@ class Element(Plugin): # # Returns the cache key, calculating it if necessary # + # Args: + # strength (_KeyStrength): Either STRONG or WEAK key strength + # # 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 _get_cache_key(self, strength=_KeyStrength.STRONG): if self.__cache_key is None: + # Calculate strong cache key dependencies = [ e._get_cache_key() for e in self.dependencies(Scope.BUILD) ] self.__cache_key = self.__calculate_cache_key(dependencies) - return self.__cache_key + # Calculate weak cache key + # Weak cache key includes names of direct build dependencies + # but does not include keys of dependencies. + dependencies = [ + e.name for e in self.dependencies(Scope.BUILD, recurse=False) + ] + self.__weak_cache_key = self.__calculate_cache_key(dependencies) + + if strength == _KeyStrength.STRONG: + return self.__cache_key + else: + return self.__weak_cache_key # _get_full_display_key(): # |