From bcd2536c2405ffa5dcd52ed9823a7c437cc1b2de Mon Sep 17 00:00:00 2001 From: Chandan Singh Date: Thu, 14 May 2020 18:45:53 +0000 Subject: Ensure there are no duplicates in Elements.dependencies() 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. --- src/buildstream/element.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src') 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): -- cgit v1.2.1