Skip to content

Commit 6d57b59

Browse files
committed
Auto merge of #6349 - collin5:b6339, r=dwijnand
Clean only release artifacts if --release option is set Fixes #6339
2 parents de1d0de + f619664 commit 6d57b59

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/cargo/ops/cargo_clean.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ pub struct CleanOptions<'a> {
2424

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

3030
// If the doc option is set, we just want to delete the doc directory.
3131
if opts.doc {
32-
let target_dir = target_dir.join("doc");
33-
let target_dir = target_dir.into_path_unlocked();
34-
return rm_rf(&target_dir, config);
32+
target_dir = target_dir.join("doc");
33+
return rm_rf(&target_dir.into_path_unlocked(), config);
34+
}
35+
36+
// If the release option is set, we set target to release directory
37+
if opts.release {
38+
target_dir = target_dir.join("release");
3539
}
3640

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

4750
let (packages, resolve) = ops::resolve_ws(ws)?;

tests/testsuite/clean.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ fn clean_release() {
117117
[FINISHED] release [optimized] target(s) in [..]
118118
",
119119
).run();
120+
121+
p.cargo("build").run();
122+
123+
p.cargo("clean").arg("--release").run();
124+
assert!(p.build_dir().is_dir());
125+
assert!(p.build_dir().join("debug").is_dir());
126+
assert!(!p.build_dir().join("release").is_dir());
120127
}
121128

122129
#[test]

0 commit comments

Comments
 (0)