summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2020-10-01 09:57:56 +0000
committerBenjamin Schubert <contact@benschubert.me>2020-10-05 09:55:05 +0000
commit818790da6b23aebea3e38afc9af5e137e8a11315 (patch)
tree4b86ead964ac8d63d299383eeba25b0a3b6fd923
parent8d9bf0249cf5293402304aacb5af98ddd4b23c24 (diff)
downloadbuildstream-bschubert/stricter-job-scheduler-separation.tar.gz
element.py: Ensure element methods with side effects on others are not called in jobsbschubert/stricter-job-scheduler-separation
This adds some assertions in the code to ensure we are not calling methods with side effects on the graph of elements in jobs.
-rw-r--r--src/buildstream/element.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index 7b3b704d2..91b809fca 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -1562,6 +1562,8 @@ class Element(Plugin):
# This unblocks pull/fetch/build.
#
def _set_required(self):
+ assert utils._is_main_process(), "This has an impact on all elements and must be run in the main process"
+
if self.__required:
# Already done
return
@@ -1597,6 +1599,8 @@ class Element(Plugin):
# required in the local cache.
#
def _set_artifact_files_required(self, scope=_Scope.RUN):
+ assert utils._is_main_process(), "This has an impact on all elements and must be run in the main process"
+
if self.__artifact_files_required:
# Already done
return
@@ -1645,6 +1649,8 @@ class Element(Plugin):
# in a subprocess.
#
def __schedule_assembly_when_necessary(self):
+ assert utils._is_main_process(), "This has an impact on all elements and must be run in the main process"
+
# FIXME: We could reduce the number of function calls a bit by
# factoring this out of this method (and checking whether we
# should schedule at the calling end).
@@ -1676,6 +1682,7 @@ class Element(Plugin):
#
def _assemble_done(self, successful):
assert self.__assemble_scheduled
+ assert utils._is_main_process(), "This has an impact on all elements and must be run in the main process"
self.__assemble_done = True
@@ -1873,6 +1880,8 @@ class Element(Plugin):
# fetched_original (bool): Whether the original sources had been asked (and fetched) or not
#
def _fetch_done(self, fetched_original):
+ assert utils._is_main_process(), "This has an impact on all elements and must be run in the main process"
+
self.__sources.fetch_done(fetched_original)
# _pull_pending()
@@ -1917,6 +1926,8 @@ class Element(Plugin):
# This will result in updating the element state.
#
def _pull_done(self):
+ assert utils._is_main_process(), "This has an impact on all elements and must be run in the main process"
+
self.__pull_done = True
# Artifact may become cached after pulling, so let it query the
@@ -2093,6 +2104,8 @@ class Element(Plugin):
# the workspaces metadata first.
#
def _open_workspace(self):
+ assert utils._is_main_process(), "This writes to a global file and therefore must be run in the main process"
+
context = self._get_context()
workspace = self._get_workspace()
assert workspace is not None
@@ -2393,6 +2406,8 @@ class Element(Plugin):
# the appropriate counters.
#
def _update_ready_for_runtime_and_cached(self):
+ assert utils._is_main_process(), "This has an impact on all elements and must be run in the main process"
+
if not self.__ready_for_runtime_and_cached:
if self.__runtime_deps_uncached == 0 and self.__cache_key and self._cached_success():
self.__ready_for_runtime_and_cached = True
@@ -3137,6 +3152,8 @@ class Element(Plugin):
# in Scope.BUILD has changed in any way.
#
def __update_cache_keys(self):
+ assert utils._is_main_process(), "This has an impact on all elements and must be run in the main process"
+
if self.__strict_cache_key is not None:
# Cache keys already calculated
assert self.__weak_cache_key is not None
@@ -3204,6 +3221,7 @@ class Element(Plugin):
# it can check whether an artifact exists for that cache key.
#
def __update_artifact_state(self):
+ assert utils._is_main_process(), "This has an impact on all elements and must be run in the main process"
assert self.__artifact is None
context = self._get_context()
@@ -3238,6 +3256,8 @@ class Element(Plugin):
# a remote cache).
#
def __update_cache_key_non_strict(self):
+ assert utils._is_main_process(), "This has an impact on all elements and must be run in the main process"
+
# The final cache key can be None here only in non-strict mode
if self.__cache_key is None:
if self._pull_pending():