Skip to content

Commit

Permalink
Merge #141
Browse files Browse the repository at this point in the history
141: Make --remap-path-prefix optional r=taiki-e a=taiki-e

Fixes #140 

cc #122

Co-authored-by: Taiki Endo <[email protected]>
  • Loading branch information
bors[bot] and taiki-e authored Apr 8, 2022
2 parents 4e3a119 + 9c2029b commit b4198cb
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ OPTIONS:
--ignore-filename-regex <PATTERN>
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

Expand Down Expand Up @@ -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>
Path to Cargo.toml

Expand Down
14 changes: 8 additions & 6 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Subcommand>,
Expand Down Expand Up @@ -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
///
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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<Coloring>,

/// 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 {
Expand Down
22 changes: 15 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -741,10 +742,17 @@ fn ignore_filename_regex(cx: &Context) -> Option<String> {
}
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);
Expand Down
1 change: 1 addition & 0 deletions tests/auxiliary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions tests/long-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ OPTIONS:
--ignore-filename-regex <PATTERN>
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

Expand Down Expand Up @@ -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>
Path to Cargo.toml

Expand Down
9 changes: 9 additions & 0 deletions tests/short-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ OPTIONS:
--ignore-filename-regex <PATTERN>
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

Expand Down Expand Up @@ -137,6 +143,9 @@ OPTIONS:
--color <WHEN>
Coloring [possible values: auto, always, never]

--remap-path-prefix
Use --remap-path-prefix for workspace root

--manifest-path <PATH>
Path to Cargo.toml

Expand Down
7 changes: 7 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit b4198cb

Please sign in to comment.