diff options
-rw-r--r-- | src/buildstream/plugins/elements/filter.py | 9 | ||||
-rw-r--r-- | src/buildstream/plugins/elements/filter.yaml | 5 | ||||
-rw-r--r-- | tests/elements/filter.py | 29 | ||||
-rw-r--r-- | tests/elements/filter/basic/elements/input.bst | 3 | ||||
-rw-r--r-- | tests/elements/filter/basic/elements/no-pass-integration.bst | 6 | ||||
-rw-r--r-- | tests/elements/filter/basic/elements/pass-integration.bst | 6 |
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 |