Skip to content

Commit ac9448d

Browse files
committed
Stabilize -Zremap-path-scope
1 parent 8927649 commit ac9448d

File tree

18 files changed

+104
-89
lines changed

18 files changed

+104
-89
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,28 @@ bitflags::bitflags! {
13841384
}
13851385
}
13861386

1387+
pub(crate) fn parse_remap_path_scope(
1388+
early_dcx: &EarlyDiagCtxt,
1389+
matches: &getopts::Matches,
1390+
) -> RemapPathScopeComponents {
1391+
if let Some(v) = matches.opt_str("remap-path-scope") {
1392+
let mut slot = RemapPathScopeComponents::empty();
1393+
for s in v.split(',') {
1394+
slot |= match s {
1395+
"macro" => RemapPathScopeComponents::MACRO,
1396+
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
1397+
"debuginfo" => RemapPathScopeComponents::DEBUGINFO,
1398+
"object" => RemapPathScopeComponents::OBJECT,
1399+
"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`"),
1401+
}
1402+
}
1403+
slot
1404+
} else {
1405+
RemapPathScopeComponents::all()
1406+
}
1407+
}
1408+
13871409
#[derive(Clone, Debug)]
13881410
pub struct Sysroot {
13891411
pub explicit: Option<PathBuf>,
@@ -1420,18 +1442,18 @@ pub fn host_tuple() -> &'static str {
14201442

14211443
fn file_path_mapping(
14221444
remap_path_prefix: Vec<(PathBuf, PathBuf)>,
1423-
unstable_opts: &UnstableOptions,
1445+
remap_path_scope: &RemapPathScopeComponents,
14241446
) -> FilePathMapping {
14251447
FilePathMapping::new(
14261448
remap_path_prefix.clone(),
1427-
if unstable_opts.remap_path_scope.contains(RemapPathScopeComponents::DIAGNOSTICS)
1449+
if remap_path_scope.contains(RemapPathScopeComponents::DIAGNOSTICS)
14281450
&& !remap_path_prefix.is_empty()
14291451
{
14301452
FileNameDisplayPreference::Remapped
14311453
} else {
14321454
FileNameDisplayPreference::Local
14331455
},
1434-
if unstable_opts.remap_path_scope.is_all() {
1456+
if remap_path_scope.is_all() {
14351457
FileNameEmbeddablePreference::RemappedOnly
14361458
} else {
14371459
FileNameEmbeddablePreference::LocalAndRemapped
@@ -1473,6 +1495,7 @@ impl Default for Options {
14731495
cli_forced_codegen_units: None,
14741496
cli_forced_local_thinlto_off: false,
14751497
remap_path_prefix: Vec::new(),
1498+
remap_path_scope: RemapPathScopeComponents::all(),
14761499
real_rust_source_base_dir: None,
14771500
real_rustc_dev_source_base_dir: None,
14781501
edition: DEFAULT_EDITION,
@@ -1499,7 +1522,7 @@ impl Options {
14991522
}
15001523

15011524
pub fn file_path_mapping(&self) -> FilePathMapping {
1502-
file_path_mapping(self.remap_path_prefix.clone(), &self.unstable_opts)
1525+
file_path_mapping(self.remap_path_prefix.clone(), &self.remap_path_scope)
15031526
}
15041527

15051528
/// Returns `true` if there will be an output file generated.
@@ -1940,6 +1963,14 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
19401963
"Remap source names in all output (compiler messages and output files)",
19411964
"<FROM>=<TO>",
19421965
),
1966+
opt(
1967+
Stable,
1968+
Opt,
1969+
"",
1970+
"remap-path-scope",
1971+
"Defines which scopes of paths should be remapped by `--remap-path-prefix`",
1972+
"<macro,diagnostics,debuginfo,object,all>",
1973+
),
19431974
opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "<VAR>=<VALUE>"),
19441975
];
19451976
options.extend(verbose_only.into_iter().map(|mut opt| {
@@ -2838,6 +2869,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
28382869
let externs = parse_externs(early_dcx, matches, &unstable_opts);
28392870

28402871
let remap_path_prefix = parse_remap_path_prefix(early_dcx, matches, &unstable_opts);
2872+
let remap_path_scope = parse_remap_path_scope(early_dcx, matches);
28412873

28422874
let pretty = parse_pretty(early_dcx, &unstable_opts);
28432875

@@ -2901,7 +2933,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
29012933
early_dcx.early_fatal(format!("Current directory is invalid: {e}"));
29022934
});
29032935

2904-
let file_mapping = file_path_mapping(remap_path_prefix.clone(), &unstable_opts);
2936+
let file_mapping = file_path_mapping(remap_path_prefix.clone(), &remap_path_scope);
29052937
let working_dir = file_mapping.to_real_filename(&working_dir);
29062938

29072939
let verbose = matches.opt_present("verbose") || unstable_opts.verbose_internals;
@@ -2938,6 +2970,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
29382970
cli_forced_codegen_units: codegen_units,
29392971
cli_forced_local_thinlto_off: disable_local_thinlto,
29402972
remap_path_prefix,
2973+
remap_path_scope,
29412974
real_rust_source_base_dir,
29422975
real_rustc_dev_source_base_dir,
29432976
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,8 +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 =
873-
"comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `object`, `all`";
874874
pub(crate) const parse_inlining_threshold: &str =
875875
"either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number";
876876
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`)";
@@ -1694,28 +1694,6 @@ pub mod parse {
16941694
true
16951695
}
16961696

1697-
pub(crate) fn parse_remap_path_scope(
1698-
slot: &mut RemapPathScopeComponents,
1699-
v: Option<&str>,
1700-
) -> bool {
1701-
if let Some(v) = v {
1702-
*slot = RemapPathScopeComponents::empty();
1703-
for s in v.split(',') {
1704-
*slot |= match s {
1705-
"macro" => RemapPathScopeComponents::MACRO,
1706-
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
1707-
"debuginfo" => RemapPathScopeComponents::DEBUGINFO,
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
@@ -882,7 +882,7 @@ impl Session {
882882
scope.bits().count_ones() == 1,
883883
"one and only one scope should be passed to `Session::filename_display_preference`"
884884
);
885-
if self.opts.unstable_opts.remap_path_scope.contains(scope) {
885+
if self.opts.remap_path_scope.contains(scope) {
886886
FileNameDisplayPreference::Remapped
887887
} else {
888888
FileNameDisplayPreference::Local
@@ -1534,7 +1534,7 @@ impl RemapFileNameExt for rustc_span::FileName {
15341534
scope.bits().count_ones() == 1,
15351535
"one and only one scope should be passed to for_scope"
15361536
);
1537-
if sess.opts.unstable_opts.remap_path_scope.contains(scope) {
1537+
if sess.opts.remap_path_scope.contains(scope) {
15381538
self.prefer_remapped_unconditionally()
15391539
} else {
15401540
self.prefer_local()
@@ -1550,7 +1550,7 @@ impl RemapFileNameExt for rustc_span::RealFileName {
15501550
scope.bits().count_ones() == 1,
15511551
"one and only one scope should be passed to for_scope"
15521552
);
1553-
if sess.opts.unstable_opts.remap_path_scope.contains(scope) {
1553+
if sess.opts.remap_path_scope.contains(scope) {
15541554
self.remapped_path_if_available()
15551555
} else {
15561556
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: 22 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,27 @@ 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 informations
39+
- `object` - apply remappings to all paths in compiled executables or libraries, but not elsewhere. Currently an alias for `macro,debuginfo`.
40+
- `all` (default) - an alias for all of the above, also equivalent to supplying only `--remap-path-prefix` without `--remap-path-scope`.
41+
42+
### Example
43+
44+
```sh
45+
# With `object` scope only the build outputs will be remapped, the diagnostics won't be remapped.
46+
rustc --remap-path-prefix=$(PWD)=/remapped --remap-path-scope=object main.rs
47+
```
48+
2849
## Caveats and Limitations
2950

3051
### Linkers generated paths

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

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

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");

tests/run-make/split-debuginfo/rmake.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ enum RemapPathPrefix {
171171
Unspecified,
172172
}
173173

174-
/// `-Zremap-path-scope`. See
175-
/// <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/remap-path-scope.html#remap-path-scope>.
174+
/// `--remap-path-scope`
176175
#[derive(Debug, Clone)]
177176
enum RemapPathScope {
178177
/// Comma-separated list of remap scopes: `macro`, `diagnostics`, `debuginfo`, `object`, `all`.
@@ -921,7 +920,7 @@ mod shared_linux_other_tests {
921920
.debuginfo(level.cli_value())
922921
.arg(format!("-Zsplit-dwarf-kind={}", split_dwarf_kind.cli_value()))
923922
.remap_path_prefix(cwd(), remapped_prefix)
924-
.arg(format!("-Zremap-path-scope={scope}"))
923+
.arg(format!("--remap-path-scope={scope}"))
925924
.run();
926925
let found_files = cwd_filenames();
927926
FileAssertions { expected_files: BTreeSet::from(["foo", "foo.dwp"]) }
@@ -950,7 +949,7 @@ mod shared_linux_other_tests {
950949
.debuginfo(level.cli_value())
951950
.arg(format!("-Zsplit-dwarf-kind={}", split_dwarf_kind.cli_value()))
952951
.remap_path_prefix(cwd(), remapped_prefix)
953-
.arg(format!("-Zremap-path-scope={scope}"))
952+
.arg(format!("--remap-path-scope={scope}"))
954953
.run();
955954
let found_files = cwd_filenames();
956955
FileAssertions { expected_files: BTreeSet::from(["foo", "foo.dwp"]) }
@@ -1202,7 +1201,7 @@ mod shared_linux_other_tests {
12021201
.debuginfo(level.cli_value())
12031202
.arg(format!("-Zsplit-dwarf-kind={}", split_dwarf_kind.cli_value()))
12041203
.remap_path_prefix(cwd(), remapped_prefix)
1205-
.arg(format!("-Zremap-path-scope={scope}"))
1204+
.arg(format!("--remap-path-scope={scope}"))
12061205
.run();
12071206

12081207
let found_files = cwd_filenames();
@@ -1242,7 +1241,7 @@ mod shared_linux_other_tests {
12421241
.debuginfo(level.cli_value())
12431242
.arg(format!("-Zsplit-dwarf-kind={}", split_dwarf_kind.cli_value()))
12441243
.remap_path_prefix(cwd(), remapped_prefix)
1245-
.arg(format!("-Zremap-path-scope={scope}"))
1244+
.arg(format!("--remap-path-scope={scope}"))
12461245
.run();
12471246

12481247
let found_files = cwd_filenames();
@@ -1356,7 +1355,7 @@ fn main() {
13561355
// NOTE: these combinations are not exhaustive, because while porting to rmake.rs initially I
13571356
// tried to preserve the existing test behavior closely. Notably, no attempt was made to
13581357
// exhaustively cover all cases in the 6-fold Cartesian product of `{,-Csplit=debuginfo=...}` x
1359-
// `{,-Cdebuginfo=...}` x `{,--remap-path-prefix}` x `{,-Zremap-path-scope=...}` x
1358+
// `{,-Cdebuginfo=...}` x `{,--remap-path-prefix}` x `{,--remap-path-scope=...}` x
13601359
// `{,-Zsplit-dwarf-kind=...}` x `{,-Clinker-plugin-lto}`. If you really want to, you can
13611360
// identify which combination isn't exercised with a 6-layers nested for loop iterating through
13621361
// each of the cli flag enum variants.

tests/ui/errors/auxiliary/file-debuginfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ compile-flags: --remap-path-prefix={{src-base}}=remapped
2-
//@ compile-flags: -Zremap-path-scope=debuginfo
2+
//@ compile-flags: --remap-path-scope=debuginfo
33

44
#[macro_export]
55
macro_rules! my_file {

0 commit comments

Comments
 (0)