diff options
author | Jürg Billeter <j@bitron.ch> | 2018-02-27 06:09:15 +0100 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2018-02-27 11:43:16 +0000 |
commit | e99e22c262941fa9cc38c5546f2b54bb5d8e191f (patch) | |
tree | 722ce6eadc7580438730c5be287f683c7fe407ce | |
parent | 623aa819e5e3d097277219e287355da073985f25 (diff) | |
download | buildstream-e99e22c262941fa9cc38c5546f2b54bb5d8e191f.tar.gz |
_artifactcache: Add keys parameter to commit() method
Contain cache key logic in Element class.
-rw-r--r-- | buildstream/_artifactcache/artifactcache.py | 3 | ||||
-rw-r--r-- | buildstream/_artifactcache/ostreecache.py | 11 | ||||
-rw-r--r-- | buildstream/_artifactcache/tarcache.py | 23 | ||||
-rw-r--r-- | buildstream/element.py | 13 |
4 files changed, 24 insertions, 26 deletions
diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py index 927876dfb..0bbb05255 100644 --- a/buildstream/_artifactcache/artifactcache.py +++ b/buildstream/_artifactcache/artifactcache.py @@ -183,8 +183,9 @@ class ArtifactCache(): # Args: # element (Element): The Element commit an artifact for # content (str): The element's content directory + # keys (list): The cache keys to use # - def commit(self, element, content): + def commit(self, element, content, keys): raise ImplError("Cache '{kind}' does not implement commit()" .format(kind=type(self).__name__)) diff --git a/buildstream/_artifactcache/ostreecache.py b/buildstream/_artifactcache/ostreecache.py index 60591d077..6a7ee2a46 100644 --- a/buildstream/_artifactcache/ostreecache.py +++ b/buildstream/_artifactcache/ostreecache.py @@ -264,16 +264,13 @@ class OSTreeCache(ArtifactCache): # Args: # element (Element): The Element commit an artifact for # content (str): The element's content directory + # keys (list): The cache keys to use # - def commit(self, element, content): - # tag with strong cache key based on dependency versions used for the build - ref = buildref(element, element._get_cache_key()) - - # also store under weak cache key - weak_ref = buildref(element, element._get_cache_key(strength=_KeyStrength.WEAK)) + def commit(self, element, content, keys): + refs = [buildref(element, key) for key in keys] try: - _ostree.commit(self.repo, content, [ref, weak_ref]) + _ostree.commit(self.repo, content, refs) except OSTreeError as e: raise ArtifactError("Failed to commit artifact: {}".format(e)) from e diff --git a/buildstream/_artifactcache/tarcache.py b/buildstream/_artifactcache/tarcache.py index d0d019649..1806725d8 100644 --- a/buildstream/_artifactcache/tarcache.py +++ b/buildstream/_artifactcache/tarcache.py @@ -256,28 +256,17 @@ class TarCache(ArtifactCache): # # Implements artifactcache.commit(). # - def commit(self, element, content): - ref = tarpath(element, element._get_cache_key()) - weak_ref = tarpath(element, element._get_cache_key(strength=_KeyStrength.WEAK)) - + def commit(self, element, content, keys): os.makedirs(os.path.join(self.tardir, element._get_project().name, element.normal_name), exist_ok=True) with utils._tempdir() as temp: - refdir = os.path.join(temp, element._get_cache_key()) - shutil.copytree(content, refdir, symlinks=True) - - if ref != weak_ref: - weak_refdir = os.path.join(temp, element._get_cache_key(strength=_KeyStrength.WEAK)) - shutil.copytree(content, weak_refdir, symlinks=True) + for key in keys: + ref = tarpath(element, key) - Tar.archive(os.path.join(self.tardir, ref), - element._get_cache_key(), - temp) + refdir = os.path.join(temp, key) + shutil.copytree(content, refdir, symlinks=True) - if ref != weak_ref: - Tar.archive(os.path.join(self.tardir, weak_ref), - element._get_cache_key(strength=_KeyStrength.WEAK), - temp) + Tar.archive(os.path.join(self.tardir, ref), key, temp) # extract() # diff --git a/buildstream/element.py b/buildstream/element.py index 0d67f8dae..86bdb248b 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -1118,7 +1118,7 @@ class Element(Plugin): _yaml.dump(_yaml.node_sanitize(meta), os.path.join(metadir, 'artifact.yaml')) with self.timed_activity("Caching Artifact"): - self.__artifacts.commit(self, assembledir) + self.__artifacts.commit(self, assembledir, self.__get_cache_keys_for_commit()) # Finally cleanup the build dir cleanup_rootdir() @@ -1833,6 +1833,17 @@ class Element(Plugin): return self.__artifacts.extract(self, key) + def __get_cache_keys_for_commit(self): + keys = [] + + # tag with strong cache key based on dependency versions used for the build + keys.append(self._get_cache_key(strength=_KeyStrength.STRONG)) + + # also store under weak cache key + keys.append(self._get_cache_key(strength=_KeyStrength.WEAK)) + + return utils._deduplicate(keys) + def _load_public_data(self): self._assert_cached() assert(self.__dynamic_public is None) |