diff --git a/Cargo.toml b/Cargo.toml index a54da54e4..28b9c6139 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ git2 = "0.15" humantime-serde = "1" indexmap = { version = "1.9.1", features = ["serde-1"] } lazy_static = "1.0" -llvm_profparser = { version = "0.1.0-alpha1", default-features = false } +llvm_profparser = { version = "0.1.0-alpha2", default-features = false } memmap = "0.7.0" object = "0.29" num_cpus = "1.13.1" diff --git a/src/path_utils.rs b/src/path_utils.rs index d2e58672b..8794e895a 100644 --- a/src/path_utils.rs +++ b/src/path_utils.rs @@ -4,6 +4,12 @@ use std::ffi::OsStr; use std::path::Path; use walkdir::{DirEntry, WalkDir}; +/// Returns true if the file is a rust source file +pub fn is_profraw_file(entry: &DirEntry) -> bool { + let p = entry.path(); + p.is_file() && p.extension() == Some(OsStr::new("profraw")) +} + /// Returns true if the file is a rust source file pub fn is_source_file(entry: &DirEntry) -> bool { let p = entry.path(); @@ -76,6 +82,17 @@ pub fn get_source_walker(config: &Config) -> impl Iterator + '_ .filter(is_source_file) } +pub fn get_profile_walker(config: &Config) -> impl Iterator { + let root = config.root(); + let target = config.target_dir(); + + let walker = WalkDir::new(&root).into_iter(); + walker + .filter_entry(move |e| is_coverable_file_path(e.path(), &root, &target)) + .filter_map(|e| e.ok()) + .filter(|e| is_profraw_file(e)) +} + #[cfg(test)] mod tests { use super::*; diff --git a/src/process_handling/mod.rs b/src/process_handling/mod.rs index 5648925ce..f73878e9f 100644 --- a/src/process_handling/mod.rs +++ b/src/process_handling/mod.rs @@ -1,5 +1,6 @@ use crate::config::Color; use crate::generate_tracemap; +use crate::path_utils::get_profile_walker; use crate::statemachine::{create_state_machine, TestState}; use crate::traces::*; use crate::{Config, EventLog, LineAnalysis, RunError, TestBinary, TraceEngine}; @@ -30,11 +31,8 @@ pub struct RunningProcessHandle { impl RunningProcessHandle { pub fn new(path: PathBuf, cmd: &mut Command, config: &Config) -> Result { let child = cmd.spawn()?; - let existing_profraws = fs::read_dir(config.root())? - .into_iter() - .filter_map(Result::ok) - .filter(|x| x.path().is_file() && x.path().extension() == Some(OsStr::new("profraw"))) - .map(|x| x.path()) + let existing_profraws = get_profile_walker(config) + .map(|x| x.path().to_path_buf()) .collect(); Ok(Self { @@ -240,6 +238,7 @@ fn execute_test( match config.engine() { TraceEngine::Llvm => { + info!("Setting LLVM_PROFILE_FILE"); // Used for llvm coverage to avoid report naming clashes TODO could have clashes // between runs envars.push(( diff --git a/src/statemachine/instrumented.rs b/src/statemachine/instrumented.rs index e8c0b49a2..b4b15f9be 100644 --- a/src/statemachine/instrumented.rs +++ b/src/statemachine/instrumented.rs @@ -1,6 +1,7 @@ #![allow(dead_code)] use crate::config::Config; use crate::errors::RunError; +use crate::path_utils::get_profile_walker; use crate::process_handling::RunningProcessHandle; use crate::source_analysis::LineAnalysis; use crate::statemachine::*; @@ -75,15 +76,8 @@ impl<'a> StateData for LlvmInstrumentedData<'a> { if let Some(parent) = self.process.as_mut() { match parent.child.wait() { Ok(exit) => { - let profraws = fs::read_dir(self.config.root())? - .into_iter() - .filter_map(Result::ok) - .filter(|x| { - x.path().is_file() - && x.path().extension() == Some(OsStr::new("profraw")) - && !parent.existing_profraws.contains(&x.path()) - }) - .map(|x| x.path()) + let profraws = get_profile_walker(self.config) + .map(|x| x.path().to_path_buf()) .collect::>(); info!(