From 4c078bd83b5ace58e193a32b796a681c82060feb Mon Sep 17 00:00:00 2001 From: Vitor Enes Date: Thu, 17 Dec 2020 21:22:36 +0100 Subject: [PATCH] Remove absolute path guessing. Absolute path guessing was introduced in https://github.com/mozilla/grcov/pull/197 but the discussion in https://github.com/mozilla/grcov/pull/546 suggests that it may not be needed. This commit removes such mechanism. --- src/path_rewriting.rs | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/src/path_rewriting.rs b/src/path_rewriting.rs index 15c551562..cad863367 100644 --- a/src/path_rewriting.rs +++ b/src/path_rewriting.rs @@ -91,22 +91,6 @@ fn apply_mapping(mapping: &Option, path: &str) -> PathBuf { PathBuf::from(path) } -// If the join of the source and the relative path is a file, return it. -// Otherwise, remove common part between the source's end and the relative -// path's start. -fn guess_abs_path(prefix_dir: &PathBuf, path: &PathBuf) -> PathBuf { - let full_path = prefix_dir.join(path); - if full_path.is_file() { - return full_path; - } - for ancestor in path.ancestors() { - if prefix_dir.ends_with(ancestor) && !ancestor.as_os_str().is_empty() { - return prefix_dir.join(path.strip_prefix(ancestor).unwrap().to_path_buf()); - } - } - full_path -} - // Remove prefix from the source file's path. fn remove_prefix(prefix_dir: &Option, path: PathBuf) -> PathBuf { if let Some(prefix_dir) = prefix_dir { @@ -136,12 +120,9 @@ fn get_abs_path(source_dir: &Option, rel_path: PathBuf) -> Option<(Path rel_path.clone() } else if let Some(ref source_dir) = source_dir { if !cfg!(windows) { - guess_abs_path(&source_dir, &rel_path) + source_dir.join(&rel_path) } else { - guess_abs_path( - &source_dir, - &PathBuf::from(&rel_path.to_str().unwrap().replace("/", "\\")), - ) + source_dir.join(&rel_path.to_str().unwrap().replace("/", "\\")) } } else { rel_path.clone()