From 1395f0f6f810a3a9cbc1d0671faf620f4bbd1c93 Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Sun, 18 Nov 2018 17:33:21 +0000 Subject: [PATCH] clean_rmeta() now removes all accompanying files --- src/common.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/common.rs b/src/common.rs index 7ab290a..a0f6461 100644 --- a/src/common.rs +++ b/src/common.rs @@ -255,23 +255,28 @@ impl Config { self.target_rustcflags = Some(flags); } - /// Remove rmeta files from target `deps` directory + /// Remove .rmeta files from target directories, along with matching artifacts. /// - /// These files are created by `cargo check`, and conflict with - /// `cargo build` rlib files, causing E0464 for tests which use - /// the parent crate. + /// These files are created by commands like `cargo check` and `cargo clippy`, and + /// conflict with `cargo build` rlib files, causing E0463 and E0464 errors for tests + /// which use the parent crate. pub fn clean_rmeta(&self) { if self.target_rustcflags.is_some() { - for directory in self.target_rustcflags - .as_ref() - .unwrap() - .split_whitespace() - .filter(|s| s.ends_with("/deps")) - { + for directory in self.target_rustcflags.as_ref().unwrap().split_whitespace() { if let Ok(mut entries) = read_dir(directory) { while let Some(Ok(entry)) = entries.next() { - if entry.file_name().to_string_lossy().ends_with(".rmeta") { + let f = entry.file_name().clone().into_string().unwrap(); + if f.ends_with(".rmeta") { + let prefix = &f[..f.len() - 5]; let _ = remove_file(entry.path()); + if let Ok(mut entries) = read_dir(directory) { + while let Some(Ok(entry)) = entries.next() { + let f = entry.file_name().clone().into_string().unwrap(); + if f.starts_with(prefix) && !f.ends_with(".rmeta") { + let _ = remove_file(entry.path()); + } + } + } } } }