diff options
author | James Ennis <james.ennis@codethink.co.uk> | 2019-05-16 14:23:42 +0100 |
---|---|---|
committer | James Ennis <james.ennis@codethink.co.uk> | 2019-06-07 14:47:16 +0100 |
commit | 3427cea53ed9f4c6517606fd13abf2d06352f8d2 (patch) | |
tree | f7f2b2640c63d4bccf78a64ee4c6fe924130fdf8 | |
parent | 322be88402c96530c6d6decfa0224dd31b71801f (diff) | |
download | buildstream-3427cea53ed9f4c6517606fd13abf2d06352f8d2.tar.gz |
element.py: Add callbacks to be used upon specific state changes
This commit introduces three callback functions which will be used
to callback to relevant queues upon specific state changes:
when an element becomes required, when an element becomes able
to query the cache and when an element becomes buildable.
-rw-r--r-- | src/buildstream/element.py | 84 |
1 files changed, 82 insertions, 2 deletions
diff --git a/src/buildstream/element.py b/src/buildstream/element.py index 7bf3ebbd3..355773f76 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -239,6 +239,11 @@ class Element(Plugin): self.__batch_prepare_assemble_flags = 0 # Sandbox flags for batching across prepare()/assemble() self.__batch_prepare_assemble_collect = None # Collect dir for batching across prepare()/assemble() + # Callbacks + self.__required_callback = None # Callback to Queues + self.__can_query_cache_callback = None # Callback to PullQueue/FetchQueue + self.__buildable_callback = None # Callback to BuildQueue + # Ensure we have loaded this class's defaults self.__init_defaults(project, plugin_conf, meta.kind, meta.is_junction) @@ -1182,9 +1187,14 @@ class Element(Plugin): if self._get_workspace() and self.__assemble_scheduled: # If we have an active workspace and are going to build, then - # discard current cache key values as their correct values can only - # be calculated once the build is complete + # discard current cache key values and invoke the buildable callback. + # The correct keys can only be calculated once the build is complete self.__reset_cache_data() + + if self.__buildable_callback is not None and self._buildable(): + self.__buildable_callback(self) + self.__buildable_callback = None + return self.__update_cache_keys() @@ -1202,6 +1212,13 @@ class Element(Plugin): not self._cached_success() and not self._pull_pending()): self._schedule_assemble() + + # 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. + if self.__can_query_cache_callback is not None: + self.__can_query_cache_callback(self) + return if not context.get_strict(): @@ -1218,6 +1235,10 @@ class Element(Plugin): self.__ready_for_runtime_and_cached = all( dep.__ready_for_runtime_and_cached for dep in self.__runtime_dependencies) + if self.__buildable_callback is not None and self._buildable(): + self.__buildable_callback(self) + self.__buildable_callback = None + # _get_display_key(): # # Returns cache keys for display purposes @@ -1500,6 +1521,11 @@ class Element(Plugin): self._update_state() + # Callback to the Queue + if self.__required_callback is not None: + self.__required_callback(self) + self.__required_callback = None + # _is_required(): # # Returns whether this element has been marked as required. @@ -2234,6 +2260,56 @@ class Element(Plugin): else: return True + # _set_required_callback() + # + # + # Notify the pull/fetch/build queue that the element is potentially + # ready to be processed. + # + # _Set the _required_callback - the _required_callback is invoked when an + # element is marked as required. This informs us that the element needs to + # either be pulled or fetched + built. + # + # Args: + # callback (callable) - The callback function + # + def _set_required_callback(self, callback): + self.__required_callback = callback + + # _set_can_query_cache_callback() + # + # Notify the pull/fetch queue that the element is potentially + # ready to be processed. + # + # Set the _can_query_cache_callback - the _can_query_cache_callback is + # invoked when an element becomes able to query the cache. That is, + # the (non-workspaced) element's strict cache key has been calculated. + # However, if the element is workspaced, we also invoke this callback + # once its build has been scheduled - this ensures that the workspaced + # element does not get blocked in the pull queue. + # + # Args: + # callback (callable) - The callback function + # + def _set_can_query_cache_callback(self, callback): + self.__can_query_cache_callback = callback + + # _set_buildable_callback() + # + # Notifiy the build queue that the element is potentially ready + # to be processed + # + # Set the _buildable_callback - the _buildable_callback is invoked when + # an element is marked as "buildable". That is, its sources are consistent, + # its been scheduled to be built and all of its build dependencies have + # had their cache key's calculated and are cached. + # + # Args: + # callback (callable) - The callback function + # + def _set_buildable_callback(self, callback): + self.__buildable_callback = callback + ############################################################# # Private Local Methods # ############################################################# @@ -2945,6 +3021,10 @@ class Element(Plugin): ] self.__strict_cache_key = self._calculate_cache_key(dependencies) + if self.__strict_cache_key is not None and self.__can_query_cache_callback is not None: + self.__can_query_cache_callback(self) + self.__can_query_cache_callback = None + # __update_artifact_state() # # Updates the data involved in knowing about the artifact corresponding |