From c2152f08058d35324e83126fd6d8e7e0c9850441 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 8 May 2019 09:00:27 -0700 Subject: [PATCH] Delete rmeta files for rlibs during `cargo clean` --- src/cargo/ops/cargo_clean.rs | 5 ++++- tests/testsuite/clean.rs | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index 1a8a15cf0..55f01a30b 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::fs; use std::path::Path; -use crate::core::compiler::UnitInterner; +use crate::core::compiler::{UnitInterner, FileFlavor}; use crate::core::compiler::{BuildConfig, BuildContext, CompileMode, Context, Kind}; use crate::core::profiles::UnitFor; use crate::core::Workspace; @@ -119,6 +119,9 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> { if let Some(ref dst) = output.hardlink { rm_rf(dst, config)?; } + if let FileFlavor::Linkable { rmeta } = &output.flavor { + rm_rf(rmeta, config)?; + } } } diff --git a/tests/testsuite/clean.rs b/tests/testsuite/clean.rs index a0ec3affc..8f746962a 100644 --- a/tests/testsuite/clean.rs +++ b/tests/testsuite/clean.rs @@ -294,3 +294,26 @@ fn clean_verbose() { .run(); p.cargo("build").run(); } + +#[test] +fn clean_remove_rlib_rmeta() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("build").run(); + assert!(p.target_debug_dir().join("libfoo.rlib").exists()); + let rmeta = p.glob("target/debug/deps/*.rmeta").next().unwrap().unwrap(); + assert!(rmeta.exists()); + p.cargo("clean -p foo").run(); + assert!(!p.target_debug_dir().join("libfoo.rlib").exists()); + assert!(!rmeta.exists()); +}