Auto merge of #6349 - collin5:b6339, r=dwijnand

Clean only release artifacts if --release option is set

Fixes #6339
This commit is contained in:
bors 2018-11-26 15:55:03 +00:00
commit 6d57b59ab5
2 changed files with 16 additions and 6 deletions

View File

@ -24,14 +24,18 @@ pub struct CleanOptions<'a> {
/// Cleans the package's build artifacts. /// Cleans the package's build artifacts.
pub fn clean(ws: &Workspace, opts: &CleanOptions) -> CargoResult<()> { 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(); let config = ws.config();
// If the doc option is set, we just want to delete the doc directory. // If the doc option is set, we just want to delete the doc directory.
if opts.doc { if opts.doc {
let target_dir = target_dir.join("doc"); target_dir = target_dir.join("doc");
let target_dir = target_dir.into_path_unlocked(); return rm_rf(&target_dir.into_path_unlocked(), config);
return rm_rf(&target_dir, 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 // 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 // Note that we don't bother grabbing a lock here as we're just going to
// blow it all away anyway. // blow it all away anyway.
if opts.spec.is_empty() { if opts.spec.is_empty() {
let target_dir = target_dir.into_path_unlocked(); return rm_rf(&target_dir.into_path_unlocked(), config);
return rm_rf(&target_dir, config);
} }
let (packages, resolve) = ops::resolve_ws(ws)?; let (packages, resolve) = ops::resolve_ws(ws)?;

View File

@ -117,6 +117,13 @@ fn clean_release() {
[FINISHED] release [optimized] target(s) in [..] [FINISHED] release [optimized] target(s) in [..]
", ",
).run(); ).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] #[test]