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

root pushed a commit to branch tlater/test_workspace_visible
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit 34d38738da8e8db3b751e5918cfb70d3b29e2a58
Author: Tristan Maat <[email protected]>
AuthorDate: Fri Oct 18 17:54:42 2019 +0100

    Create _initialize_state() to capture an _update_state() use case
---
 src/buildstream/_artifactelement.py |  7 ++++---
 src/buildstream/_loader/loader.py   |  6 +-----
 src/buildstream/_pipeline.py        |  3 +--
 src/buildstream/element.py          | 15 +++++++++++++--
 tests/artifactcache/push.py         |  3 +--
 5 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/src/buildstream/_artifactelement.py 
b/src/buildstream/_artifactelement.py
index 0baf634..c5df67e 100644
--- a/src/buildstream/_artifactelement.py
+++ b/src/buildstream/_artifactelement.py
@@ -78,10 +78,11 @@ class ArtifactElement(Element):
             return cls.__instantiated_artifacts[ref]
 
         artifact_element = ArtifactElement(context, ref)
-        # XXX: We need to call update state as it is responsible for
+        # XXX: We need to call initialize_state as it is responsible for
         # initialising an Element/ArtifactElement's Artifact (__artifact)
-        artifact_element._update_source_state()
-        artifact_element._update_state()
+        #
+        # Not sure why _source_state is important for this, though...
+        artifact_element._initialize_state()
         cls.__instantiated_artifacts[ref] = artifact_element
 
         for dep_ref in artifact_element.get_dependency_refs(Scope.BUILD):
diff --git a/src/buildstream/_loader/loader.py 
b/src/buildstream/_loader/loader.py
index d89db13..c5970fd 100644
--- a/src/buildstream/_loader/loader.py
+++ b/src/buildstream/_loader/loader.py
@@ -633,11 +633,7 @@ class Loader():
                 LoadErrorReason.INVALID_JUNCTION)
 
         element = Element._new_from_meta(meta_element)
-        element._update_source_state()
-        # FIXME: We're doubly updating here for the moment; this
-        # should be removed once we don't need the entirety of
-        # _update_state() anymore
-        element._update_state()
+        element._initialize_state()
 
         # If this junction element points to a sub-sub-project, we need to
         # find loader for that project.
diff --git a/src/buildstream/_pipeline.py b/src/buildstream/_pipeline.py
index c13cb05..39d5bc3 100644
--- a/src/buildstream/_pipeline.py
+++ b/src/buildstream/_pipeline.py
@@ -152,8 +152,7 @@ class Pipeline():
             for element in self.dependencies(targets, Scope.ALL):
                 # Determine initial element state.
                 if not element._resolved_initial_state:
-                    element._update_source_state()
-                    element._update_state()
+                    element._initialize_state()
 
                 # We may already have Elements which are cached and have their 
runtimes
                 # cached, if this is the case, we should immediately notify 
their reverse
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index 860c728..975f67c 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -1251,6 +1251,16 @@ class Element(Plugin):
         # cache cannot be queried until strict cache key is available
         return self.__strict_cache_key is not None
 
+    def _initialize_state(self):
+        # assert not self._resolved_initial_state, "_initialize_state() should 
only be called once"
+        self._resolved_initial_state = True
+
+        self._update_source_state()
+        # FIXME: This should be unrolled; currently we're doing the
+        # work twice because _update_source_state() *probably* calls
+        # it, but might not.
+        self._update_state()
+
     # _update_state()
     #
     # Keep track of element state. Calculate cache keys if possible and
@@ -1259,8 +1269,9 @@ class Element(Plugin):
     # This must be called whenever the state of an element may have changed.
     #
     def _update_state(self):
-        if not self._resolved_initial_state:
-            self._resolved_initial_state = True
+        # assert self._resolved_initial_state, "_initialize_state() should be 
called first"
+        self._resolved_initial_state = True
+
         context = self._get_context()
 
         if self._get_consistency() == Consistency.INCONSISTENT:
diff --git a/tests/artifactcache/push.py b/tests/artifactcache/push.py
index d7757c3..ae7d370 100644
--- a/tests/artifactcache/push.py
+++ b/tests/artifactcache/push.py
@@ -40,8 +40,7 @@ def _push(cli, cache_dir, project_dir, config_file, target):
         # as this test does not use the cli frontend.
         for e in element.dependencies(Scope.ALL):
             # Determine initial element state.
-            e._update_source_state()
-            e._update_state()
+            e._initialize_state()
 
         # Manually setup the CAS remotes
         artifactcache.setup_remotes(use_config=True)

Reply via email to