summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTristan Maat <tristan.maat@codethink.co.uk>2019-10-17 16:28:12 +0100
committerTristan Maat <tristan.maat@codethink.co.uk>2019-11-18 13:22:38 +0000
commit1514119c8287ab5583f26d4dc1b412f318f6adcf (patch)
tree8ab2a9fd772642aebdfa4ab47c3fb37a5d1f793f /src
parent516833fb68af32af80135639190ac7501df1c79f (diff)
downloadbuildstream-1514119c8287ab5583f26d4dc1b412f318f6adcf.tar.gz
element.py: Refactor `_schedule_assemble`
Move the logic that decides whether we can schedule an element for assembly *into* this function. This makes it a fair bit easier to grok, and reduces the complexity of `_update_state()`.
Diffstat (limited to 'src')
-rw-r--r--src/buildstream/element.py42
1 files changed, 32 insertions, 10 deletions
diff --git a/src/buildstream/element.py b/src/buildstream/element.py
index 5028cc5fa..8eea54c81 100644
--- a/src/buildstream/element.py
+++ b/src/buildstream/element.py
@@ -1254,16 +1254,9 @@ class Element(Plugin):
# If the element wasn't assembled and isn't scheduled to be assemble,
# or cached, or waiting to be pulled but has an artifact then schedule
# the assembly.
- if (
- not self.__assemble_scheduled
- and not self.__assemble_done
- and self.__artifact
- and self._is_required()
- and not self._cached()
- and not self._pull_pending()
- ):
- self._schedule_assemble()
+ scheduled = self._schedule_assemble()
+ if scheduled:
# If a build has been scheduled, we know that the element
# is not cached and can allow cache query even if the strict cache
# key is not available yet.
@@ -1556,13 +1549,40 @@ class Element(Plugin):
def _artifact_files_required(self):
return self.__artifact_files_required
+ # __can_schedule()
+ #
+ # Returns:
+ # bool - Whether the element can be scheduled for a build.
+ #
+ def __can_schedule(self):
+ # We're processing if we're already scheduled, we've
+ # finished assembling or if we're waiting to pull.
+ processing = self.__assemble_scheduled or self.__assemble_done or self._pull_pending()
+
+ # We can schedule when
+ return (
+ # We're not processing
+ not processing
+ and
+ # We're required for the current build
+ self._is_required()
+ and
+ # We have figured out the state of our artifact
+ self.__artifact
+ and
+ # And we're not cached yet
+ not self._cached()
+ )
+
# _schedule_assemble():
#
# This is called in the main process before the element is assembled
# in a subprocess.
#
def _schedule_assemble(self):
- assert not self.__assemble_scheduled
+ if not self.__can_schedule():
+ return False
+
self.__assemble_scheduled = True
# Requests artifacts of build dependencies
@@ -1578,6 +1598,8 @@ class Element(Plugin):
self._update_state()
+ return True
+
# _assemble_done():
#
# This is called in the main process after the element has been assembled