diff options
author | Tristan van Berkom <tristan.vanberkom@codethink.co.uk> | 2020-08-11 18:29:02 +0900 |
---|---|---|
committer | Tristan van Berkom <tristan.vanberkom@codethink.co.uk> | 2020-08-13 16:38:33 +0900 |
commit | 830401ba6abbced060ceb5e833a5a76fea39a743 (patch) | |
tree | 12f96d582714f0a9c49939b3be7b478fb3340e66 | |
parent | dca535f43947543ce2dbc46b2408ed566811270e (diff) | |
download | buildstream-830401ba6abbced060ceb5e833a5a76fea39a743.tar.gz |
element.py: Early return in _initialize_state()
Instead of having an assertion here, lets just have an early return
and make the __resolved_initial_state variable internal private
(with two leading underscores).
We also stop checking for it in _pipeline.py before resolving state.
Some background:
* We only defer _initialize_state() to a later stage because
it can be a resource intensive task which interrogates the
disk or the local CAS, thus we have the Pipeline iterate
over the instantiated elements and resolve them separately
for better user feedback.
* Some "first pass" elements must have their state initialized
earlier, i.e. the "link" and "junction" elements need to be
usable during the load sequence.
-rw-r--r-- | src/buildstream/_pipeline.py | 3 | ||||
-rw-r--r-- | src/buildstream/element.py | 7 | ||||
-rw-r--r-- | tests/artifactcache/push.py | 4 |
3 files changed, 6 insertions, 8 deletions
diff --git a/src/buildstream/_pipeline.py b/src/buildstream/_pipeline.py index 42579af85..340c12b1a 100644 --- a/src/buildstream/_pipeline.py +++ b/src/buildstream/_pipeline.py @@ -115,8 +115,7 @@ class Pipeline: # greater value. for element in self.dependencies(targets, Scope.ALL): # Determine initial element state. - if not element._resolved_initial_state: - element._initialize_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 b57f10a66..f1e909bce 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -267,7 +267,7 @@ class Element(Plugin): self.__buildable_callback = None # Callback to BuildQueue self._depth = None # Depth of Element in its current dependency graph - self._resolved_initial_state = False # Whether the initial state of the Element has been resolved + self.__resolved_initial_state = False # Whether the initial state of the Element has been resolved # Ensure we have loaded this class's defaults self.__init_defaults(project, plugin_conf, meta.kind, meta.is_junction) @@ -1155,8 +1155,9 @@ class Element(Plugin): # the minimum amount of work is done. # def _initialize_state(self): - assert not self._resolved_initial_state, "_initialize_state() should only be called once" - self._resolved_initial_state = True + if self.__resolved_initial_state: + return + self.__resolved_initial_state = True # This will initialize source state. self.__sources.update_resolved_state() diff --git a/tests/artifactcache/push.py b/tests/artifactcache/push.py index 7160e05b4..07f2c2560 100644 --- a/tests/artifactcache/push.py +++ b/tests/artifactcache/push.py @@ -36,9 +36,7 @@ def _push(cli, cache_dir, project_dir, config_file, target): # This is duplicated from Pipeline.resolve_elements() # as this test does not use the cli frontend. for e in element.dependencies(Scope.ALL): - # Determine initial element state. - if not element._resolved_initial_state: - e._initialize_state() + e._initialize_state() # Manually setup the CAS remotes artifactcache.setup_remotes(use_config=True) |