From f1531cc02d836c28728ac3ad3326bffbb3014419 Mon Sep 17 00:00:00 2001 From: Benjamin Schubert Date: Tue, 26 Nov 2019 10:45:33 +0000 Subject: source.py: Introduce methods to query state instead of get_consistency `get_consistency` doesn't allow being fine grained and asking only for a specific bit of information. This introduces methods `is_cached` and `is_resolved` which will be more flexible for refactoring. --- src/buildstream/_pipeline.py | 4 ++-- src/buildstream/element.py | 13 +++++++++---- src/buildstream/source.py | 11 ++++++++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/buildstream/_pipeline.py b/src/buildstream/_pipeline.py index aee0c55da..0588fe21d 100644 --- a/src/buildstream/_pipeline.py +++ b/src/buildstream/_pipeline.py @@ -382,7 +382,7 @@ class Pipeline: for element in inconsistent: detail += " Element: {} is inconsistent\n".format(element._get_full_name()) for source in element.sources(): - if source._get_consistency() == Consistency.INCONSISTENT: + if not source._is_resolved(): detail += " {} is missing ref\n".format(source) detail += "\n" detail += "Try tracking these elements first with `bst source track`\n" @@ -414,7 +414,7 @@ class Pipeline: for element in uncached: detail += " Following sources for element: {} are not cached:\n".format(element._get_full_name()) for source in element.sources(): - if source._get_consistency() < Consistency.CACHED: + if source._is_cached(): detail += " {}\n".format(source) detail += "\n" detail += ( diff --git a/src/buildstream/element.py b/src/buildstream/element.py index 106460b9a..6aeaedc74 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -2104,7 +2104,7 @@ class Element(Plugin): continue # try and fetch from source cache - if source._get_consistency() < Consistency.CACHED and self.__sourcecache.has_fetch_remotes(): + if not source._is_cached() and self.__sourcecache.has_fetch_remotes(): if self.__sourcecache.pull(source): continue @@ -2113,8 +2113,7 @@ class Element(Plugin): # We need to fetch original sources if fetch_needed or fetch_original: for source in self.sources(): - source_consistency = source._get_consistency() - if source_consistency != Consistency.CACHED: + if not source._is_cached(): source._fetch(previous_sources) previous_sources.append(source) @@ -2357,7 +2356,13 @@ class Element(Plugin): for source in self.__sources: # FIXME: It'd be nice to remove this eventually source._update_state() - self.__consistency = min(self.__consistency, source._get_consistency()) + + if source._is_cached(): + self.__consistency = min(self.__consistency, Consistency.CACHED) + elif source._is_resolved(): + self.__consistency = min(self.__consistency, Consistency.RESOLVED) + else: + self.__consistency = Consistency.INCONSISTENT # If the source state changes, our cache key must also change, # since it contains the source's key. diff --git a/src/buildstream/source.py b/src/buildstream/source.py index f49cdb493..4f1133de7 100644 --- a/src/buildstream/source.py +++ b/src/buildstream/source.py @@ -783,10 +783,15 @@ class Source(Plugin): if self.__consistency == Consistency.CACHED: self.validate_cache() - # Return cached consistency + # Get whether the source is consistent # - def _get_consistency(self): - return self.__consistency + def _is_resolved(self): + return self.__consistency >= Consistency.RESOLVED + + # Get whether the source is cached by the source plugin + # + def _is_cached(self): + return self.__consistency >= Consistency.CACHED # Wrapper function around plugin provided fetch method # -- cgit v1.2.1