Skip to content

Commit 83afa6e

Browse files
committed
Auto merge of #5059 - tobywhughes:master, r=alexcrichton
Clean with --verbose now prints path of what is being removed. Added verbose output for the clean command. Simply takes whatever is passed into the rm_rf() function and outputs "Removing /whatever/the/path/to/remove/is" [Issue this is being used for](#5056)
2 parents 31847ee + 0661b3f commit 83afa6e

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

src/cargo/ops/cargo_clean.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct CleanOptions<'a> {
1717
/// Cleans the project from build artifacts.
1818
pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
1919
let target_dir = ws.target_dir();
20+
let config = ws.config();
2021

2122
// If we have a spec, then we need to delete some packages, otherwise, just
2223
// remove the whole target directory and be done with it!
@@ -25,7 +26,7 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
2526
// blow it all away anyway.
2627
if opts.spec.is_empty() {
2728
let target_dir = target_dir.into_path_unlocked();
28-
return rm_rf(&target_dir);
29+
return rm_rf(&target_dir, config);
2930
}
3031

3132
let (packages, resolve) = ops::resolve_ws(ws)?;
@@ -73,37 +74,39 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
7374
cx.probe_target_info(&units)?;
7475

7576
for unit in units.iter() {
76-
rm_rf(&cx.fingerprint_dir(unit))?;
77+
rm_rf(&cx.fingerprint_dir(unit), config)?;
7778
if unit.target.is_custom_build() {
7879
if unit.profile.run_custom_build {
79-
rm_rf(&cx.build_script_out_dir(unit))?;
80+
rm_rf(&cx.build_script_out_dir(unit), config)?;
8081
} else {
81-
rm_rf(&cx.build_script_dir(unit))?;
82+
rm_rf(&cx.build_script_dir(unit), config)?;
8283
}
8384
continue
8485
}
8586

8687
for &(ref src, ref link_dst, _) in cx.target_filenames(unit)?.iter() {
87-
rm_rf(src)?;
88+
rm_rf(src, config)?;
8889
if let Some(ref dst) = *link_dst {
89-
rm_rf(dst)?;
90+
rm_rf(dst, config)?;
9091
}
9192
}
9293
}
9394

9495
Ok(())
9596
}
9697

97-
fn rm_rf(path: &Path) -> CargoResult<()> {
98+
fn rm_rf(path: &Path, config: &Config) -> CargoResult<()> {
9899
let m = fs::metadata(path);
99100
if m.as_ref().map(|s| s.is_dir()).unwrap_or(false) {
101+
config.shell().verbose(|shell| {shell.status("Removing", path.display())})?;
100102
fs::remove_dir_all(path).chain_err(|| {
101103
format_err!("could not remove build directory")
102104
})?;
103105
} else if m.is_ok() {
106+
config.shell().verbose(|shell| {shell.status("Removing", path.display())})?;
104107
fs::remove_file(path).chain_err(|| {
105108
format_err!("failed to remove build artifact")
106109
})?;
107110
}
108111
Ok(())
109-
}
112+
}

tests/testsuite/clean.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,30 @@ fn registry() {
234234
assert_that(p.cargo("build"),
235235
execs().with_status(0));
236236
}
237+
238+
#[test]
239+
fn clean_verbose(){
240+
let p = project("foo")
241+
.file("Cargo.toml", r#"
242+
[package]
243+
name = "foo"
244+
version = "0.0.1"
245+
246+
[dependencies]
247+
bar = "0.1"
248+
"#)
249+
.file("src/main.rs", "fn main() {}")
250+
.build();
251+
252+
Package::new("bar", "0.1.0").publish();
253+
254+
assert_that(p.cargo("build"),
255+
execs().with_status(0));
256+
assert_that(p.cargo("clean").arg("-p").arg("bar").arg("--verbose"),
257+
execs().with_status(0).with_stderr("\
258+
[REMOVING] [..]
259+
[REMOVING] [..]
260+
"));
261+
assert_that(p.cargo("build"),
262+
execs().with_status(0));
263+
}

0 commit comments

Comments
 (0)