James Ennis pushed to branch jennis/warn_for_nonexistent_domains at BuildStream / buildstream
Commits:
-
78f831c0
by James Ennis at 2019-01-30T17:44:33Z
3 changed files:
- buildstream/plugins/elements/filter.py
- tests/elements/filter.py
- + tests/elements/filter/basic/elements/output-include-nonexistent-domain.bst
Changes:
| ... | ... | @@ -66,6 +66,8 @@ class FilterElement(Element): |
| 66 | 66 |
self.include = self.node_get_member(node, list, 'include')
|
| 67 | 67 |
self.exclude = self.node_get_member(node, list, 'exclude')
|
| 68 | 68 |
self.include_orphans = self.node_get_member(node, bool, 'include-orphans')
|
| 69 |
+ self.include_provenance = self.node_provenance(node, member_name='include')
|
|
| 70 |
+ self.exclude_provenance = self.node_provenance(node, member_name='exclude')
|
|
| 69 | 71 |
|
| 70 | 72 |
def preflight(self):
|
| 71 | 73 |
# Exactly one build-depend is permitted
|
| ... | ... | @@ -105,6 +107,31 @@ class FilterElement(Element): |
| 105 | 107 |
def assemble(self, sandbox):
|
| 106 | 108 |
with self.timed_activity("Staging artifact", silent_nested=True):
|
| 107 | 109 |
for dep in self.dependencies(Scope.BUILD, recurse=False):
|
| 110 |
+ # Check that all the included/excluded domains exist
|
|
| 111 |
+ pub_data = dep.get_public_data('bst')
|
|
| 112 |
+ split_rules = pub_data.get('split-rules', {})
|
|
| 113 |
+ unfound_includes = []
|
|
| 114 |
+ for domain in self.include:
|
|
| 115 |
+ if domain not in split_rules:
|
|
| 116 |
+ unfound_includes.append(domain)
|
|
| 117 |
+ unfound_excludes = []
|
|
| 118 |
+ for domain in self.exclude:
|
|
| 119 |
+ if domain not in split_rules:
|
|
| 120 |
+ unfound_excludes.append(domain)
|
|
| 121 |
+ |
|
| 122 |
+ detail = []
|
|
| 123 |
+ if unfound_includes:
|
|
| 124 |
+ detail.append("Unknown domains were used in {}".format(self.include_provenance))
|
|
| 125 |
+ detail.extend([' - {}'.format(domain) for domain in unfound_includes])
|
|
| 126 |
+ |
|
| 127 |
+ if unfound_excludes:
|
|
| 128 |
+ detail.append("Unknown domains were used in {}".format(self.exclude_provenance))
|
|
| 129 |
+ detail.extend([' - {}'.format(domain) for domain in unfound_excludes])
|
|
| 130 |
+ |
|
| 131 |
+ if detail:
|
|
| 132 |
+ detail = '\n'.join(detail)
|
|
| 133 |
+ raise ElementError("Unknown domains declared.", detail=detail)
|
|
| 134 |
+ |
|
| 108 | 135 |
dep.stage_artifact(sandbox, include=self.include,
|
| 109 | 136 |
exclude=self.exclude, orphans=self.include_orphans)
|
| 110 | 137 |
return ""
|
| ... | ... | @@ -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 |
+kind: filter
|
|
| 2 |
+depends:
|
|
| 3 |
+- filename: input.bst
|
|
| 4 |
+ type: build
|
|
| 5 |
+config:
|
|
| 6 |
+ include:
|
|
| 7 |
+ - unknown_file
|
|
| 8 |
+ |
