Skip to content

Commit 2d91dbe

Browse files
committed
Add coverage scope for paths code coverage
1 parent fb09b4a commit 2d91dbe

File tree

9 files changed

+72
-5
lines changed

9 files changed

+72
-5
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,10 +1377,12 @@ bitflags::bitflags! {
13771377
const DIAGNOSTICS = 1 << 1;
13781378
/// Apply remappings to debug information
13791379
const DEBUGINFO = 1 << 3;
1380+
/// Apply remappings to coverage information
1381+
const COVERAGE = 1 << 4;
13801382

13811383
/// An alias for `macro` and `debuginfo`. This ensures all paths in compiled
13821384
/// executables or libraries are remapped but not elsewhere.
1383-
const OBJECT = Self::MACRO.bits() | Self::DEBUGINFO.bits();
1385+
const OBJECT = Self::MACRO.bits() | Self::DEBUGINFO.bits() | Self::COVERAGE.bits();
13841386
}
13851387
}
13861388

@@ -1395,9 +1397,10 @@ pub(crate) fn parse_remap_path_scope(
13951397
"macro" => RemapPathScopeComponents::MACRO,
13961398
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
13971399
"debuginfo" => RemapPathScopeComponents::DEBUGINFO,
1400+
"coverage" => RemapPathScopeComponents::COVERAGE,
13981401
"object" => RemapPathScopeComponents::OBJECT,
13991402
"all" => RemapPathScopeComponents::all(),
1400-
_ => early_dcx.early_fatal("argument for `--remap-path-scope` must be a comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `object`, `all`"),
1403+
_ => early_dcx.early_fatal("argument for `--remap-path-scope` must be a comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `coverage`, `object`, `all`"),
14011404
}
14021405
}
14031406
slot

src/doc/rustc/src/remap-source-paths.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ The valid scopes are:
3636
- `macro` - apply remappings to the expansion of `std::file!()` macro. This is where paths in embedded panic messages come from
3737
- `diagnostics` - apply remappings to printed compiler diagnostics
3838
- `debuginfo` - apply remappings to debug informations
39-
- `object` - apply remappings to all paths in compiled executables or libraries, but not elsewhere. Currently an alias for `macro,debuginfo`.
39+
- `coverage` - apply remappings to coverage informations
40+
- `object` - apply remappings to all paths in compiled executables or libraries, but not elsewhere. Currently an alias for `macro,coverage,debuginfo`.
4041
- `all` (default) - an alias for all of the above, also equivalent to supplying only `--remap-path-prefix` without `--remap-path-scope`.
4142

4243
The scopes accepted by `--remap-path-scope` are not exhaustive - new scopes may be added in future releases for eventual stabilisation.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This test makes sure that the files used in the coverage are remapped by `--remap-path-prefix`
2+
// and the `coverage` <- `object` scope.
3+
4+
//@ revisions: with_remap with_coverage_scope with_object_scope with_macro_scope
5+
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
6+
//
7+
//@[with_coverage_scope] compile-flags: --remap-path-scope=coverage
8+
//@[with_object_scope] compile-flags: --remap-path-scope=object
9+
//@[with_macro_scope] compile-flags: --remap-path-scope=macro
10+
11+
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, 0b, 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 + 11, 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, 0b, 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 + 11, 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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
LL| |// This test makes sure that the files used in the coverage are remapped by `--remap-path-prefix`
2+
LL| |// and the `coverage` <- `object` scope.
3+
LL| |
4+
LL| |//@ revisions: with_remap with_coverage_scope with_object_scope with_macro_scope
5+
LL| |//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
6+
LL| |//
7+
LL| |//@[with_coverage_scope] compile-flags: --remap-path-scope=coverage
8+
LL| |//@[with_object_scope] compile-flags: --remap-path-scope=object
9+
LL| |//@[with_macro_scope] compile-flags: --remap-path-scope=macro
10+
LL| |
11+
LL| 1|fn main() {}
12+
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, 0b, 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 + 11, 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, 0b, 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 + 11, 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)