diff options
author | Benjamin Schubert <bschubert15@bloomberg.net> | 2019-11-27 16:26:37 +0000 |
---|---|---|
committer | Benjamin Schubert <bschubert15@bloomberg.net> | 2020-01-16 16:33:19 +0000 |
commit | 4a47af24fca8aeb6c0c0fe6bd754712ecce5211d (patch) | |
tree | 08f72ea7bbc2979637900b1bcaeb8aa798d41c52 /src/buildstream/source.py | |
parent | 93ebe4992c32b2588ae213a98c3e05d60c974a00 (diff) | |
download | buildstream-4a47af24fca8aeb6c0c0fe6bd754712ecce5211d.tar.gz |
source.py: Add a new 'is_resolved' to get whether a source is resolved.
`get_consistency` is coarse grained and hard to optimize, in addition
to being un-userfriendly.
This adds a new `is_resolved` that has for default implementation
`get_ref() is not None`, which is true for most sources in BuildStream.
Sources for which this is not true can override the method to give a
more accurate description.
Checking for this before looking whether the source is cached can
reduce the amount of work necessary in some pipeline and opens the
door for more optimizations and the removal of the source state check.
Diffstat (limited to 'src/buildstream/source.py')
-rw-r--r-- | src/buildstream/source.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/buildstream/source.py b/src/buildstream/source.py index 4f1133de7..4ec52336b 100644 --- a/src/buildstream/source.py +++ b/src/buildstream/source.py @@ -705,6 +705,22 @@ class Source(Plugin): with utils._tempdir(dir=mirrordir) as tempdir: yield tempdir + def is_resolved(self) -> bool: + """Get whether the source is resolved. + + This has a default implementation that checks whether the source + has a ref or not. If it has a ref, it is assumed to be resolved. + + Sources that never have a ref or have uncommon requirements can + override this method to specify when they should be considered + resolved + + Returns: whether the source is fully resolved or not + + *Since: 1.93.0* + """ + return self.get_ref() is not None + ############################################################# # Private Abstract Methods used in BuildStream # ############################################################# @@ -783,11 +799,6 @@ class Source(Plugin): if self.__consistency == Consistency.CACHED: self.validate_cache() - # Get whether the source is consistent - # - def _is_resolved(self): - return self.__consistency >= Consistency.RESOLVED - # Get whether the source is cached by the source plugin # def _is_cached(self): @@ -1416,7 +1427,7 @@ class Source(Plugin): for index, src in enumerate(previous_sources): # BuildStream should track sources in the order they appear so # previous sources should never be in an inconsistent state - assert src.get_consistency() != Consistency.INCONSISTENT + assert src.is_resolved() if src.get_consistency() == Consistency.RESOLVED: src._fetch(previous_sources[0:index]) |