You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by tv...@apache.org on 2021/02/04 07:24:57 UTC

[buildstream] branch key-calc created (now cc08185)

This is an automated email from the ASF dual-hosted git repository.

tvb pushed a change to branch key-calc
in repository https://gitbox.apache.org/repos/asf/buildstream.git.


      at cc08185  element.py: Calculate effective cache key before calling plugin methods

This branch includes the following new commits:

     new cc08185  element.py: Calculate effective cache key before calling plugin methods

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[buildstream] 01/01: element.py: Calculate effective cache key before calling plugin methods

Posted by tv...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tvb pushed a commit to branch key-calc
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit cc08185235a0375cf5488e2f21be064f41cfb5ba
Author: Jürg Billeter <j...@bitron.ch>
AuthorDate: Fri Jul 21 13:25:40 2017 +0200

    element.py: Calculate effective cache key before calling plugin methods
---
 buildstream/_artifactcache/artifactcache.py |  6 +++---
 buildstream/element.py                      | 11 +++++++++--
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/buildstream/_artifactcache/artifactcache.py b/buildstream/_artifactcache/artifactcache.py
index a7208e8..4e0d703 100644
--- a/buildstream/_artifactcache/artifactcache.py
+++ b/buildstream/_artifactcache/artifactcache.py
@@ -220,12 +220,12 @@ class ArtifactCache():
     #     element (Element): The Element commit an artifact for
     #     content (str): The element's content directory
     #
-    def commit(self, element, content):
+    def commit(self, key, weak_key, element, content):
         # tag with strong cache key based on dependency versions used for the build
-        ref = buildref(element, element._get_cache_key_for_build())
+        ref = buildref(element, key)
 
         # also store under weak cache key
-        weak_ref = buildref(element, element._get_cache_key(strength=_KeyStrength.WEAK))
+        weak_ref = buildref(element, weak_key)
 
         _ostree.commit(self.repo, content, ref, weak_ref)
 
diff --git a/buildstream/element.py b/buildstream/element.py
index 60e81fd..0d0a68d 100644
--- a/buildstream/element.py
+++ b/buildstream/element.py
@@ -1015,6 +1015,11 @@ class Element(Plugin):
                 # The plugin's assemble() method may modify this, though.
                 self.__dynamic_public = self.__public
 
+                # Calculate effective cache key before calling plugin methods
+                # to ensure the key is not affected by any side-effects of
+                # these methods
+                effective_cache_key = self._get_cache_key_for_build()
+
                 # Call the abstract plugin methods
                 try:
                     # Step 1 - Configure
@@ -1067,7 +1072,7 @@ class Element(Plugin):
                     }
                     meta = {
                         'keys': {
-                            'strong': self._get_cache_key_for_build(),
+                            'strong': effective_cache_key,
                             'weak': self._get_cache_key(_KeyStrength.WEAK),
                             'dependencies': dependencies
                         },
@@ -1077,7 +1082,9 @@ 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(effective_cache_key,
+                                                self._get_cache_key(strength=_KeyStrength.WEAK),
+                                                self, assembledir)
 
             # Finally cleanup the build dir
             shutil.rmtree(rootdir)