diff options
author | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2019-05-02 17:43:18 +0100 |
---|---|---|
committer | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2019-05-17 17:07:27 +0100 |
commit | dee20725d39d634c804e5e05cd19659e1f945f47 (patch) | |
tree | 020fa0a4ab1700e467712406e7d63cfedce32b0c /buildstream/element.py | |
parent | 8a16aa6f7af238fb77e90c6f4e7d4f1457507b85 (diff) | |
download | buildstream-jonathan/cached-to-artifact.tar.gz |
Delegate storage of cached state to the Artifact classjonathan/cached-to-artifact
This commit also removes Element.__is_cached because it doesn't seem to
serve a purpose.
Diffstat (limited to 'buildstream/element.py')
-rw-r--r-- | buildstream/element.py | 46 |
1 files changed, 17 insertions, 29 deletions
diff --git a/buildstream/element.py b/buildstream/element.py index 8c507b768..83b40a2db 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -216,8 +216,6 @@ class Element(Plugin): self.__artifacts = context.artifactcache # Artifact cache self.__sourcecache = context.sourcecache # Source cache self.__consistency = Consistency.INCONSISTENT # Cached overall consistency state - self.__strong_cached = None # Whether we have a cached artifact - self.__weak_cached = None # Whether we have a cached artifact self.__assemble_scheduled = False # Element is scheduled to be assembled self.__assemble_done = False # Element is assembled self.__tracking_scheduled = False # Sources are scheduled to be tracked @@ -1055,7 +1053,10 @@ class Element(Plugin): # the artifact cache # def _cached(self): - return self.__is_cached(keystrength=None) + if not self.__artifact: + return False + + return self.__artifact.cached() # _get_build_result(): # @@ -1789,13 +1790,14 @@ class Element(Plugin): # in user context, as to complete a partial artifact pull_buildtrees = self._get_context().pull_buildtrees - if self.__strong_cached and pull_buildtrees: - # If we've specified a subdir, check if the subdir is cached locally - # or if it's possible to get - if self._cached_buildtree() or not self._buildtree_exists(): + if self.__strict_artifact: + if self.__strict_artifact.cached() and pull_buildtrees: + # If we've specified a subdir, check if the subdir is cached locally + # or if it's possible to get + if self._cached_buildtree() or not self._buildtree_exists(): + return False + elif self.__strict_artifact.cached(): return False - elif self.__strong_cached: - return False # Pull is pending if artifact remote server available # and pull has not been attempted yet @@ -2304,18 +2306,12 @@ class Element(Plugin): # have been executed. sandbox._callback(mark_workspace_prepared) - def __is_cached(self, keystrength): - if keystrength is None: - keystrength = _KeyStrength.STRONG if self._get_context().get_strict() else _KeyStrength.WEAK - - return self.__strong_cached if keystrength == _KeyStrength.STRONG else self.__weak_cached - # __assert_cached() # # Raises an error if the artifact is not cached. # def __assert_cached(self, keystrength=None): - assert self.__is_cached(keystrength=keystrength), "{}: Missing artifact {}".format( + assert self._cached(), "{}: Missing artifact {}".format( self, self._get_brief_display_key()) # __get_tainted(): @@ -2882,8 +2878,6 @@ class Element(Plugin): self.__strict_cache_key = None self.__artifact = None self.__strict_artifact = None - self.__weak_cached = None - self.__strong_cached = None # __update_cache_keys() # @@ -2951,8 +2945,6 @@ class Element(Plugin): if not context.get_strict() and not self.__artifact: # We've calculated the weak_key, so instantiate artifact instance member self.__artifact = Artifact(self, context, weak_key=self.__weak_cache_key) - # and update the weak cached state (required early for workspaces) - self.__weak_cached = self.__artifact.cached() if not self.__strict_cache_key: return @@ -2966,15 +2958,11 @@ class Element(Plugin): self.__cache_key = self.__strict_cache_key self.__artifact = self.__strict_artifact - # Query caches now that the weak and strict cache keys are available. - # strong_cached in non-strict mode is only of relevance when querying - # if a 'better' artifact could be pulled, which is redudant if we already - # have it cached locally with a strict_key. As such strong_cached is only - # checked against the 'strict' artifact. - if not self.__strong_cached: - self.__strong_cached = self.__strict_artifact.cached() - if not self.__weak_cached and not context.get_strict(): - self.__weak_cached = self.__artifact.cached() + # Allow caches to be queried, since they may now be cached + # The next invocation of Artifact.cached() will access the filesystem. + # Note that this will safely do nothing if the artifacts are already cached. + self.__strict_artifact.reset_cached() + self.__artifact.reset_cached() # __update_cache_key_non_strict() # |