Tristan Van Berkom pushed to branch bst-1.2 at BuildStream / buildstream
Commits:
-
eb24011f
by Tristan Van Berkom at 2019-02-22T08:44:41Z
-
ad526441
by Tristan Van Berkom at 2019-02-22T08:44:41Z
-
79bbefe2
by Tristan Van Berkom at 2019-02-22T10:28:36Z
8 changed files:
- buildstream/element.py
- tests/frontend/overlaps.py
- + tests/frontend/overlaps/sub-collect.bst
- + tests/frontend/overlaps/sub-project/a-sub.bst
- + tests/frontend/overlaps/sub-project/files/a/file3
- + tests/frontend/overlaps/sub-project/files/z/file1
- + tests/frontend/overlaps/sub-project/files/z/file2
- + tests/frontend/overlaps/sub-project/z-sub.bst
Changes:
... | ... | @@ -685,6 +685,7 @@ class Element(Plugin): |
685 | 685 |
files_written = {}
|
686 | 686 |
old_dep_keys = {}
|
687 | 687 |
workspace = self._get_workspace()
|
688 |
+ project = self._get_project()
|
|
688 | 689 |
|
689 | 690 |
if self.__can_build_incrementally() and workspace.last_successful:
|
690 | 691 |
old_dep_keys = self.__get_artifact_metadata_dependencies(workspace.last_successful)
|
... | ... | @@ -746,9 +747,8 @@ class Element(Plugin): |
746 | 747 |
overlapping_elements = elements[1:]
|
747 | 748 |
for elm in overlapping_elements:
|
748 | 749 |
element = self.search(scope, elm)
|
749 |
- element_project = element._get_project()
|
|
750 | 750 |
if not element.__file_is_whitelisted(f):
|
751 |
- if element_project.fail_on_overlap:
|
|
751 |
+ if project.fail_on_overlap:
|
|
752 | 752 |
overlap_error_elements.append(elm)
|
753 | 753 |
overlap_error = True
|
754 | 754 |
else:
|
1 | 1 |
import os
|
2 | 2 |
import pytest
|
3 | 3 |
from tests.testutils.runcli import cli
|
4 |
+from tests.testutils import generate_junction
|
|
4 | 5 |
from buildstream._exceptions import ErrorDomain
|
5 | 6 |
from buildstream import _yaml
|
6 | 7 |
|
... | ... | @@ -10,15 +11,12 @@ DATA_DIR = os.path.join( |
10 | 11 |
"overlaps"
|
11 | 12 |
)
|
12 | 13 |
|
13 |
-project_template = {
|
|
14 |
- "name": "test",
|
|
15 |
- "element-path": "."
|
|
16 |
-}
|
|
17 | 14 |
|
18 |
- |
|
19 |
-def gen_project(project_dir, fail_on_overlap):
|
|
20 |
- template = dict(project_template)
|
|
21 |
- template["fail-on-overlap"] = fail_on_overlap
|
|
15 |
+def gen_project(project_dir, fail_on_overlap, project_name="test"):
|
|
16 |
+ template = {
|
|
17 |
+ "name": project_name,
|
|
18 |
+ "fail-on-overlap": fail_on_overlap
|
|
19 |
+ }
|
|
22 | 20 |
projectfile = os.path.join(project_dir, "project.conf")
|
23 | 21 |
_yaml.dump(template, projectfile)
|
24 | 22 |
|
... | ... | @@ -82,3 +80,30 @@ def test_overlaps_script(cli, datafiles): |
82 | 80 |
result = cli.run(project=project_dir, silent=True, args=[
|
83 | 81 |
'build', 'script.bst'])
|
84 | 82 |
result.assert_success()
|
83 |
+ |
|
84 |
+ |
|
85 |
+@pytest.mark.datafiles(DATA_DIR)
|
|
86 |
+@pytest.mark.parametrize("project_policy", [('fail'), ('warn')])
|
|
87 |
+@pytest.mark.parametrize("subproject_policy", [('fail'), ('warn')])
|
|
88 |
+def test_overlap_subproject(cli, tmpdir, datafiles, project_policy, subproject_policy):
|
|
89 |
+ project_dir = str(datafiles)
|
|
90 |
+ subproject_dir = os.path.join(project_dir, 'sub-project')
|
|
91 |
+ junction_path = os.path.join(project_dir, 'sub-project.bst')
|
|
92 |
+ |
|
93 |
+ gen_project(project_dir, bool(project_policy == 'fail'), project_name='test')
|
|
94 |
+ gen_project(subproject_dir, bool(subproject_policy == 'fail'), project_name='subtest')
|
|
95 |
+ generate_junction(tmpdir, subproject_dir, junction_path)
|
|
96 |
+ |
|
97 |
+ # Here we have a dependency chain where the project element
|
|
98 |
+ # always overlaps with the subproject element.
|
|
99 |
+ #
|
|
100 |
+ # Test that overlap error vs warning policy for this overlap
|
|
101 |
+ # is always controlled by the project and not the subproject.
|
|
102 |
+ #
|
|
103 |
+ result = cli.run(project=project_dir, silent=True, args=['build', 'sub-collect.bst'])
|
|
104 |
+ if project_policy == 'fail':
|
|
105 |
+ result.assert_main_error(ErrorDomain.STREAM, None)
|
|
106 |
+ result.assert_task_error(ErrorDomain.ELEMENT, "overlap-error")
|
|
107 |
+ else:
|
|
108 |
+ result.assert_success()
|
|
109 |
+ assert "WARNING Non-whitelisted overlaps detected" in result.stderr
|
1 |
+kind: compose
|
|
2 |
+ |
|
3 |
+depends:
|
|
4 |
+- filename: c.bst
|
|
5 |
+ type: build
|
|
6 |
+- filename: a-sub.bst
|
|
7 |
+ junction: sub-project.bst
|
|
8 |
+ type: build
|
|
9 |
+- filename: z-sub.bst
|
|
10 |
+ junction: sub-project.bst
|
|
11 |
+ type: build
|
1 |
+kind: import
|
|
2 |
+config:
|
|
3 |
+ source: /
|
|
4 |
+ target: /
|
|
5 |
+sources:
|
|
6 |
+- kind: local
|
|
7 |
+ path: "files/a"
|
1 |
+barny
|
1 |
+foo
|
1 |
+bar
|
1 |
+kind: import
|
|
2 |
+config:
|
|
3 |
+ source: /
|
|
4 |
+ target: /
|
|
5 |
+sources:
|
|
6 |
+- kind: local
|
|
7 |
+ path: "files/z"
|