diff options
author | Tristan van Berkom <tristan.vanberkom@codethink.co.uk> | 2020-08-09 20:14:43 +0900 |
---|---|---|
committer | Tristan van Berkom <tristan@codethink.co.uk> | 2020-09-18 12:38:49 +0900 |
commit | 42c5ee0a3a840756aae675a96b7b3c09e06b487d (patch) | |
tree | f14b74b70bf512bafda10b3ea75d946bc6f9fb0c /src/buildstream/_loader | |
parent | af478ca1b9a2855b0b0bcd71d4e33270853caade (diff) | |
download | buildstream-42c5ee0a3a840756aae675a96b7b3c09e06b487d.tar.gz |
element.py: Adding new configure_dependencies() public API method
This patch implements the essentials of the proposal to extend the
dependency attributes:
https://lists.apache.org/thread.html/r850aeb270200daade44261f16dbad403bf762e553b89dcafa0848fe7%40%3Cdev.buildstream.apache.org%3E
And essentially this will obsolete issue #931 by providing a more
suitable replacement for Element.search().
Summary of changes:
* _loader/loadelement.pyx: The Dependency object now loads the `config` node,
and raises an error if the `config` node is specified on a runtime-only
dependency.
* element.py: Created the new Element.configure_dependencies() virtual method.
If elements implement this method, then a list of all dependencies are
collected at element construction time and given to the implementing
(depending) element.
If a build dependency has more than one `config` specified, then
it will be given to the Element twice, and if there is no `config`
specified, then the tuple will still be given to the element with
a Null `config`.
Elements are provided via a new DependencyConfiguration type.
Diffstat (limited to 'src/buildstream/_loader')
-rw-r--r-- | src/buildstream/_loader/loadelement.pyx | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/buildstream/_loader/loadelement.pyx b/src/buildstream/_loader/loadelement.pyx index 858334c7d..80b96cd2c 100644 --- a/src/buildstream/_loader/loadelement.pyx +++ b/src/buildstream/_loader/loadelement.pyx @@ -74,6 +74,7 @@ cdef class Dependency: cdef readonly str junction # The junction path of the dependency name, if any cdef readonly bint strict # Whether this is a strict dependency cdef Node _node # The original node of the dependency + cdef readonly list config_nodes # The custom config nodes for Element.configure_dependencies() def __cinit__(self, LoadElement element = None, int dep_type = DependencyType.ALL): self.element = element @@ -81,6 +82,7 @@ cdef class Dependency: self.name = None self.junction = None self.strict = False + self.config_nodes = None self._node = None # provenance @@ -128,6 +130,7 @@ cdef class Dependency: # cdef load(self, Node dep, int default_dep_type): cdef str parsed_type + cdef MappingNode config_node self._node = dep self.element = None @@ -140,10 +143,10 @@ cdef class Dependency: elif type(dep) is MappingNode: if default_dep_type: - (<MappingNode> dep).validate_keys(['filename', 'junction', 'strict']) + (<MappingNode> dep).validate_keys([Symbol.FILENAME, Symbol.JUNCTION, Symbol.STRICT, Symbol.CONFIG]) self.dep_type = default_dep_type else: - (<MappingNode> dep).validate_keys(['filename', 'type', 'junction', 'strict']) + (<MappingNode> dep).validate_keys([Symbol.FILENAME, Symbol.TYPE, Symbol.JUNCTION, Symbol.STRICT, Symbol.CONFIG]) # Resolve the DependencyType parsed_type = (<MappingNode> dep).get_str(<str> Symbol.TYPE, None) @@ -162,6 +165,13 @@ cdef class Dependency: self.junction = (<MappingNode> dep).get_str(<str> Symbol.JUNCTION, None) self.strict = (<MappingNode> dep).get_bool(<str> Symbol.STRICT, False) + config_node = (<MappingNode> dep).get_mapping(<str> Symbol.CONFIG, None) + if config_node: + if self.dep_type == DependencyType.RUNTIME: + raise LoadError("{}: Specifying 'config' for a runtime dependency is not allowed" + .format(config_node.get_provenance()), LoadErrorReason.INVALID_DATA) + self.config_nodes = [config_node] + # Here we disallow explicitly setting 'strict' to False. # # This is in order to keep the door open to allowing the project.conf @@ -209,6 +219,11 @@ cdef class Dependency: self.dep_type = self.dep_type | other.dep_type self.strict = self.strict or other.strict + if self.config_nodes and other.config_nodes: + self.config_nodes.extend(other.config_nodes) + else: + self.config_nodes = self.config_nodes or other.config_nodes + # LoadElement(): # |