Skip to content

Commit a383fe8

Browse files
authored
Rollup merge of rust-lang#148139 - Urgau:add-coverage-scope, r=Zalathar
Add `coverage` scope for controlling paths in code coverage This PR adds a `coverage` scope (for `-Zremap-path-scope`) for controlling if the paths that ends up in code coverage output should be remapped or not. Currently code coverage use the `macro` scope which is not a appropriate scope for them. Found during the stabilization of `-Zremap-path-scope` rust-lang#147611 (comment) and was asked to be in a separate PR in rust-lang#147611 (comment). r? compiler
2 parents 78526e4 + 94c893e commit a383fe8

File tree

10 files changed

+86
-8
lines changed

10 files changed

+86
-8
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl GlobalFileTable {
128128
for file in all_files {
129129
raw_file_table.entry(file.stable_id).or_insert_with(|| {
130130
file.name
131-
.for_scope(tcx.sess, RemapPathScopeComponents::MACRO)
131+
.for_scope(tcx.sess, RemapPathScopeComponents::COVERAGE)
132132
.to_string_lossy()
133133
.into_owned()
134134
});
@@ -147,7 +147,7 @@ impl GlobalFileTable {
147147
.sess
148148
.opts
149149
.working_dir
150-
.for_scope(tcx.sess, RemapPathScopeComponents::MACRO)
150+
.for_scope(tcx.sess, RemapPathScopeComponents::COVERAGE)
151151
.to_string_lossy();
152152
table.push(base_dir.as_ref());
153153

compiler/rustc_session/src/config.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,10 +1386,12 @@ bitflags::bitflags! {
13861386
const DIAGNOSTICS = 1 << 1;
13871387
/// Apply remappings to debug information
13881388
const DEBUGINFO = 1 << 3;
1389+
/// Apply remappings to coverage information
1390+
const COVERAGE = 1 << 4;
13891391

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

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,7 @@ mod desc {
869869
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)";
870870
pub(crate) const parse_proc_macro_execution_strategy: &str =
871871
"one of supported execution strategies (`same-thread`, or `cross-thread`)";
872-
pub(crate) const parse_remap_path_scope: &str =
873-
"comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `object`, `all`";
872+
pub(crate) const parse_remap_path_scope: &str = "comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `coverage`, `object`, `all`";
874873
pub(crate) const parse_inlining_threshold: &str =
875874
"either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number";
876875
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`)";
@@ -1705,6 +1704,7 @@ pub mod parse {
17051704
"macro" => RemapPathScopeComponents::MACRO,
17061705
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
17071706
"debuginfo" => RemapPathScopeComponents::DEBUGINFO,
1707+
"coverage" => RemapPathScopeComponents::COVERAGE,
17081708
"object" => RemapPathScopeComponents::OBJECT,
17091709
"all" => RemapPathScopeComponents::all(),
17101710
_ => return false,

src/doc/unstable-book/src/compiler-flags/remap-path-scope.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ This flag accepts a comma-separated list of values and may be specified multiple
1010

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This test makes sure that the files used in the coverage are remapped by
2+
// `--remap-path-prefix` and the `coverage` <- `object` scopes.
3+
//
4+
// We also test the `macro` scope to make sure it does not affect coverage.
5+
6+
// When coverage paths are remapped, the coverage-run mode can't find source files (because
7+
// it doesn't know about the remapping), so it produces an empty coverage report. The empty
8+
// report (i.e. no `.coverage` files) helps to demonstrate that remapping was indeed performed.
9+
10+
//@ revisions: with_remap with_coverage_scope with_object_scope with_macro_scope
11+
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
12+
//
13+
//@[with_coverage_scope] compile-flags: -Zremap-path-scope=coverage
14+
//@[with_object_scope] compile-flags: -Zremap-path-scope=object
15+
//@[with_macro_scope] compile-flags: -Zremap-path-scope=macro
16+
17+
fn main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Function name: remap_path_prefix::main
2+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 11, 01, 00, 0a, 01, 00, 0c, 00, 0d]
3+
Number of files: 1
4+
- file 0 => remapped/remap-path-prefix.rs
5+
Number of expressions: 0
6+
Number of file 0 mappings: 2
7+
- Code(Counter(0)) at (prev + 17, 1) to (start + 0, 10)
8+
- Code(Counter(0)) at (prev + 0, 12) to (start + 0, 13)
9+
Highest counter ID seen: c0
10+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Function name: remap_path_prefix::main
2+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 11, 01, 00, 0a, 01, 00, 0c, 00, 0d]
3+
Number of files: 1
4+
- file 0 => $DIR/remap-path-prefix.rs
5+
Number of expressions: 0
6+
Number of file 0 mappings: 2
7+
- Code(Counter(0)) at (prev + 17, 1) to (start + 0, 10)
8+
- Code(Counter(0)) at (prev + 0, 12) to (start + 0, 13)
9+
Highest counter ID seen: c0
10+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
LL| |// This test makes sure that the files used in the coverage are remapped by
2+
LL| |// `--remap-path-prefix` and the `coverage` <- `object` scopes.
3+
LL| |//
4+
LL| |// We also test the `macro` scope to make sure it does not affect coverage.
5+
LL| |
6+
LL| |// When coverage paths are remapped, the coverage-run mode can't find source files (because
7+
LL| |// it doesn't know about the remapping), so it produces an empty coverage report. The empty
8+
LL| |// report (i.e. no `.coverage` files) helps to demonstrate that remapping was indeed performed.
9+
LL| |
10+
LL| |//@ revisions: with_remap with_coverage_scope with_object_scope with_macro_scope
11+
LL| |//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
12+
LL| |//
13+
LL| |//@[with_coverage_scope] compile-flags: -Zremap-path-scope=coverage
14+
LL| |//@[with_object_scope] compile-flags: -Zremap-path-scope=object
15+
LL| |//@[with_macro_scope] compile-flags: -Zremap-path-scope=macro
16+
LL| |
17+
LL| 1|fn main() {}
18+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Function name: remap_path_prefix::main
2+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 11, 01, 00, 0a, 01, 00, 0c, 00, 0d]
3+
Number of files: 1
4+
- file 0 => remapped/remap-path-prefix.rs
5+
Number of expressions: 0
6+
Number of file 0 mappings: 2
7+
- Code(Counter(0)) at (prev + 17, 1) to (start + 0, 10)
8+
- Code(Counter(0)) at (prev + 0, 12) to (start + 0, 13)
9+
Highest counter ID seen: c0
10+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Function name: remap_path_prefix::main
2+
Raw bytes (14): 0x[01, 01, 00, 02, 01, 11, 01, 00, 0a, 01, 00, 0c, 00, 0d]
3+
Number of files: 1
4+
- file 0 => remapped/remap-path-prefix.rs
5+
Number of expressions: 0
6+
Number of file 0 mappings: 2
7+
- Code(Counter(0)) at (prev + 17, 1) to (start + 0, 10)
8+
- Code(Counter(0)) at (prev + 0, 12) to (start + 0, 13)
9+
Highest counter ID seen: c0
10+

0 commit comments

Comments
 (0)