summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChandan Singh <chandan@chandansingh.net>2020-05-14 18:45:53 +0000
committerChandan Singh <chandan@chandansingh.net>2020-05-14 19:37:37 +0000
commitbcd2536c2405ffa5dcd52ed9823a7c437cc1b2de (patch)
tree7a63e9dd83f8e93689adee7c9846c7ad5e1cce51 /src
parentdd2eb18bfc60cef39c9aa478397a4ff9a6c87a1d (diff)
downloadbuildstream-chandan/duplicate-format-deps.tar.gz
Ensure there are no duplicates in Elements.dependencies()chandan/duplicate-format-deps
When we are not recursing, `Element.dependencies()` uses a much more light weight codepath since it just needs to print the direct dependencies. However, this simple codepath was not accounting for duplicates, in case something is both a build time and run time dependency. One way this manifested itself was in `bst show --format %{deps}`, but it would also affect anything that was using this method to iterate on the dependencies. Fixes #1308.
Diffstat (limited to 'src')
-rw-r--r--src/buildstream/element.py15
1 files changed, 11 insertions, 4 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):