From c5d0c34bc719ef04e42bbef3c774423012fd4af3 Mon Sep 17 00:00:00 2001 From: Collins Abitekaniza Date: Mon, 26 Nov 2018 15:07:05 +0300 Subject: [PATCH 1/3] only clean release artifacts if --release option is set --- src/cargo/ops/cargo_clean.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index 10308cd8920..0f0f0adea6d 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -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 @@ -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)?; From 84be123f791a6392f5897723d8c943bf42613936 Mon Sep 17 00:00:00 2001 From: Collins Abitekaniza Date: Mon, 26 Nov 2018 17:40:50 +0300 Subject: [PATCH 2/3] test cargo clean with --release option --- tests/testsuite/clean.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/testsuite/clean.rs b/tests/testsuite/clean.rs index ea62d062b8a..9e03bd11655 100644 --- a/tests/testsuite/clean.rs +++ b/tests/testsuite/clean.rs @@ -117,6 +117,9 @@ fn clean_release() { [FINISHED] release [optimized] target(s) in [..] ", ).run(); + + p.cargo("clean").arg("--release").run(); + assert!(!p.build_dir().join("release").is_dir()); } #[test] From f61966403abdbbb142bcf9263a7a46ae196c5fef Mon Sep 17 00:00:00 2001 From: Collins Abitekaniza Date: Mon, 26 Nov 2018 18:12:11 +0300 Subject: [PATCH 3/3] assert for non-release artifacts --- tests/testsuite/clean.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/testsuite/clean.rs b/tests/testsuite/clean.rs index 9e03bd11655..dc2ac57c4df 100644 --- a/tests/testsuite/clean.rs +++ b/tests/testsuite/clean.rs @@ -118,7 +118,11 @@ fn clean_release() { ", ).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()); }