James Ennis pushed to branch master at BuildStream / buildstream
Commits:
5 changed files:
- buildstream/plugins/elements/filter.py
- buildstream/plugins/elements/filter.yaml
- tests/elements/filter.py
- tests/elements/filter/basic/elements/deps-permitted.bst
- + tests/elements/filter/basic/elements/output-include-nonexistent-domain.bst
Changes:
... | ... | @@ -168,6 +168,8 @@ class FilterElement(Element): |
168 | 168 |
self.include = self.node_get_member(node, list, 'include')
|
169 | 169 |
self.exclude = self.node_get_member(node, list, 'exclude')
|
170 | 170 |
self.include_orphans = self.node_get_member(node, bool, 'include-orphans')
|
171 |
+ self.include_provenance = self.node_provenance(node, member_name='include')
|
|
172 |
+ self.exclude_provenance = self.node_provenance(node, member_name='exclude')
|
|
171 | 173 |
|
172 | 174 |
def preflight(self):
|
173 | 175 |
# Exactly one build-depend is permitted
|
... | ... | @@ -207,6 +209,31 @@ class FilterElement(Element): |
207 | 209 |
def assemble(self, sandbox):
|
208 | 210 |
with self.timed_activity("Staging artifact", silent_nested=True):
|
209 | 211 |
for dep in self.dependencies(Scope.BUILD, recurse=False):
|
212 |
+ # Check that all the included/excluded domains exist
|
|
213 |
+ pub_data = dep.get_public_data('bst')
|
|
214 |
+ split_rules = pub_data.get('split-rules', {})
|
|
215 |
+ unfound_includes = []
|
|
216 |
+ for domain in self.include:
|
|
217 |
+ if domain not in split_rules:
|
|
218 |
+ unfound_includes.append(domain)
|
|
219 |
+ unfound_excludes = []
|
|
220 |
+ for domain in self.exclude:
|
|
221 |
+ if domain not in split_rules:
|
|
222 |
+ unfound_excludes.append(domain)
|
|
223 |
+ |
|
224 |
+ detail = []
|
|
225 |
+ if unfound_includes:
|
|
226 |
+ detail.append("Unknown domains were used in {}".format(self.include_provenance))
|
|
227 |
+ detail.extend([' - {}'.format(domain) for domain in unfound_includes])
|
|
228 |
+ |
|
229 |
+ if unfound_excludes:
|
|
230 |
+ detail.append("Unknown domains were used in {}".format(self.exclude_provenance))
|
|
231 |
+ detail.extend([' - {}'.format(domain) for domain in unfound_excludes])
|
|
232 |
+ |
|
233 |
+ if detail:
|
|
234 |
+ detail = '\n'.join(detail)
|
|
235 |
+ raise ElementError("Unknown domains declared.", detail=detail)
|
|
236 |
+ |
|
210 | 237 |
dep.stage_artifact(sandbox, include=self.include,
|
211 | 238 |
exclude=self.exclude, orphans=self.include_orphans)
|
212 | 239 |
return ""
|
... | ... | @@ -6,9 +6,8 @@ config: |
6 | 6 |
# they were defined as public data in the parent
|
7 | 7 |
# element's 'split-rules'.
|
8 | 8 |
#
|
9 |
- # Since domains can be added, it is not an error to
|
|
10 |
- # specify domains which may not exist for all of the
|
|
11 |
- # elements in this composition.
|
|
9 |
+ # If a domain is specified that does not exist, the
|
|
10 |
+ # filter element will fail to build.
|
|
12 | 11 |
#
|
13 | 12 |
# The default empty list indicates that all domains
|
14 | 13 |
# of the parent's artifact should be included.
|
... | ... | @@ -484,3 +484,14 @@ def test_filter_include_with_indirect_deps(datafiles, cli, tmpdir): |
484 | 484 |
# indirect dependencies shouldn't be staged and filtered
|
485 | 485 |
assert not os.path.exists(os.path.join(checkout, "foo"))
|
486 | 486 |
assert not os.path.exists(os.path.join(checkout, "bar"))
|
487 |
+ |
|
488 |
+ |
|
489 |
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'basic'))
|
|
490 |
+def test_filter_fails_for_nonexisting_domain(datafiles, cli, tmpdir):
|
|
491 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
492 |
+ result = cli.run(project=project, args=['build', 'output-include-nonexistent-domain.bst'])
|
|
493 |
+ result.assert_main_error(ErrorDomain.STREAM, None)
|
|
494 |
+ |
|
495 |
+ error = "Unknown domains were used in output-include-nonexistent-domain.bst [line 7 column 2]"
|
|
496 |
+ assert error in result.stderr
|
|
497 |
+ assert '- unknown_file' in result.stderr
|
1 | 1 |
kind: filter
|
2 | 2 |
depends:
|
3 |
-- filename: output-include.bst
|
|
3 |
+- filename: input.bst
|
|
4 | 4 |
type: build
|
5 | 5 |
- filename: output-exclude.bst
|
6 | 6 |
type: runtime
|
1 |
+kind: filter
|
|
2 |
+depends:
|
|
3 |
+- filename: input.bst
|
|
4 |
+ type: build
|
|
5 |
+config:
|
|
6 |
+ include:
|
|
7 |
+ - unknown_file
|
|
8 |
+ |