summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Maw <jonathan.maw@codethink.co.uk>2018-02-22 12:57:54 +0000
committerJonathan Maw <jonathan.maw@codethink.co.uk>2018-03-01 17:27:28 +0000
commitc333adf4faaf2d18c1bf9a5321f083d574a994f4 (patch)
tree337c66bc44c7011bd957d171319673b8a73cd5c2
parente566bc05e28400295a2d27fab51a5285661b49a4 (diff)
downloadbuildstream-c333adf4faaf2d18c1bf9a5321f083d574a994f4.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.py2
-rw-r--r--buildstream/_pipeline.py2
-rw-r--r--buildstream/element.py23
-rw-r--r--buildstream/plugin.py11
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 #
#############################################################