summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <bschubert15@bloomberg.net>2019-11-26 10:45:33 +0000
committerBenjamin Schubert <contact@benschubert.me>2020-01-16 14:36:35 +0000
commit0d012ee39240a677baa6336bcdf96a5c282d3d85 (patch)
treed7b190bc23ad3e14c6cbaea4ae8ebaceb7731830
parenta6f3f42e278a0b70ca8883575371248a826b1ceb (diff)
downloadbuildstream-0d012ee39240a677baa6336bcdf96a5c282d3d85.tar.gz
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.
-rw-r--r--src/buildstream/_pipeline.py4
-rw-r--r--src/buildstream/element.py13
-rw-r--r--src/buildstream/source.py11
3 files changed, 19 insertions, 9 deletions
diff --git a/src/buildstream/_pipeline.py b/src/buildstream/_pipeline.py
index 353a9c3a0..282408cd4 100644
--- a/src/buildstream/_pipeline.py
+++ b/src/buildstream/_pipeline.py
@@ -351,7 +351,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"
@@ -383,7 +383,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 not source._is_cached():
detail += " {}\n".format(source)
detail += "\n"
detail += (
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index 595724fcf..8c77ce775 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -2094,7 +2094,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
@@ -2103,8 +2103,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)
@@ -2347,7 +2346,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
#