summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaoul Hidalgo Charman <raoul.hidalgocharman@codethink.co.uk>2019-03-18 17:53:10 +0000
committerbst-marge-bot <marge-bot@buildstream.build>2019-03-21 18:31:26 +0000
commit8cdfbfda50ba146ec4ae63af46cb2b6f7ca764a7 (patch)
tree01dd79db70e8767f850837e1cf4fde90013ed455
parentc5f7df237240146cbf6571f45802e4bac9eb9c18 (diff)
downloadbuildstream-8cdfbfda50ba146ec4ae63af46cb2b6f7ca764a7.tar.gz
element.py: move _generate_key to _source_cached
This means that keys are only generated after tracking. Part of a fix for !1124
-rw-r--r--buildstream/element.py29
-rw-r--r--tests/sourcecache/staging.py2
2 files changed, 10 insertions, 21 deletions
diff --git a/buildstream/element.py b/buildstream/element.py
index 88f6863d6..03b7690ec 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -957,15 +957,11 @@ class Element(Plugin):
cls.__instantiated_elements[meta] = element
# Instantiate sources and generate their keys
- previous_sources = []
for meta_source in meta.sources:
meta_source.first_pass = meta.kind == "junction"
source = meta.project.create_source(meta_source,
first_pass=meta.first_pass)
- source._generate_key(previous_sources)
- previous_sources.append(source)
-
redundant_ref = source._load_ref()
element.__sources.append(source)
@@ -1376,12 +1372,6 @@ class Element(Plugin):
self.__tracking_scheduled = False
self.__tracking_done = True
- # update keys
- sources = list(self.sources())
- if sources:
- source = sources.pop()
- source._generate_key(sources)
-
self.__update_state_recursively()
# _track():
@@ -2166,12 +2156,13 @@ class Element(Plugin):
return _cachekey.generate_key(cache_key_dict)
+ # Check if sources are cached, generating the source key if it hasn't been
def _source_cached(self):
- source = None
- for source in self.sources():
- pass
- if source:
- return self._get_context().sourcecache.contains(source)
+ if self.__sources:
+ last_source = self.__sources[-1]
+ if not last_source._key:
+ last_source._generate_key(self.__sources[:-1])
+ return self._get_context().sourcecache.contains(last_source)
else:
return True
@@ -2927,11 +2918,9 @@ class Element(Plugin):
# Caches the sources into the local CAS
#
def __cache_sources(self):
- sources = list(self.sources())
- if sources:
- sourcecache = self._get_context().sourcecache
- if not sourcecache.contains(sources[-1]):
- sources[-1]._cache(sources[:-1])
+ sources = self.__sources
+ if sources and not self._source_cached():
+ sources[-1]._cache(sources[:-1])
# __update_state_recursively()
#
diff --git a/tests/sourcecache/staging.py b/tests/sourcecache/staging.py
index a61f5163d..5c1c4f358 100644
--- a/tests/sourcecache/staging.py
+++ b/tests/sourcecache/staging.py
@@ -74,8 +74,8 @@ def test_source_staged(tmpdir, cli, datafiles):
# seems to be the only way to get the sources?
element = project.load_elements(["import-bin.bst"])[0]
source = list(element.sources())[0]
- assert sourcecache.contains(source)
assert element._source_cached()
+ assert sourcecache.contains(source)
# Extract the file and check it's the same as the one we imported
ref = source._get_source_name()