Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/cargo/ops/cargo_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ pub struct CleanOptions<'a> {

/// Cleans the package's build artifacts.
pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
let target_dir = ws.target_dir();
let mut target_dir = ws.target_dir();
let config = ws.config();

// If the doc option is set, we just want to delete the doc directory.
if opts.doc {
let target_dir = target_dir.join("doc");
let target_dir = target_dir.into_path_unlocked();
return rm_rf(&target_dir, config);
target_dir = target_dir.join("doc");
return rm_rf(&target_dir.into_path_unlocked(), config);
}

// If the release option is set, we set target to release directory
if opts.release {
target_dir = target_dir.join("release");
}

// If we have a spec, then we need to delete some packages, otherwise, just
Expand All @@ -40,8 +44,7 @@ pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> {
// Note that we don't bother grabbing a lock here as we're just going to
// blow it all away anyway.
if opts.spec.is_empty() {
let target_dir = target_dir.into_path_unlocked();
return rm_rf(&target_dir, config);
return rm_rf(&target_dir.into_path_unlocked(), config);
}

let (packages, resolve) = ops::resolve_ws(ws)?;
Expand Down
7 changes: 7 additions & 0 deletions tests/testsuite/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ fn clean_release() {
[FINISHED] release [optimized] target(s) in [..]
",
).run();

p.cargo("build").run();

p.cargo("clean").arg("--release").run();
assert!(p.build_dir().is_dir());
assert!(p.build_dir().join("debug").is_dir());
assert!(!p.build_dir().join("release").is_dir());
}

#[test]
Expand Down