summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Coldrick <thomas.coldrick@codethink.co.uk>2019-09-10 11:14:45 +0100
committerThomas Coldrick <othko97@gmail.com>2019-09-16 06:55:56 +0000
commitb2af82add70ca6c582d08d916fb243493de397e2 (patch)
tree417f41ff5448489e3589bb5207838768761324a1
parent8ff9262d9843a8e858a594c787ddbd156b4b3d3b (diff)
downloadbuildstream-b2af82add70ca6c582d08d916fb243493de397e2.tar.gz
filter.py: Fail if parent element is a stack
As stack elements do not provide any artifacts, it is misleading to allow them as dependencies for filter elements. This commit makes a dependency on a stack element a failure with a descriptive error message. Additionally adds a test to make sure this works. Addresses #1104
-rw-r--r--src/buildstream/plugins/elements/filter.py7
-rw-r--r--tests/elements/filter.py8
-rw-r--r--tests/elements/filter/basic/elements/forbidden-stack-dep.bst4
-rw-r--r--tests/elements/filter/basic/elements/stack.bst3
4 files changed, 22 insertions, 0 deletions
diff --git a/src/buildstream/plugins/elements/filter.py b/src/buildstream/plugins/elements/filter.py
index 795d8910b..2f9204215 100644
--- a/src/buildstream/plugins/elements/filter.py
+++ b/src/buildstream/plugins/elements/filter.py
@@ -200,6 +200,13 @@ class FilterElement(Element):
.format(self, type(self).__name__),
detail=detail, reason="filter-bdepend-also-rdepend")
+ # If a stack, fail and inform user that the dependency can't be a stack
+ if build_deps[0].get_kind() == 'stack':
+ detail = "{} is a stack element, which has no artifact".format(build_deps[0].name)
+ raise ElementError("{}: {} element's build dependency must not be a stack element"
+ .format(self, type(self).__name__),
+ detail=detail, reason="filter-bdepend-is-stack")
+
def get_unique_key(self):
key = {
'include': sorted(self.include),
diff --git a/tests/elements/filter.py b/tests/elements/filter.py
index ea6bd2306..b8dd4351e 100644
--- a/tests/elements/filter.py
+++ b/tests/elements/filter.py
@@ -551,3 +551,11 @@ def test_filter_pass_integration(datafiles, cli):
result = cli.run(project=project, args=['artifact', 'checkout', '--integrate',
'--directory', checkout_dir, 'pass-integration.bst'])
result.assert_main_error(ErrorDomain.STREAM, "missing-command")
+
+
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
+def test_filter_stack_depend_failure(datafiles, cli):
+ project = str(datafiles)
+
+ result = cli.run(project=project, args=['build', 'forbidden-stack-dep.bst'])
+ result.assert_main_error(ErrorDomain.ELEMENT, "filter-bdepend-is-stack")
diff --git a/tests/elements/filter/basic/elements/forbidden-stack-dep.bst b/tests/elements/filter/basic/elements/forbidden-stack-dep.bst
new file mode 100644
index 000000000..6624c5d9a
--- /dev/null
+++ b/tests/elements/filter/basic/elements/forbidden-stack-dep.bst
@@ -0,0 +1,4 @@
+kind: filter
+depends:
+- filename: stack.bst
+ type: build
diff --git a/tests/elements/filter/basic/elements/stack.bst b/tests/elements/filter/basic/elements/stack.bst
new file mode 100644
index 000000000..daea67ccf
--- /dev/null
+++ b/tests/elements/filter/basic/elements/stack.bst
@@ -0,0 +1,3 @@
+kind: stack
+depends:
+- filename: input.bst