From 9c2029b3c4a664e3ccfa73ba42c48cf92e208167 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Fri, 8 Apr 2022 14:19:01 +0900 Subject: [PATCH] Make --remap-path-prefix optional --- CHANGELOG.md | 2 ++ README.md | 11 +++++++++++ src/cli.rs | 14 ++++++++------ src/main.rs | 22 +++++++++++++++------- tests/auxiliary/mod.rs | 1 + tests/long-help.txt | 11 +++++++++++ tests/short-help.txt | 9 +++++++++ tests/test.rs | 7 +++++++ 8 files changed, 64 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2e2c437..18b1b409 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com ## [Unreleased] +- Make `--remap-path-prefix` optional. ([#141](https://github.com/taiki-e/cargo-llvm-cov/pull/141)) + ## [0.2.4] - 2022-03-18 - Add support for `nextest`. ([#144](https://github.com/taiki-e/cargo-llvm-cov/pull/144), thanks @skyzh) diff --git a/README.md b/README.md index bfc79884..03341d51 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,12 @@ OPTIONS: --ignore-filename-regex Skip source code files with file paths that match the given regular expression + --hide-instantiations + Hide instantiations from report + + --no-cfg-coverage + Unset cfg(coverage) + --no-report Run tests, but don't generate coverage report @@ -219,6 +225,11 @@ OPTIONS: [possible values: auto, always, never] + --remap-path-prefix + Use --remap-path-prefix for workspace root + + Note that this does not fully compatible with doctest. + --manifest-path Path to Cargo.toml diff --git a/src/cli.rs b/src/cli.rs index 5dbf9e69..2a9a8c35 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -32,7 +32,6 @@ pub(crate) enum Opts { max_term_width(MAX_TERM_WIDTH), setting(AppSettings::DeriveDisplayOrder) )] -#[allow(clippy::struct_excessive_bools)] pub(crate) struct Args { #[clap(subcommand)] pub(crate) subcommand: Option, @@ -223,7 +222,6 @@ pub(crate) enum Subcommand { } #[derive(Debug, Default, Parser)] -#[allow(clippy::struct_excessive_bools)] pub(crate) struct LlvmCovOptions { /// Export coverage data in "json" format /// @@ -306,13 +304,11 @@ pub(crate) struct LlvmCovOptions { // For debugging (unstable) #[clap(long, hide = true)] pub(crate) disable_default_ignore_filename_regex: bool, - // For debugging (unstable) /// Hide instantiations from report - #[clap(long, hide = true)] + #[clap(long)] pub(crate) hide_instantiations: bool, - // For debugging (unstable) /// Unset cfg(coverage) - #[clap(long, hide = true)] + #[clap(long)] pub(crate) no_cfg_coverage: bool, /// Run tests, but don't generate coverage report #[clap(long)] @@ -376,6 +372,12 @@ pub(crate) struct BuildOptions { // This flag will be propagated to both cargo and llvm-cov. #[clap(long, arg_enum, value_name = "WHEN")] pub(crate) color: Option, + + /// Use --remap-path-prefix for workspace root + /// + /// Note that this does not fully compatible with doctest. + #[clap(long)] + pub(crate) remap_path_prefix: bool, } impl BuildOptions { diff --git a/src/main.rs b/src/main.rs index a7f0d9d2..5cfbe759 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ #![forbid(unsafe_code)] #![warn(rust_2018_idioms, single_use_lifetimes, unreachable_pub)] #![warn(clippy::pedantic)] -#![allow(clippy::single_match_else)] +#![allow(clippy::single_match_else, clippy::struct_excessive_bools)] // Refs: // - https://doc.rust-lang.org/nightly/rustc/instrument-coverage.html @@ -241,8 +241,9 @@ fn set_env(cx: &Context, target: &mut impl EnvTarget) { rustflags.push_str(" -C codegen-units=1"); } } - // --remap-path-prefix is needed because sometimes macros are displayed with absolute path - rustflags.push_str(&format!(" --remap-path-prefix {}/=", cx.ws.metadata.workspace_root)); + if cx.build.remap_path_prefix { + rustflags.push_str(&format!(" --remap-path-prefix {}/=", cx.ws.metadata.workspace_root)); + } if !cx.cov.no_cfg_coverage { rustflags.push_str(" --cfg coverage"); } @@ -741,10 +742,17 @@ fn ignore_filename_regex(cx: &Context) -> Option { } if !cx.cov.disable_default_ignore_filename_regex { out.push(default_ignore_filename_regex()); - for path in - [home::home_dir(), home::cargo_home().ok(), home::rustup_home().ok()].iter().flatten() - { - out.push_abs_path(path); + if cx.build.remap_path_prefix { + for path in [home::home_dir(), home::cargo_home().ok(), home::rustup_home().ok()] + .iter() + .flatten() + { + out.push_abs_path(path); + } + } else { + for path in [home::cargo_home().ok(), home::rustup_home().ok()].iter().flatten() { + out.push_abs_path(path); + } } for path in resolve_excluded_paths(cx) { out.push_abs_path(path); diff --git a/tests/auxiliary/mod.rs b/tests/auxiliary/mod.rs index c4171057..f965ef71 100644 --- a/tests/auxiliary/mod.rs +++ b/tests/auxiliary/mod.rs @@ -55,6 +55,7 @@ pub fn test_report( } cmd.args(["--color", "never", "--output-path"]) .arg(output_path) + .arg("--remap-path-prefix") .args(args) .current_dir(workspace_root.path()); for (key, val) in envs { diff --git a/tests/long-help.txt b/tests/long-help.txt index f48a1f2f..7262d149 100644 --- a/tests/long-help.txt +++ b/tests/long-help.txt @@ -73,6 +73,12 @@ OPTIONS: --ignore-filename-regex Skip source code files with file paths that match the given regular expression + --hide-instantiations + Hide instantiations from report + + --no-cfg-coverage + Unset cfg(coverage) + --no-report Run tests, but don't generate coverage report @@ -184,6 +190,11 @@ OPTIONS: [possible values: auto, always, never] + --remap-path-prefix + Use --remap-path-prefix for workspace root + + Note that this does not fully compatible with doctest. + --manifest-path Path to Cargo.toml diff --git a/tests/short-help.txt b/tests/short-help.txt index 927c54b8..d3a3e80f 100644 --- a/tests/short-help.txt +++ b/tests/short-help.txt @@ -41,6 +41,12 @@ OPTIONS: --ignore-filename-regex Skip source code files with file paths that match the given regular expression + --hide-instantiations + Hide instantiations from report + + --no-cfg-coverage + Unset cfg(coverage) + --no-report Run tests, but don't generate coverage report @@ -137,6 +143,9 @@ OPTIONS: --color Coloring [possible values: auto, always, never] + --remap-path-prefix + Use --remap-path-prefix for workspace root + --manifest-path Path to Cargo.toml diff --git a/tests/test.rs b/tests/test.rs index 8273c492..699b8932 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -152,15 +152,18 @@ fn merge_with_failure_mode(output_dir: &Utf8Path, failure_mode_all: bool) { let expected = &fs::read_to_string(output_path).unwrap_or_default(); cargo_llvm_cov() .args(["--color", "never", "--no-report", "--features", "a"]) + .arg("--remap-path-prefix") .current_dir(workspace_root.path()) .assert_success(); cargo_llvm_cov() .args(["--color", "never", "--no-report", "--features", "b"]) + .arg("--remap-path-prefix") .current_dir(workspace_root.path()) .assert_success(); let mut cmd = cargo_llvm_cov(); cmd.args(["--color", "never", "--no-run", "--output-path"]) .arg(output_path) + .arg("--remap-path-prefix") .args(args) .current_dir(workspace_root.path()); cmd.assert_success(); @@ -190,11 +193,13 @@ fn clean_ws() { let expected = &fs::read_to_string(output_path).unwrap_or_default(); cargo_llvm_cov() .args(["--color", "never", "--no-report", "--features", "a"]) + .arg("--remap-path-prefix") .current_dir(workspace_root.path()) .assert_success(); cargo_llvm_cov() .args(["--color", "never", "--no-run", "--output-path"]) .arg(output_path) + .arg("--remap-path-prefix") .args(args) .current_dir(workspace_root.path()) .assert_success(); @@ -208,11 +213,13 @@ fn clean_ws() { .assert_success(); cargo_llvm_cov() .args(["--color", "never", "--no-report", "--features", "a"]) + .arg("--remap-path-prefix") .current_dir(workspace_root.path()) .assert_success(); cargo_llvm_cov() .args(["--color", "never", "--no-run", "--output-path"]) .arg(output_path) + .arg("--remap-path-prefix") .args(args) .current_dir(workspace_root.path()) .assert_success();