summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Pollard <tom.pollard@codethink.co.uk>2019-04-17 15:35:53 +0100
committerTom Pollard <tom.pollard@codethink.co.uk>2019-04-17 16:47:27 +0100
commitc2673f4a42c3925abb58dfc91196bb37ab5456af (patch)
tree1fed2ddbca36b3b346a228b4bb4ed7bf523f2cd8
parent5790aa5b4536c39c97181cb16e5c84465ddd7bbf (diff)
downloadbuildstream-c2673f4a42c3925abb58dfc91196bb37ab5456af.tar.gz
element.py: Discard __artifact/__strict_artifact in update_state()
When we determine that current cache keys are to be discarded, we should also discard the associated members for correctness. This should act as a safeguard against accessing Artifact instances that have discarded cache keys. A side effect of this is the querying of element buildtree state from cli methods on elements that don't have a cached artifact would lead to the artifact member methods not being reachable. Ensuring the element is cached before trying to call said accessor methods resolves this.
-rw-r--r--buildstream/_artifact.py11
-rw-r--r--buildstream/element.py11
2 files changed, 12 insertions, 10 deletions
diff --git a/buildstream/_artifact.py b/buildstream/_artifact.py
index 41dc14367..4d9e4bf08 100644
--- a/buildstream/_artifact.py
+++ b/buildstream/_artifact.py
@@ -195,17 +195,13 @@ class Artifact():
#
# Returns:
# (bool): True if artifact cached with buildtree, False if
- # element not cached or missing expected buildtree.
- # Note this only confirms if a buildtree is present,
- # not its contents.
+ # missing expected buildtree. Note this only confirms
+ # if a buildtree is present, not its contents.
#
def cached_buildtree(self):
element = self._element
- if not element._cached():
- return False
-
key = self.get_extract_key()
if not self._artifacts.contains_subdir_artifact(element, key, 'buildtree'):
return False
@@ -222,9 +218,6 @@ class Artifact():
#
def buildtree_exists(self):
- if not self._element._cached():
- return False
-
artifact_vdir, _ = self._get_directory()
return artifact_vdir._exists('buildtree')
diff --git a/buildstream/element.py b/buildstream/element.py
index 4a6813f48..95081b940 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -1183,6 +1183,8 @@ class Element(Plugin):
self.__strong_cached = None
self.__weak_cached = None
self.__build_result = None
+ self.__artifact = None
+ self.__strict_artifact = None
return
if self.__weak_cache_key is None:
@@ -2149,6 +2151,9 @@ class Element(Plugin):
# not its contents.
#
def _cached_buildtree(self):
+ if not self._cached():
+ return False
+
return self.__artifact.cached_buildtree()
# _buildtree_exists()
@@ -2157,9 +2162,13 @@ class Element(Plugin):
# whether the buildtree is present in the local cache.
#
# Returns:
- # (bool): True if artifact was created with buildtree
+ # (bool): True if artifact was created with buildtree, False if
+ # element not cached or not created with a buildtree.
#
def _buildtree_exists(self):
+ if not self._cached():
+ return False
+
return self.__artifact.buildtree_exists()
# _cached_logs()