summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2020-09-24 16:00:45 +0200
committerJürg Billeter <j@bitron.ch>2020-09-24 16:51:06 +0200
commite94d5e51bea444305014540a051ecfe924536c2b (patch)
treec8ce3475ae12aacde937bb2c0d62abbff6f985bc
parentf9103c7873b5ae33a71e53dc30165d0c736ca6a9 (diff)
downloadbuildstream-juerg/artifact-pull.tar.gz
element.py: Use Artifact.pull() methodjuerg/artifact-pull
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.
-rw-r--r--src/buildstream/element.py69
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