diff options
author | Jürg Billeter <j@bitron.ch> | 2020-09-24 16:00:45 +0200 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2020-09-28 14:30:39 +0200 |
commit | eecd703d13fb566b795a08d7a90ae4748154f3d3 (patch) | |
tree | 3137abc22bcfcd87b20eb1ee50e2e8de8141847d /src/buildstream | |
parent | ba659a8b5e1947a501ca566d850b5e481ea828d8 (diff) | |
download | buildstream-eecd703d13fb566b795a08d7a90ae4748154f3d3.tar.gz |
element.py: Use Artifact.pull() method
This replaces `__pull_strong()` and `__pull_weak()` with calls to
`Artifact.pull()`. Besides simplifying code in `element.py`, this
removes the call to `_pull_done()` from the job process, which would
cause issues with the upcoming thread-based scheduler.
Diffstat (limited to 'src/buildstream')
-rw-r--r-- | src/buildstream/element.py | 69 |
1 files changed, 11 insertions, 58 deletions
diff --git a/src/buildstream/element.py b/src/buildstream/element.py index 9348dff48..5118f0193 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -1945,17 +1945,20 @@ class Element(Plugin): pull_buildtrees = context.pull_buildtrees # Attempt to pull artifact without knowing whether it's available - pulled = self.__pull_strong(pull_buildtrees=pull_buildtrees) - - if not pulled and not self._cached() and not context.get_strict(): - pulled = self.__pull_weak(pull_buildtrees=pull_buildtrees) + strict_artifact = Artifact(self, context, strong_key=self.__strict_cache_key, weak_key=self.__weak_cache_key) + if strict_artifact.pull(pull_buildtrees=pull_buildtrees): + # Notify successful download + return True - if not pulled: + if not context.get_strict() and not self._cached(): + # In non-strict mode also try pulling weak artifact + # if no weak artifact is cached yet. + artifact = Artifact(self, context, weak_key=self.__weak_cache_key) + return artifact.pull(pull_buildtrees=pull_buildtrees) + else: + # No artifact has been downloaded return False - # Notify successfull download - return True - def _skip_source_push(self): if not self.sources() or self._get_workspace(): return True @@ -3099,56 +3102,6 @@ class Element(Plugin): self.__build_result = self.__artifact.load_build_result() - # __pull_strong(): - # - # Attempt pulling given element from configured artifact caches with - # the strict cache key - # - # Args: - # progress (callable): The progress callback, if any - # subdir (str): The optional specific subdir to pull - # excluded_subdirs (list): The optional list of subdirs to not pull - # - # Returns: - # (bool): Whether or not the pull was successful - # - def __pull_strong(self, *, pull_buildtrees): - weak_key = self._get_cache_key(strength=_KeyStrength.WEAK) - key = self.__strict_cache_key - if not self.__artifacts.pull(self, key, pull_buildtrees=pull_buildtrees): - return False - - # update weak ref by pointing it to this newly fetched artifact - self.__artifacts.link_key(self, key, weak_key) - - return True - - # __pull_weak(): - # - # Attempt pulling given element from configured artifact caches with - # the weak cache key - # - # Args: - # subdir (str): The optional specific subdir to pull - # excluded_subdirs (list): The optional list of subdirs to not pull - # - # Returns: - # (bool): Whether or not the pull was successful - # - def __pull_weak(self, *, pull_buildtrees): - weak_key = self._get_cache_key(strength=_KeyStrength.WEAK) - if not self.__artifacts.pull(self, weak_key, pull_buildtrees=pull_buildtrees): - return False - - # extract strong cache key from this newly fetched artifact - self._pull_done() - - # create tag for strong cache key - key = self._get_cache_key(strength=_KeyStrength.STRONG) - self.__artifacts.link_key(self, weak_key, key) - - return True - # __update_cache_keys() # # Updates weak and strict cache keys |