diff options
author | bst-marge-bot <marge-bot@buildstream.build> | 2020-05-18 10:23:20 +0000 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2020-05-18 10:23:20 +0000 |
commit | 0c9ca749b32c2ed8b41e6f94e7c6f5431eae4d70 (patch) | |
tree | d19365ab5f2359ad3b34c3b958b82a1e0ffefc9b | |
parent | 4819011147ab67462d9e378938a9139b479d5fe7 (diff) | |
parent | b8b40314740c118398641a3b86655a8b0434631d (diff) | |
download | buildstream-0c9ca749b32c2ed8b41e6f94e7c6f5431eae4d70.tar.gz |
Merge branch 'chandan/duplicate-format-deps' into 'master'
Ensure there are no duplicates in Elements.dependencies()
Closes #1308
See merge request BuildStream/buildstream!1931
-rw-r--r-- | src/buildstream/element.py | 15 | ||||
-rw-r--r-- | tests/frontend/project/elements/format-deps.bst | 17 | ||||
-rw-r--r-- | tests/frontend/show.py | 8 |
3 files changed, 32 insertions, 8 deletions
diff --git a/src/buildstream/element.py b/src/buildstream/element.py index fa39eba12..404cae5e7 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -83,7 +83,7 @@ from contextlib import contextmanager from functools import partial from itertools import chain import string -from typing import cast, TYPE_CHECKING, Any, Dict, Iterator, List, Optional +from typing import cast, TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Set from pyroaring import BitMap # pylint: disable=no-name-in-module @@ -113,7 +113,7 @@ from .storage.directory import VirtualDirectoryError if TYPE_CHECKING: from .node import MappingNode, ScalarNode, SequenceNode from .types import SourceRef - from typing import Set, Tuple + from typing import Tuple # pylint: disable=cyclic-import from .sandbox import Sandbox @@ -441,10 +441,17 @@ class Element(Plugin): # containing element that have been visited for the `Scope.BUILD` case # and the second one relating to the `Scope.RUN` case. if not recurse: + result: Set[Element] = set() if scope in (Scope.BUILD, Scope.ALL): - yield from self.__build_dependencies + for dep in self.__build_dependencies: + if dep not in result: + result.add(dep) + yield dep if scope in (Scope.RUN, Scope.ALL): - yield from self.__runtime_dependencies + for dep in self.__runtime_dependencies: + if dep not in result: + result.add(dep) + yield dep else: def visit(element, scope, visited): diff --git a/tests/frontend/project/elements/format-deps.bst b/tests/frontend/project/elements/format-deps.bst new file mode 100644 index 000000000..58a46891b --- /dev/null +++ b/tests/frontend/project/elements/format-deps.bst @@ -0,0 +1,17 @@ +kind: import + +description: > + It is important that this element has both and build and runtime dependencies. + It is also important that it has a dependency that is needed at both build + time and runtime. + +sources: +- kind: local + path: files/etc-files + +depends: +- import-links.bst +build-depends: +- import-dev.bst +runtime-depends: +- import-bin.bst diff --git a/tests/frontend/show.py b/tests/frontend/show.py index 17931ffe3..4be4b72e9 100644 --- a/tests/frontend/show.py +++ b/tests/frontend/show.py @@ -399,14 +399,14 @@ def test_exceed_max_recursion_depth(cli, tmpdir, dependency_depth): @pytest.mark.parametrize( "dep_kind, expected_deps", [ - ("%{deps}", "[import-dev.bst, import-bin.bst]"), - ("%{build-deps}", "[import-dev.bst]"), - ("%{runtime-deps}", "[import-bin.bst]"), + ("%{deps}", "[import-dev.bst, import-links.bst, import-bin.bst]"), + ("%{build-deps}", "[import-dev.bst, import-links.bst]"), + ("%{runtime-deps}", "[import-links.bst, import-bin.bst]"), ], ) def test_format_deps(cli, datafiles, dep_kind, expected_deps): project = str(datafiles) - target = "checkout-deps.bst" + target = "format-deps.bst" result = cli.run( project=project, silent=True, args=["show", "--deps", "none", "--format", "%{name}: " + dep_kind, target] ) |