Skip to content

Commit

Permalink
Tweaks based on windows feedback
Browse files Browse the repository at this point in the history
* -C codegen-units=1 rust-lang/rust#85461
* Look for profraws in workspace folders
* Upgrade llvm-profparser to one that handles merging no files
  • Loading branch information
xd009642 committed Apr 9, 2022
1 parent 3fbd4e6 commit ba91bb7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ git2 = "0.14"
humantime-serde = "1"
indexmap = { version = "1.8.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"
num_cpus = "1.13.1"
object = "0.28"
Expand Down
17 changes: 17 additions & 0 deletions src/path_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -76,6 +82,17 @@ pub fn get_source_walker(config: &Config) -> impl Iterator<Item = DirEntry> + '_
.filter(is_source_file)
}

pub fn get_profile_walker(config: &Config) -> impl Iterator<Item = DirEntry> {
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::*;
Expand Down
9 changes: 4 additions & 5 deletions src/process_handling/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -30,11 +31,8 @@ pub struct RunningProcessHandle {
impl RunningProcessHandle {
pub fn new(path: PathBuf, cmd: &mut Command, config: &Config) -> Result<Self, RunError> {
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 {
Expand Down Expand Up @@ -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((
Expand Down
12 changes: 3 additions & 9 deletions src/statemachine/instrumented.rs
Original file line number Diff line number Diff line change
@@ -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::*;
Expand Down Expand Up @@ -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::<Vec<_>>();

info!(
Expand Down

0 comments on commit ba91bb7

Please sign in to comment.