summaryrefslogtreecommitdiff
path: root/buildstream/source.py
diff options
context:
space:
mode:
authorJonathan Maw <jonathan.maw@codethink.co.uk>2018-02-05 16:54:49 +0000
committerJürg Billeter <j@bitron.ch>2018-02-19 15:17:01 +0000
commit445372c4691f8ac020bc06d61f47ca4123f2c6f7 (patch)
treef6424aabac645c8cc61df0b43f9f098140157ae4 /buildstream/source.py
parentc81776249ac245ba0cea57de3fa5f625e57ee918 (diff)
downloadbuildstream-445372c4691f8ac020bc06d61f47ca4123f2c6f7.tar.gz
Add a 'sources' field to project.conf to override defaults
Equivalent to the 'elements' field, but slightly different because sources don't have accompanying yaml.
Diffstat (limited to 'buildstream/source.py')
-rw-r--r--buildstream/source.py29
1 files changed, 28 insertions, 1 deletions
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