Skip to content

Commit

Permalink
Auto merge of #12638 - ehuss:clean-updates, r=epage
Browse files Browse the repository at this point in the history
Add some enhancements to `cargo clean`

### What does this PR try to resolve?

This adds some enhancements to `cargo clean` that fell out as a result of some refactorings in #12634 for supporting an interface for cleaning from other places in cargo, and these were relatively easy to add and assist with testing in #12634.

The changes are:
- Introduce some refactoring to offer a cleaning interface that can be used elsewhere in cargo.
- Adds a `--dry-run` CLI option which will print what `cargo clean` will delete without deleting it. **NOTE** This PR makes the flag insta-stable. I don't figure there is too much that can be learned about it keeping it unstable, though we could change that. #12634 has this flag gated with `-Zgc`.
- Adds a summary line at the end of the `cargo clean` operation that indicates how much was deleted.

### How should we test and review this PR?

Note that this PR also includes the changes from #12635 and #12637. Those commits can be dropped if those PRs are merged.

For the most part, this involves wrapping the cleaning operations in a `CleanContext` which provides an interface for performing cleaning operations. The dry run is just a flag that is checked at the deletion points. The summary data is also collected at those same points.
  • Loading branch information
bors committed Sep 20, 2023
2 parents f9335ba + 655f75d commit f57c80e
Show file tree
Hide file tree
Showing 11 changed files with 346 additions and 135 deletions.
1 change: 1 addition & 0 deletions crates/cargo-test-support/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ fn substitute_macros(input: &str) -> String {
("[UPDATING]", " Updating"),
("[ADDING]", " Adding"),
("[REMOVING]", " Removing"),
("[REMOVED]", " Removed"),
("[DOCTEST]", " Doc-tests"),
("[PACKAGING]", " Packaging"),
("[PACKAGED]", " Packaged"),
Expand Down
2 changes: 2 additions & 0 deletions src/bin/cargo/commands/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub fn cli() -> Command {
.arg_target_triple("Target triple to clean output for")
.arg_target_dir()
.arg_manifest_path()
.arg_dry_run("Display what would be deleted without deleting anything")
.after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help clean</>` for more detailed information.\n"
))
Expand All @@ -33,6 +34,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
requested_profile: args.get_profile_name(config, "dev", ProfileChecking::Custom)?,
profile_specified: args.contains_id("profile") || args.flag("release"),
doc: args.flag("doc"),
dry_run: args.dry_run(),
};
ops::clean(&ws, &opts)?;
Ok(())
Expand Down
Loading

0 comments on commit f57c80e

Please sign in to comment.