Skip to content

Commit f57c80e

Browse files
committed
Auto merge of #12638 - ehuss:clean-updates, r=epage
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.
2 parents f9335ba + 655f75d commit f57c80e

File tree

11 files changed

+346
-135
lines changed

11 files changed

+346
-135
lines changed

crates/cargo-test-support/src/compare.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ fn substitute_macros(input: &str) -> String {
206206
("[UPDATING]", " Updating"),
207207
("[ADDING]", " Adding"),
208208
("[REMOVING]", " Removing"),
209+
("[REMOVED]", " Removed"),
209210
("[DOCTEST]", " Doc-tests"),
210211
("[PACKAGING]", " Packaging"),
211212
("[PACKAGED]", " Packaged"),

src/bin/cargo/commands/clean.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub fn cli() -> Command {
1414
.arg_target_triple("Target triple to clean output for")
1515
.arg_target_dir()
1616
.arg_manifest_path()
17+
.arg_dry_run("Display what would be deleted without deleting anything")
1718
.after_help(color_print::cstr!(
1819
"Run `<cyan,bold>cargo help clean</>` for more detailed information.\n"
1920
))
@@ -33,6 +34,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
3334
requested_profile: args.get_profile_name(config, "dev", ProfileChecking::Custom)?,
3435
profile_specified: args.contains_id("profile") || args.flag("release"),
3536
doc: args.flag("doc"),
37+
dry_run: args.dry_run(),
3638
};
3739
ops::clean(&ws, &opts)?;
3840
Ok(())

0 commit comments

Comments
 (0)