Delete rmeta files for rlibs during cargo clean

This commit is contained in:
Alex Crichton 2019-05-08 09:00:27 -07:00
parent 8f032b3bd4
commit c2152f0805
2 changed files with 27 additions and 1 deletions

View File

@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::fs; use std::fs;
use std::path::Path; 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::compiler::{BuildConfig, BuildContext, CompileMode, Context, Kind};
use crate::core::profiles::UnitFor; use crate::core::profiles::UnitFor;
use crate::core::Workspace; use crate::core::Workspace;
@ -119,6 +119,9 @@ pub fn clean(ws: &Workspace<'_>, opts: &CleanOptions<'_>) -> CargoResult<()> {
if let Some(ref dst) = output.hardlink { if let Some(ref dst) = output.hardlink {
rm_rf(dst, config)?; rm_rf(dst, config)?;
} }
if let FileFlavor::Linkable { rmeta } = &output.flavor {
rm_rf(rmeta, config)?;
}
} }
} }

View File

@ -294,3 +294,26 @@ fn clean_verbose() {
.run(); .run();
p.cargo("build").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());
}