Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl GlobalFileTable {
for file in all_files {
raw_file_table.entry(file.stable_id).or_insert_with(|| {
file.name
.for_scope(tcx.sess, RemapPathScopeComponents::MACRO)
.for_scope(tcx.sess, RemapPathScopeComponents::COVERAGE)
.to_string_lossy()
.into_owned()
});
Expand All @@ -147,7 +147,7 @@ impl GlobalFileTable {
.sess
.opts
.working_dir
.for_scope(tcx.sess, RemapPathScopeComponents::MACRO)
.for_scope(tcx.sess, RemapPathScopeComponents::COVERAGE)
.to_string_lossy();
table.push(base_dir.as_ref());

Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1377,10 +1377,12 @@ bitflags::bitflags! {
const DIAGNOSTICS = 1 << 1;
/// Apply remappings to debug information
const DEBUGINFO = 1 << 3;
/// Apply remappings to coverage information
const COVERAGE = 1 << 4;

/// An alias for `macro` and `debuginfo`. This ensures all paths in compiled
/// executables or libraries are remapped but not elsewhere.
const OBJECT = Self::MACRO.bits() | Self::DEBUGINFO.bits();
/// An alias for `macro`, `debuginfo` and `coverage`. This ensures all paths in compiled
/// executables, libraries and objects are remapped but not elsewhere.
const OBJECT = Self::MACRO.bits() | Self::DEBUGINFO.bits() | Self::COVERAGE.bits();
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,7 @@ mod desc {
pub(crate) const parse_branch_protection: &str = "a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set)";
pub(crate) const parse_proc_macro_execution_strategy: &str =
"one of supported execution strategies (`same-thread`, or `cross-thread`)";
pub(crate) const parse_remap_path_scope: &str =
"comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `object`, `all`";
pub(crate) const parse_remap_path_scope: &str = "comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `coverage`, `object`, `all`";
pub(crate) const parse_inlining_threshold: &str =
"either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number";
pub(crate) const parse_llvm_module_flag: &str = "<key>:<type>:<value>:<behavior>. Type must currently be `u32`. Behavior should be one of (`error`, `warning`, `require`, `override`, `append`, `appendunique`, `max`, `min`)";
Expand Down Expand Up @@ -1705,6 +1704,7 @@ pub mod parse {
"macro" => RemapPathScopeComponents::MACRO,
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
"debuginfo" => RemapPathScopeComponents::DEBUGINFO,
"coverage" => RemapPathScopeComponents::COVERAGE,
"object" => RemapPathScopeComponents::OBJECT,
"all" => RemapPathScopeComponents::all(),
_ => return false,
Expand Down
3 changes: 2 additions & 1 deletion src/doc/unstable-book/src/compiler-flags/remap-path-scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ This flag accepts a comma-separated list of values and may be specified multiple

- `macro` - apply remappings to the expansion of `std::file!()` macro. This is where paths in embedded panic messages come from
- `diagnostics` - apply remappings to printed compiler diagnostics
- `debuginfo` - apply remappings to debug informations
- `debuginfo` - apply remappings to debug information
- `coverage` - apply remappings to coverage information
- `object` - apply remappings to all paths in compiled executables or libraries, but not elsewhere. Currently an alias for `macro,debuginfo`.
- `all` - an alias for all of the above, also equivalent to supplying only `--remap-path-prefix` without `--remap-path-scope`.

Expand Down
17 changes: 17 additions & 0 deletions tests/coverage/remap-path-prefix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This test makes sure that the files used in the coverage are remapped by
// `--remap-path-prefix` and the `coverage` <- `object` scopes.
//
// We also test the `macro` scope to make sure it does not affect coverage.

// When coverage paths are remapped, the coverage-run mode can't find source files (because
// it doesn't know about the remapping), so it produces an empty coverage report. The empty
// report (i.e. no `.coverage` files) helps to demonstrate that remapping was indeed performed.

//@ revisions: with_remap with_coverage_scope with_object_scope with_macro_scope
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
//
//@[with_coverage_scope] compile-flags: -Zremap-path-scope=coverage
//@[with_object_scope] compile-flags: -Zremap-path-scope=object
//@[with_macro_scope] compile-flags: -Zremap-path-scope=macro

fn main() {}
10 changes: 10 additions & 0 deletions tests/coverage/remap-path-prefix.with_coverage_scope.cov-map
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Function name: remap_path_prefix::main
Raw bytes (14): 0x[01, 01, 00, 02, 01, 11, 01, 00, 0a, 01, 00, 0c, 00, 0d]
Number of files: 1
- file 0 => remapped/remap-path-prefix.rs
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Counter(0)) at (prev + 17, 1) to (start + 0, 10)
- Code(Counter(0)) at (prev + 0, 12) to (start + 0, 13)
Highest counter ID seen: c0

10 changes: 10 additions & 0 deletions tests/coverage/remap-path-prefix.with_macro_scope.cov-map
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Function name: remap_path_prefix::main
Raw bytes (14): 0x[01, 01, 00, 02, 01, 11, 01, 00, 0a, 01, 00, 0c, 00, 0d]
Number of files: 1
- file 0 => $DIR/remap-path-prefix.rs
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Counter(0)) at (prev + 17, 1) to (start + 0, 10)
- Code(Counter(0)) at (prev + 0, 12) to (start + 0, 13)
Highest counter ID seen: c0

18 changes: 18 additions & 0 deletions tests/coverage/remap-path-prefix.with_macro_scope.coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
LL| |// This test makes sure that the files used in the coverage are remapped by
LL| |// `--remap-path-prefix` and the `coverage` <- `object` scopes.
LL| |//
LL| |// We also test the `macro` scope to make sure it does not affect coverage.
LL| |
LL| |// When coverage paths are remapped, the coverage-run mode can't find source files (because
LL| |// it doesn't know about the remapping), so it produces an empty coverage report. The empty
LL| |// report (i.e. no `.coverage` files) helps to demonstrate that remapping was indeed performed.
LL| |
LL| |//@ revisions: with_remap with_coverage_scope with_object_scope with_macro_scope
LL| |//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
LL| |//
LL| |//@[with_coverage_scope] compile-flags: -Zremap-path-scope=coverage
LL| |//@[with_object_scope] compile-flags: -Zremap-path-scope=object
LL| |//@[with_macro_scope] compile-flags: -Zremap-path-scope=macro
LL| |
LL| 1|fn main() {}

10 changes: 10 additions & 0 deletions tests/coverage/remap-path-prefix.with_object_scope.cov-map
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Function name: remap_path_prefix::main
Raw bytes (14): 0x[01, 01, 00, 02, 01, 11, 01, 00, 0a, 01, 00, 0c, 00, 0d]
Number of files: 1
- file 0 => remapped/remap-path-prefix.rs
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Counter(0)) at (prev + 17, 1) to (start + 0, 10)
- Code(Counter(0)) at (prev + 0, 12) to (start + 0, 13)
Highest counter ID seen: c0

10 changes: 10 additions & 0 deletions tests/coverage/remap-path-prefix.with_remap.cov-map
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Function name: remap_path_prefix::main
Raw bytes (14): 0x[01, 01, 00, 02, 01, 11, 01, 00, 0a, 01, 00, 0c, 00, 0d]
Number of files: 1
- file 0 => remapped/remap-path-prefix.rs
Number of expressions: 0
Number of file 0 mappings: 2
- Code(Counter(0)) at (prev + 17, 1) to (start + 0, 10)
- Code(Counter(0)) at (prev + 0, 12) to (start + 0, 13)
Highest counter ID seen: c0

Loading