summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Coldrick <thomas.coldrick@codethink.co.uk>2019-09-10 10:53:17 +0100
committerDarius Makovsky <traveltissues@protonmail.com>2019-09-18 14:50:16 +0100
commit06096116fae63dc34b3e851e6b8d2f737106fcc0 (patch)
treeb566da3f861a1b1e1d0ebe10692d3e50506691ef
parentf841779dd19da7404de702887ccba7da0ec50c46 (diff)
downloadbuildstream-06096116fae63dc34b3e851e6b8d2f737106fcc0.tar.gz
filter.py: Allow passing integration commands
It is tedious to manually copy the integration commands of the parent element into a filter element, so this allows it to be done automatically. Here we modify FilterElement.integrate() to allow us to pass through the parent's integration commands, iff an option is set. Also adds a test for the new feature, but this is not as comprehensive as would be idea, as getting to the integration commands which are run is a little more difficult. Addresses #1107
-rw-r--r--src/buildstream/plugins/elements/filter.py9
-rw-r--r--src/buildstream/plugins/elements/filter.yaml5
-rw-r--r--tests/elements/filter.py29
-rw-r--r--tests/elements/filter/basic/elements/input.bst3
-rw-r--r--tests/elements/filter/basic/elements/no-pass-integration.bst6
-rw-r--r--tests/elements/filter/basic/elements/pass-integration.bst6
6 files changed, 57 insertions, 1 deletions
diff --git a/src/buildstream/plugins/elements/filter.py b/src/buildstream/plugins/elements/filter.py
index c2c2e0125..795d8910b 100644
--- a/src/buildstream/plugins/elements/filter.py
+++ b/src/buildstream/plugins/elements/filter.py
@@ -168,7 +168,7 @@ class FilterElement(Element):
def configure(self, node):
node.validate_keys([
- 'include', 'exclude', 'include-orphans'
+ 'include', 'exclude', 'include-orphans', 'pass-integration'
])
self.include_node = node.get_sequence('include')
@@ -177,6 +177,7 @@ class FilterElement(Element):
self.include = self.include_node.as_str_list()
self.exclude = self.exclude_node.as_str_list()
self.include_orphans = node.get_bool('include-orphans')
+ self.pass_integration = node.get_bool('pass-integration', False)
def preflight(self):
# Exactly one build-depend is permitted
@@ -252,6 +253,12 @@ class FilterElement(Element):
output_elm = build_deps[0]._get_source_element()
return output_elm
+ def integrate(self, sandbox):
+ if self.pass_integration:
+ for dep in self.dependencies(Scope.BUILD, recurse=False):
+ dep.integrate(sandbox)
+ super().integrate(sandbox)
+
def setup():
return FilterElement
diff --git a/src/buildstream/plugins/elements/filter.yaml b/src/buildstream/plugins/elements/filter.yaml
index 9c2bf69f4..12a82a9cb 100644
--- a/src/buildstream/plugins/elements/filter.yaml
+++ b/src/buildstream/plugins/elements/filter.yaml
@@ -27,3 +27,8 @@ config:
# the parent element.
#
include-orphans: False
+
+ # Whether to pass the 'integration-commands' of the
+ # parent element through the filter.
+ #
+ pass-integration: False
diff --git a/tests/elements/filter.py b/tests/elements/filter.py
index d8370c6bb..ea6bd2306 100644
--- a/tests/elements/filter.py
+++ b/tests/elements/filter.py
@@ -522,3 +522,32 @@ def test_filter_fails_for_nonexisting_domain(datafiles, cli):
error = "Unknown domains were used in output-include-nonexistent-domain.bst [line 7 column 2]"
assert error in result.stderr
assert '- unknown_file' in result.stderr
+
+# TODO: Figure out how to check if the passed integration commands
+# are actually correct, this just makes sure things build and
+# some integration commands attempt to run
+#
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
+def test_filter_pass_integration(datafiles, cli):
+ project = str(datafiles)
+
+ # Explicitly not passing integration commands should be fine
+ result = cli.run(project=project, args=['build', 'no-pass-integration.bst'])
+ result.assert_success()
+
+ # Passing integration commands should build nicely
+ result = cli.run(project=project, args=['build', 'pass-integration.bst'])
+ result.assert_success()
+
+ # Checking out elements which don't pass integration commands should still work
+ checkout_dir = os.path.join(project, 'no-pass')
+ result = cli.run(project=project, args=['artifact', 'checkout', '--integrate',
+ '--directory', checkout_dir, 'no-pass-integration.bst'])
+ result.assert_success()
+
+ # Checking out the artifact should fail if we run integration commands, as
+ # the staged artifacts don't have a shell
+ checkout_dir = os.path.join(project, 'pass')
+ result = cli.run(project=project, args=['artifact', 'checkout', '--integrate',
+ '--directory', checkout_dir, 'pass-integration.bst'])
+ result.assert_main_error(ErrorDomain.STREAM, "missing-command")
diff --git a/tests/elements/filter/basic/elements/input.bst b/tests/elements/filter/basic/elements/input.bst
index fb3f5d194..94d8c17c4 100644
--- a/tests/elements/filter/basic/elements/input.bst
+++ b/tests/elements/filter/basic/elements/input.bst
@@ -9,3 +9,6 @@ public:
- /foo
bar:
- /bar
+ integration-commands:
+ - foo
+ - bar
diff --git a/tests/elements/filter/basic/elements/no-pass-integration.bst b/tests/elements/filter/basic/elements/no-pass-integration.bst
new file mode 100644
index 000000000..e512ade01
--- /dev/null
+++ b/tests/elements/filter/basic/elements/no-pass-integration.bst
@@ -0,0 +1,6 @@
+kind: filter
+depends:
+- filename: input.bst
+ type: build
+config:
+ pass-integration: False
diff --git a/tests/elements/filter/basic/elements/pass-integration.bst b/tests/elements/filter/basic/elements/pass-integration.bst
new file mode 100644
index 000000000..77b462cd0
--- /dev/null
+++ b/tests/elements/filter/basic/elements/pass-integration.bst
@@ -0,0 +1,6 @@
+kind: filter
+depends:
+- filename: input.bst
+ type: build
+config:
+ pass-integration: True