summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-07-05 20:57:24 +0900
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-07-05 21:11:56 +0900
commit4a90e5ac777140574dbddc9ab65bb23ecdbf9036 (patch)
treea53e91c4ee67eb79ba7e8d39afa87e8f33684657
parentc9e6cb91a6a6f8ad096bbb7e025c005fc0051346 (diff)
downloadbuildstream-4a90e5ac777140574dbddc9ab65bb23ecdbf9036.tar.gz
element.py: _cached() and _assert_cached() now takes tristate 'recalculate'
o None: Calculate cache state if not previously calculated o True: Force recalculate cached state, even if already checked o False: Only return cached state, never recalculate automatically And _load_public_data() passes and explicit False value for 'recalculate', this ensures we never accidentally resolve cached state prematurely if trying to load the public data as a side effect of calling Element.get_public_data() outside of the build phase, when all elements in scope should have cached state resolved and correct anyway.
-rw-r--r--buildstream/element.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/buildstream/element.py b/buildstream/element.py
index e1e0c569d..5e1996d73 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -619,21 +619,32 @@ class Element(Plugin):
# (bool): Whether this element is already present in
# the artifact cache
#
- def _cached(self, recalculate=False):
+ # Note: The recalculate argument is actually tristate:
+ #
+ # o None: Calculate cache state if not previously calculated
+ # o True: Force recalculate cached state, even if already checked
+ # o False: Only return cached state, never recalculate automatically
+ #
+ def _cached(self, recalculate=None):
if recalculate:
self.__cached = None
- if self.__cached is None and self._get_cache_key() is not None:
- self.__cached = self.__artifacts.contains(self)
+ if recalculate != False:
+ if self.__cached is None and self._get_cache_key() is not None:
+ self.__cached = self.__artifacts.contains(self)
return False if self.__cached is None else self.__cached
# _assert_cached()
#
+ # Args:
+ # recalculate (bool): Argument to pass to Element._cached()
+ #
# Raises an error if the artifact is not cached.
- def _assert_cached(self):
- if not self._cached():
+ #
+ def _assert_cached(self, recalculate=None):
+ if not self._cached(recalculate=recalculate):
raise ElementError("{}: Missing artifact {}"
.format(self, self._get_display_key()))
@@ -1251,7 +1262,7 @@ class Element(Plugin):
yield filename.lstrip(os.sep)
def _load_public_data(self):
- self._assert_cached()
+ self._assert_cached(recalculate=False)
assert(self.__dynamic_public is None)
# Load the public data from the artifact