From 4ff66bea7eb5c7782d1b979b6ba16cba02964597 Mon Sep 17 00:00:00 2001 From: Andrew Halberstadt Date: Tue, 17 Feb 2026 16:05:48 -0500 Subject: [PATCH] WIP: apply if-dependencies at target phase --- src/taskgraph/generator.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/taskgraph/generator.py b/src/taskgraph/generator.py index a944a8b02..10cbd2ff8 100644 --- a/src/taskgraph/generator.py +++ b/src/taskgraph/generator.py @@ -513,6 +513,20 @@ def _run(self): f"Adding {len(always_target_tasks) - len(always_target_tasks & target_tasks)} tasks with `always_target` attribute" # type: ignore ) requested_tasks = target_tasks | always_target_tasks # type: ignore + + # Ensure if a task has any `if-dependencies`, it isn't responsible for + # pulling any of them into the target graph when computing the + # transitive closure. + for label in requested_tasks: + task = all_tasks[label] + if_dep_labels = {task.dependencies[e] for e in task.if_dependencies} + + # Find any if-dependencies that aren't in `requested_tasks` and + # delete them. + for missing in if_dep_labels - requested_tasks: + task.if_dependencies.remove(m) + del task.dependencies[m] + target_graph = full_task_graph.graph.transitive_closure(requested_tasks) target_task_graph = TaskGraph( {l: all_tasks[l] for l in target_graph.nodes},