diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 138f1ae03233..678fe268925f 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1174,20 +1174,23 @@ def get_all_link_deps(self) -> ImmutableListProtocol[BuildTargetTypes]: at link time, see get_dependencies() for that. """ result: OrderedSet[BuildTargetTypes] = OrderedSet() + nonresults: T.Set[BuildTargetTypes] = set() stack: T.Deque[BuildTargetTypes] = deque() stack.appendleft(self) while stack: t = stack.pop() - if t in result: + if t in result or t in nonresults: continue if isinstance(t, CustomTargetIndex): stack.appendleft(t.target) continue if isinstance(t, SharedLibrary): result.add(t) + else: + nonresults.add(t) if isinstance(t, BuildTarget): - stack.extendleft(t.link_targets) - stack.extendleft(t.link_whole_targets) + stack.extendleft((t2 for t2 in t.link_targets if t2 not in nonresults)) + stack.extendleft((t2 for t2 in t.link_whole_targets if t2 not in nonresults)) return list(result) @lru_cache(maxsize=None)