diff options
-rw-r--r-- | buildstream/_project.py | 8 | ||||
-rw-r--r-- | buildstream/source.py | 29 | ||||
-rw-r--r-- | doc/source/projectconf.rst | 22 |
3 files changed, 56 insertions, 3 deletions
diff --git a/buildstream/_project.py b/buildstream/_project.py index 6ff44b0a2..cb19b55e3 100644 --- a/buildstream/_project.py +++ b/buildstream/_project.py @@ -66,6 +66,7 @@ class Project(): self._variables = {} # The default variables overridden with project wide overrides self._environment = {} # The base sandbox environment self._elements = {} # Element specific configurations + self._sources = {} # Source specific configurations self._aliases = {} # Aliases dictionary self._workspaces = {} # Workspaces self._plugin_source_origins = [] # Origins of custom sources @@ -123,10 +124,13 @@ class Project(): project_conf = _yaml.load(projectfile) _yaml.composite(config, project_conf) - # Element type configurations will be composited later onto element types, - # so we delete it from here and run our final assertion after. + # Element and Source type configurations will be composited later onto + # element/source types, so we delete it from here and run our final + # assertion after. self._elements = _yaml.node_get(config, Mapping, 'elements', default_value={}) + self._sources = _yaml.node_get(config, Mapping, 'sources', default_value={}) config.pop('elements', None) + config.pop('sources', None) _yaml.node_final_assertions(config) _yaml.node_validate(config, [ 'format-version', diff --git a/buildstream/source.py b/buildstream/source.py index 590d0e262..d8c36ba99 100644 --- a/buildstream/source.py +++ b/buildstream/source.py @@ -23,6 +23,7 @@ Source """ import os +from collections import Mapping from contextlib import contextmanager from . import Plugin @@ -74,6 +75,9 @@ class Source(Plugin): All Sources derive from this class, this interface defines how the core will be interacting with Sources. """ + __defaults = {} # The defaults from the project + __defaults_set = False # Flag, in case there are not defaults at all + def __init__(self, context, project, meta): provenance = _yaml.node_get_provenance(meta.config) super().__init__(meta.name, context, project, provenance, "source") @@ -88,7 +92,11 @@ class Source(Plugin): self.__workspace = None # Directory of the currently active workspace self.__workspace_key = None # Cached directory content hashes for workspaced source - self.configure(meta.config) + # Collect the composited element configuration and + # ask the element to configure itself. + self.__init_defaults() + self.__config = self.__extract_config(meta) + self.configure(self.__config) COMMON_CONFIG_KEYS = ['kind', 'directory'] """Common source config keys @@ -97,6 +105,25 @@ class Source(Plugin): should be checked for using node_validate(). """ + def __init_defaults(self): + if not self.__defaults_set: + project = self._get_project() + sources = project._sources + type(self).__defaults = sources.get(self.get_kind(), {}) + type(self).__defaults_set = True + + # This will resolve the final configuration to be handed + # off to source.configure() + # + def __extract_config(self, meta): + config = _yaml.node_get(self.__defaults, Mapping, 'config', default_value={}) + config = _yaml.node_chain_copy(config) + + _yaml.composite(config, meta.config) + _yaml.node_final_assertions(config) + + return config + def get_mirror_directory(self): """Fetches the directory where this source should store things diff --git a/doc/source/projectconf.rst b/doc/source/projectconf.rst index ead949c6c..de19c9e84 100644 --- a/doc/source/projectconf.rst +++ b/doc/source/projectconf.rst @@ -503,6 +503,8 @@ be specified here. %{libdir}/lib*.la +.. _project_element_overrides: + Element Overrides ~~~~~~~~~~~~~~~~~ Base attributes declared by element default yaml files can be overridden @@ -527,6 +529,26 @@ variables, environments or plugin specific configuration data as shown below. PKG_CONFIG_PATH=%{libdir}/pkgconfig +.. _project_source_overrides: + +Source Overrides +~~~~~~~~~~~~~~~~ +Default values (overriding built-in defaults) can be set on a project +wide basis. The sources dictionary can be used to override plugin specific +configuration data as shown below. + + +.. code:: yaml + + sources: + + # Override default values for all git sources + git: + + config: + checkout-submodules: False + + .. _project_builtin_defaults: Builtin Defaults |