Skip to content

Commit c616e13

Browse files
Urgaudavidtwco
andcommitted
Stabilize -Zremap-path-scope as --remap-path-scope
In the process also document that new `--remap-path-scope` scopes may be added in the future, and that the `all` always represent all the scopes. Co-authored-by: David Wood <[email protected]>
1 parent bc1d727 commit c616e13

File tree

22 files changed

+122
-97
lines changed

22 files changed

+122
-97
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,29 @@ bitflags::bitflags! {
13951395
}
13961396
}
13971397

1398+
pub(crate) fn parse_remap_path_scope(
1399+
early_dcx: &EarlyDiagCtxt,
1400+
matches: &getopts::Matches,
1401+
) -> RemapPathScopeComponents {
1402+
if let Some(v) = matches.opt_str("remap-path-scope") {
1403+
let mut slot = RemapPathScopeComponents::empty();
1404+
for s in v.split(',') {
1405+
slot |= match s {
1406+
"macro" => RemapPathScopeComponents::MACRO,
1407+
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
1408+
"debuginfo" => RemapPathScopeComponents::DEBUGINFO,
1409+
"coverage" => RemapPathScopeComponents::COVERAGE,
1410+
"object" => RemapPathScopeComponents::OBJECT,
1411+
"all" => RemapPathScopeComponents::all(),
1412+
_ => early_dcx.early_fatal("argument for `--remap-path-scope` must be a comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `coverage`, `object`, `all`"),
1413+
}
1414+
}
1415+
slot
1416+
} else {
1417+
RemapPathScopeComponents::all()
1418+
}
1419+
}
1420+
13981421
#[derive(Clone, Debug)]
13991422
pub struct Sysroot {
14001423
pub explicit: Option<PathBuf>,
@@ -1431,18 +1454,18 @@ pub fn host_tuple() -> &'static str {
14311454

14321455
fn file_path_mapping(
14331456
remap_path_prefix: Vec<(PathBuf, PathBuf)>,
1434-
unstable_opts: &UnstableOptions,
1457+
remap_path_scope: &RemapPathScopeComponents,
14351458
) -> FilePathMapping {
14361459
FilePathMapping::new(
14371460
remap_path_prefix.clone(),
1438-
if unstable_opts.remap_path_scope.contains(RemapPathScopeComponents::DIAGNOSTICS)
1461+
if remap_path_scope.contains(RemapPathScopeComponents::DIAGNOSTICS)
14391462
&& !remap_path_prefix.is_empty()
14401463
{
14411464
FileNameDisplayPreference::Remapped
14421465
} else {
14431466
FileNameDisplayPreference::Local
14441467
},
1445-
if unstable_opts.remap_path_scope.is_all() {
1468+
if remap_path_scope.is_all() {
14461469
FileNameEmbeddablePreference::RemappedOnly
14471470
} else {
14481471
FileNameEmbeddablePreference::LocalAndRemapped
@@ -1484,6 +1507,7 @@ impl Default for Options {
14841507
cli_forced_codegen_units: None,
14851508
cli_forced_local_thinlto_off: false,
14861509
remap_path_prefix: Vec::new(),
1510+
remap_path_scope: RemapPathScopeComponents::all(),
14871511
real_rust_source_base_dir: None,
14881512
real_rustc_dev_source_base_dir: None,
14891513
edition: DEFAULT_EDITION,
@@ -1510,7 +1534,7 @@ impl Options {
15101534
}
15111535

15121536
pub fn file_path_mapping(&self) -> FilePathMapping {
1513-
file_path_mapping(self.remap_path_prefix.clone(), &self.unstable_opts)
1537+
file_path_mapping(self.remap_path_prefix.clone(), &self.remap_path_scope)
15141538
}
15151539

15161540
/// Returns `true` if there will be an output file generated.
@@ -1951,6 +1975,14 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
19511975
"Remap source names in all output (compiler messages and output files)",
19521976
"<FROM>=<TO>",
19531977
),
1978+
opt(
1979+
Stable,
1980+
Opt,
1981+
"",
1982+
"remap-path-scope",
1983+
"Defines which scopes of paths should be remapped by `--remap-path-prefix`",
1984+
"<macro,diagnostics,debuginfo,coverage,object,all>",
1985+
),
19541986
opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "<VAR>=<VALUE>"),
19551987
];
19561988
options.extend(verbose_only.into_iter().map(|mut opt| {
@@ -2849,6 +2881,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
28492881
let externs = parse_externs(early_dcx, matches, &unstable_opts);
28502882

28512883
let remap_path_prefix = parse_remap_path_prefix(early_dcx, matches, &unstable_opts);
2884+
let remap_path_scope = parse_remap_path_scope(early_dcx, matches);
28522885

28532886
let pretty = parse_pretty(early_dcx, &unstable_opts);
28542887

@@ -2912,7 +2945,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
29122945
early_dcx.early_fatal(format!("Current directory is invalid: {e}"));
29132946
});
29142947

2915-
let file_mapping = file_path_mapping(remap_path_prefix.clone(), &unstable_opts);
2948+
let file_mapping = file_path_mapping(remap_path_prefix.clone(), &remap_path_scope);
29162949
let working_dir = file_mapping.to_real_filename(&working_dir);
29172950

29182951
let verbose = matches.opt_present("verbose") || unstable_opts.verbose_internals;
@@ -2949,6 +2982,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
29492982
cli_forced_codegen_units: codegen_units,
29502983
cli_forced_local_thinlto_off: disable_local_thinlto,
29512984
remap_path_prefix,
2985+
remap_path_scope,
29522986
real_rust_source_base_dir,
29532987
real_rustc_dev_source_base_dir,
29542988
edition,

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ top_level_options!(
454454

455455
/// Remap source path prefixes in all output (messages, object files, debug, etc.).
456456
remap_path_prefix: Vec<(PathBuf, PathBuf)> [TRACKED_NO_CRATE_HASH],
457+
/// Defines which scopes of paths should be remapped by `--remap-path-prefix`.
458+
remap_path_scope: RemapPathScopeComponents [TRACKED_NO_CRATE_HASH],
457459

458460
/// Base directory containing the `library/` directory for the Rust standard library.
459461
/// Right now it's always `$sysroot/lib/rustlib/src/rust`
@@ -869,7 +871,6 @@ mod desc {
869871
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)";
870872
pub(crate) const parse_proc_macro_execution_strategy: &str =
871873
"one of supported execution strategies (`same-thread`, or `cross-thread`)";
872-
pub(crate) const parse_remap_path_scope: &str = "comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `coverage`, `object`, `all`";
873874
pub(crate) const parse_inlining_threshold: &str =
874875
"either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number";
875876
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`)";
@@ -1693,29 +1694,6 @@ pub mod parse {
16931694
true
16941695
}
16951696

1696-
pub(crate) fn parse_remap_path_scope(
1697-
slot: &mut RemapPathScopeComponents,
1698-
v: Option<&str>,
1699-
) -> bool {
1700-
if let Some(v) = v {
1701-
*slot = RemapPathScopeComponents::empty();
1702-
for s in v.split(',') {
1703-
*slot |= match s {
1704-
"macro" => RemapPathScopeComponents::MACRO,
1705-
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
1706-
"debuginfo" => RemapPathScopeComponents::DEBUGINFO,
1707-
"coverage" => RemapPathScopeComponents::COVERAGE,
1708-
"object" => RemapPathScopeComponents::OBJECT,
1709-
"all" => RemapPathScopeComponents::all(),
1710-
_ => return false,
1711-
}
1712-
}
1713-
true
1714-
} else {
1715-
false
1716-
}
1717-
}
1718-
17191697
pub(crate) fn parse_relocation_model(slot: &mut Option<RelocModel>, v: Option<&str>) -> bool {
17201698
match v.and_then(|s| RelocModel::from_str(s).ok()) {
17211699
Some(relocation_model) => *slot = Some(relocation_model),
@@ -2565,8 +2543,6 @@ options! {
25652543
"whether ELF relocations can be relaxed"),
25662544
remap_cwd_prefix: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
25672545
"remap paths under the current working directory to this path prefix"),
2568-
remap_path_scope: RemapPathScopeComponents = (RemapPathScopeComponents::all(), parse_remap_path_scope, [TRACKED],
2569-
"remap path scope (default: all)"),
25702546
remark_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
25712547
"directory into which to write optimization remarks (if not specified, they will be \
25722548
written to standard error output)"),

compiler/rustc_session/src/session.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ impl Session {
877877
scope.bits().count_ones() == 1,
878878
"one and only one scope should be passed to `Session::filename_display_preference`"
879879
);
880-
if self.opts.unstable_opts.remap_path_scope.contains(scope) {
880+
if self.opts.remap_path_scope.contains(scope) {
881881
FileNameDisplayPreference::Remapped
882882
} else {
883883
FileNameDisplayPreference::Local
@@ -1544,7 +1544,7 @@ impl RemapFileNameExt for rustc_span::FileName {
15441544
scope.bits().count_ones() == 1,
15451545
"one and only one scope should be passed to for_scope"
15461546
);
1547-
if sess.opts.unstable_opts.remap_path_scope.contains(scope) {
1547+
if sess.opts.remap_path_scope.contains(scope) {
15481548
self.prefer_remapped_unconditionally()
15491549
} else {
15501550
self.prefer_local()
@@ -1560,7 +1560,7 @@ impl RemapFileNameExt for rustc_span::RealFileName {
15601560
scope.bits().count_ones() == 1,
15611561
"one and only one scope should be passed to for_scope"
15621562
);
1563-
if sess.opts.unstable_opts.remap_path_scope.contains(scope) {
1563+
if sess.opts.remap_path_scope.contains(scope) {
15641564
self.remapped_path_if_available()
15651565
} else {
15661566
self.local_path_if_available()

src/doc/rustc/src/command-line-arguments.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,14 @@ specified multiple times.
428428
Refer to the [Remap source paths](remap-source-paths.md) section of this book for
429429
further details and explanation.
430430

431+
<a id="option-remap-path-scope"></a>
432+
## `--remap-path-scope`: remap source paths in output
433+
434+
Defines which scopes of paths should be remapped by `--remap-path-prefix`.
435+
436+
Refer to the [Remap source paths](remap-source-paths.md) section of this book for
437+
further details and explanation.
438+
431439
<a id="option-json"></a>
432440
## `--json`: configure json messages printed by the compiler
433441

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ output, including compiler diagnostics, debugging information, macro expansions,
66
This is useful for normalizing build products, for example by removing the current directory
77
out of the paths emitted into object files.
88

9-
The remapping is done via the `--remap-path-prefix` option.
9+
The remapping is done via the `--remap-path-prefix` flag and can be customized via the `--remap-path-scope` flag.
1010

1111
## `--remap-path-prefix`
1212

@@ -25,6 +25,31 @@ rustc --remap-path-prefix "/home/user/project=/redacted"
2525

2626
This example replaces all occurrences of `/home/user/project` in emitted paths with `/redacted`.
2727

28+
## `--remap-path-scope`
29+
30+
Defines which scopes of paths should be remapped by `--remap-path-prefix`.
31+
32+
This flag accepts a comma-separated list of values and may be specified multiple times, in which case the scopes are aggregated together.
33+
34+
The valid scopes are:
35+
36+
- `macro` - apply remappings to the expansion of `std::file!()` macro. This is where paths in embedded panic messages come from
37+
- `diagnostics` - apply remappings to printed compiler diagnostics
38+
- `debuginfo` - apply remappings to debug information
39+
- `coverage` - apply remappings to coverage information
40+
- `object` - apply remappings to all paths in compiled executables or libraries, but not elsewhere. Currently an alias for `macro,coverage,debuginfo`.
41+
- `all` (default) - an alias for all of the above, also equivalent to supplying only `--remap-path-prefix` without `--remap-path-scope`.
42+
43+
The scopes accepted by `--remap-path-scope` are not exhaustive - new scopes may be added in future releases for eventual stabilisation.
44+
This implies that the `all` scope can correspond to different scopes between releases.
45+
46+
### Example
47+
48+
```sh
49+
# With `object` scope only the build outputs will be remapped, the diagnostics won't be remapped.
50+
rustc --remap-path-prefix=$(PWD)=/remapped --remap-path-scope=object main.rs
51+
```
52+
2853
## Caveats and Limitations
2954

3055
### Linkers generated paths

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

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/coverage/remap-path-prefix.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
//@ revisions: with_remap with_coverage_scope with_object_scope with_macro_scope
1111
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
1212
//
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
13+
//@[with_coverage_scope] compile-flags: --remap-path-scope=coverage
14+
//@[with_object_scope] compile-flags: --remap-path-scope=object
15+
//@[with_macro_scope] compile-flags: --remap-path-scope=macro
1616

1717
fn main() {}

tests/coverage/remap-path-prefix.with_macro_scope.coverage

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
LL| |//@ revisions: with_remap with_coverage_scope with_object_scope with_macro_scope
1111
LL| |//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
1212
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
13+
LL| |//@[with_coverage_scope] compile-flags: --remap-path-scope=coverage
14+
LL| |//@[with_object_scope] compile-flags: --remap-path-scope=object
15+
LL| |//@[with_macro_scope] compile-flags: --remap-path-scope=macro
1616
LL| |
1717
LL| 1|fn main() {}
1818

tests/run-make/remap-path-prefix-dwarf/rmake.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn check_dwarf_deps(scope: &str, dwarf_test: DwarfDump) {
105105
let mut rustc_sm = rustc();
106106
rustc_sm.input(cwd().join("src/some_value.rs"));
107107
rustc_sm.arg("-Cdebuginfo=2");
108-
rustc_sm.arg(format!("-Zremap-path-scope={}", scope));
108+
rustc_sm.arg(format!("--remap-path-scope={}", scope));
109109
rustc_sm.arg("--remap-path-prefix");
110110
rustc_sm.arg(format!("{}=/REMAPPED", cwd().display()));
111111
rustc_sm.arg("-Csplit-debuginfo=off");
@@ -117,7 +117,7 @@ fn check_dwarf_deps(scope: &str, dwarf_test: DwarfDump) {
117117
rustc_pv.input(cwd().join("src/print_value.rs"));
118118
rustc_pv.output(&print_value_rlib);
119119
rustc_pv.arg("-Cdebuginfo=2");
120-
rustc_pv.arg(format!("-Zremap-path-scope={}", scope));
120+
rustc_pv.arg(format!("--remap-path-scope={}", scope));
121121
rustc_pv.arg("--remap-path-prefix");
122122
rustc_pv.arg(format!("{}=/REMAPPED", cwd().display()));
123123
rustc_pv.arg("-Csplit-debuginfo=off");
@@ -158,8 +158,8 @@ fn check_dwarf(test: DwarfTest) {
158158
rustc.arg("-Cdebuginfo=2");
159159
if let Some(scope) = test.scope {
160160
match scope {
161-
ScopeType::Object => rustc.arg("-Zremap-path-scope=object"),
162-
ScopeType::Diagnostics => rustc.arg("-Zremap-path-scope=diagnostics"),
161+
ScopeType::Object => rustc.arg("--remap-path-scope=object"),
162+
ScopeType::Diagnostics => rustc.arg("--remap-path-scope=diagnostics"),
163163
};
164164
if is_darwin() {
165165
rustc.arg("-Csplit-debuginfo=off");

tests/run-make/remap-path-prefix/rmake.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ fn main() {
3838
rmeta_contains("/the/aux/lib.rs");
3939
rmeta_not_contains("auxiliary");
4040

41-
out_object.arg("-Zremap-path-scope=object");
42-
out_macro.arg("-Zremap-path-scope=macro");
43-
out_diagobj.arg("-Zremap-path-scope=diagnostics,object");
41+
out_object.arg("--remap-path-scope=object");
42+
out_macro.arg("--remap-path-scope=macro");
43+
out_diagobj.arg("--remap-path-scope=diagnostics,object");
4444
if is_darwin() {
4545
out_object.arg("-Csplit-debuginfo=off");
4646
out_macro.arg("-Csplit-debuginfo=off");

0 commit comments

Comments
 (0)