diff options
author | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-10-01 18:58:19 +0900 |
---|---|---|
committer | Tristan Van Berkom <tristan.vanberkom@codethink.co.uk> | 2017-10-01 19:11:53 +0900 |
commit | 935761a3e031c78e77c04b33f0c8a1701d192892 (patch) | |
tree | 2452e896cf9da50a49b3c51bd5181a467d349a91 | |
parent | 5bbec550b65835cc16d7c5e13f12e6c7f9b99d3d (diff) | |
download | buildstream-935761a3e031c78e77c04b33f0c8a1701d192892.tar.gz |
context.py: Add _get_overrides() and basic project override validation
This is just a step towards making the per-project overrides a little
bit more comprehensive in the code base.
Also, validation was missing on the overrides entirely.
-rw-r--r-- | buildstream/context.py | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/buildstream/context.py b/buildstream/context.py index 4ac1adc7a..8485bb035 100644 --- a/buildstream/context.py +++ b/buildstream/context.py @@ -118,9 +118,6 @@ class Context(): self.sched_error_action = 'continue' """What to do when a build fails in non interactive mode""" - self.project_overrides = {} - """Per-project overrides of project configurations""" - # Make sure the XDG vars are set in the environment before loading anything self._init_xdg() @@ -129,6 +126,7 @@ class Context(): self._message_handler = None self._message_depth = deque() self._platform = None + self._project_overrides = {} def load(self, config=None): """Loads the configuration files @@ -216,7 +214,12 @@ class Context(): self.sched_network_retries = _yaml.node_get(scheduler, int, 'network-retries') # Load per-projects overrides - self.project_overrides = _yaml.node_get(defaults, Mapping, 'projects', default_value={}) + self._project_overrides = _yaml.node_get(defaults, Mapping, 'projects', default_value={}) + + # Shallow validation of overrides, parts of buildstream which rely + # on the overrides are expected to validate elsewhere. + for project_name, overrides in _yaml.node_items(self._project_overrides): + _yaml.validate_node(overrides, ['artifacts']) profile_end(Topics.LOAD_CONTEXT, 'load') @@ -231,15 +234,20 @@ class Context(): # Private Methods used in BuildStream # ############################################################# - # _set_message_handler() + # _get_overrides(): # - # Sets the handler for any status messages propagated through - # the context. + # Fetch the override dictionary for the active project. This returns + # a node loaded from YAML and as such, values loaded from the returned + # node should be loaded using the _yaml.node_get() family of functions. # - # The message handler should have the same signature as - # the _message() method - def _set_message_handler(self, handler): - self._message_handler = handler + # Args: + # project: The Project + # + # Returns: + # (Mapping): The overrides dictionary for the specified project + # + def _get_overrides(self, project): + return _yaml.node_get(self._project_overrides, Mapping, project.name, default_value={}) # _get_cache_key(): # @@ -259,6 +267,16 @@ class Context(): return self._cache_key + # _set_message_handler() + # + # Sets the handler for any status messages propagated through + # the context. + # + # The message handler should have the same signature as + # the _message() method + def _set_message_handler(self, handler): + self._message_handler = handler + # _push_message_depth() / _pop_message_depth() # # For status messages, send the depth of timed |