diff options
author | Jürg Billeter <j@bitron.ch> | 2017-12-21 17:10:56 +0100 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2018-01-12 11:21:57 +0100 |
commit | bc492fa8f3973367c3817c84064629f3975b22bd (patch) | |
tree | 1947c66bfb0f2440b3183fda2209af739d14aa75 /buildstream/_artifactcache/tarcache.py | |
parent | 170a9d469a36337990a324d4be2b5c42306b1b13 (diff) | |
download | buildstream-bc492fa8f3973367c3817c84064629f3975b22bd.tar.gz |
Use explicit element state updates
This adds the _update_state() method to the Element class to keep track
of element state and avoid calculating the same cache key multiple
times. This also consolidates the different get_cache_key
methods into a single method that always returns the cache key
calculated by _update_state(), if available.
Fixes #149, #173
Diffstat (limited to 'buildstream/_artifactcache/tarcache.py')
-rw-r--r-- | buildstream/_artifactcache/tarcache.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/buildstream/_artifactcache/tarcache.py b/buildstream/_artifactcache/tarcache.py index 5f8fc7410..82487f077 100644 --- a/buildstream/_artifactcache/tarcache.py +++ b/buildstream/_artifactcache/tarcache.py @@ -252,8 +252,10 @@ class TarCache(ArtifactCache): if strength is None: strength = _KeyStrength.STRONG if element._get_strict() else _KeyStrength.WEAK - key = element._get_cache_key(strength) - + if strength == _KeyStrength.STRONG: + key = element._get_strict_cache_key() + else: + key = element._get_cache_key(strength) if not key: return False @@ -279,13 +281,13 @@ class TarCache(ArtifactCache): # Implements artifactcache.commit(). # def commit(self, element, content): - ref = tarpath(element, element._get_cache_key_for_build()) + ref = tarpath(element, element._get_cache_key()) weak_ref = tarpath(element, element._get_cache_key(strength=_KeyStrength.WEAK)) 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_for_build()) + refdir = os.path.join(temp, element._get_cache_key()) shutil.copytree(content, refdir, symlinks=True) if ref != weak_ref: @@ -293,7 +295,7 @@ class TarCache(ArtifactCache): shutil.copytree(content, weak_refdir, symlinks=True) Tar.archive(os.path.join(self.tardir, ref), - element._get_cache_key_for_build(), + element._get_cache_key(), temp) if ref != weak_ref: @@ -307,7 +309,7 @@ class TarCache(ArtifactCache): # def extract(self, element): - key = element._get_cache_key() + key = element._get_strict_cache_key() ref = buildref(element, key) path = tarpath(element, key) |