diff options
author | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2018-02-22 12:57:54 +0000 |
---|---|---|
committer | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2018-03-01 12:48:35 +0000 |
commit | 3fb2b87e47f5259c6e77881ee53093754d3fd1a0 (patch) | |
tree | fa5eb8f95fff12269d06811bd061d2079926d5ca | |
parent | 543a0012560d5bcb709d8fc0d95bc4269109f920 (diff) | |
download | buildstream-3fb2b87e47f5259c6e77881ee53093754d3fd1a0.tar.gz |
Allow plugins to forbid runtime dependencies and sources
The flags BST_FORBID_RDEPENDS and BST_FORBID_SOURCES can be set in the
plugin's class declaration, and exceptions will be raised during
pre-flight checks
-rw-r--r-- | buildstream/_loader.py | 2 | ||||
-rw-r--r-- | buildstream/_pipeline.py | 2 | ||||
-rw-r--r-- | buildstream/element.py | 23 | ||||
-rw-r--r-- | buildstream/plugin.py | 11 |
4 files changed, 36 insertions, 2 deletions
diff --git a/buildstream/_loader.py b/buildstream/_loader.py index 2ced3abfa..de9efdd25 100644 --- a/buildstream/_loader.py +++ b/buildstream/_loader.py @@ -350,7 +350,7 @@ class Loader(): source = meta_element.project._create_source(meta_source.kind, meta_source) - source.preflight() + source._preflight() if source.get_consistency() != Consistency.CACHED: if self.context._fetch_subprojects: diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py index 7328d7d38..d1ab0f27c 100644 --- a/buildstream/_pipeline.py +++ b/buildstream/_pipeline.py @@ -164,7 +164,7 @@ class Pipeline(): def preflight(self): for plugin in self.dependencies(Scope.ALL, include_sources=True): try: - plugin.preflight() + plugin._preflight() except BstError as e: # Prepend the plugin identifier string to the error raised by # the plugin so that users can more quickly identify the issue diff --git a/buildstream/element.py b/buildstream/element.py index 2bd7abfca..8362f81ca 100644 --- a/buildstream/element.py +++ b/buildstream/element.py @@ -128,6 +128,14 @@ class Element(Plugin): any of the dependencies have changed. """ + BST_FORBID_RDEPENDS = False + """Whether to raise exceptions if an element has runtime-dependencies. + """ + + BST_FORBID_SOURCES = False + """Whether to raise exceptions if an element has sources. + """ + def __init__(self, context, project, artifacts, meta, plugin_conf): super().__init__(meta.name, context, project, meta.provenance, "element") @@ -1662,6 +1670,21 @@ class Element(Plugin): # Strong cache key could not be calculated yet return + def _preflight(self): + if self.BST_FORBID_RDEPENDS: + runtime_deps = list(self.dependencies(Scope.RUN, recurse=False)) + if runtime_deps: + raise ElementError("{}: Runtime dependencies are forbidden for elements of type {}" + .format(self, type(self).__name__), reason="element-forbidden-rdepends") + + if self.BST_FORBID_SOURCES: + sources = list(self.sources()) + if sources: + raise ElementError("{}: Sources are forbidden for elements of type {}" + .format(self, type(self).__name__), reason="element-forbidden-sources") + + self.preflight() + ############################################################# # Private Local Methods # ############################################################# diff --git a/buildstream/plugin.py b/buildstream/plugin.py index bfa37ef5b..353f13cc1 100644 --- a/buildstream/plugin.py +++ b/buildstream/plugin.py @@ -577,6 +577,17 @@ class Plugin(): else: yield self.__log + # _preflight(): + # Calls preflight() for the plugin, and allows generic preflight + # checks to be added + # + # Raises: + # SourceError: If it's a Source implementation + # ElementError: If it's an Element implementation + # ProgramNotFoundError: If a required host tool is not found + def _preflight(self): + self.preflight() + ############################################################# # Local Private Methods # ############################################################# |