Skip to content

Fix -t clean to remove all outputs of multi-output edges#2751

Open
philwo wants to merge 1 commit intoninja-build:masterfrom
philwo:clean-multi-outputs
Open

Fix -t clean to remove all outputs of multi-output edges#2751
philwo wants to merge 1 commit intoninja-build:masterfrom
philwo:clean-multi-outputs

Conversation

@philwo
Copy link
Copy Markdown

@philwo philwo commented Mar 24, 2026

When cleaning a specific target with ninja -t clean <target>, DoCleanTarget only removed the named target file. For multi-output edges (e.g. build a.txt | b.txt: gen in.txt), the other outputs were left behind even though they are produced by the same command and cannot be rebuilt independently. The docs say "additional arguments are targets, which removes the given targets and recursively all files built for them", so I think this is a bug.

Fix by iterating over all edge outputs in DoCleanTarget, consistent with how CleanAll already handles multi-output edges.

When cleaning a specific target with `ninja -t clean <target>`,
DoCleanTarget only removed the named target file. For multi-output
edges (e.g. `build a.txt | b.txt: gen in.txt`), the other outputs
were left behind even though they are produced by the same command
and cannot be rebuilt independently.

Fix by iterating over all edge outputs in DoCleanTarget, consistent
with how CleanAll already handles multi-output edges.
Copilot AI review requested due to automatic review settings March 24, 2026 00:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes ninja -t clean <target> so that cleaning a single target from a multi-output edge removes all outputs produced by that edge, aligning behavior with the documented “recursively all files built for them” semantics.

Changes:

  • Update Cleaner::DoCleanTarget to remove every output in the producing edge (not only the named target).
  • Add a unit test verifying multi-output edge cleanup behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/clean.cc Ensures CleanTarget removes all outputs of the target’s generating edge before recursing.
src/clean_test.cc Adds coverage for cleaning a target that is one of multiple outputs from the same edge.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jhasse jhasse added this to the 1.14.0 milestone Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants