Skip to content

Commit d0d8258

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` scope always represent all the scopes. Co-authored-by: David Wood <[email protected]>
1 parent 8188f6c commit d0d8258

File tree

22 files changed

+124
-97
lines changed

22 files changed

+124
-97
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use rustc_hashes::Hash64;
2424
use rustc_macros::{BlobDecodable, Decodable, Encodable, HashStable_Generic};
2525
use rustc_span::edition::{DEFAULT_EDITION, EDITION_NAME_LIST, Edition, LATEST_STABLE_EDITION};
2626
use rustc_span::source_map::FilePathMapping;
27-
use rustc_span::{FileName, RealFileName, SourceFileHashAlgorithm, Symbol, sym};
27+
use rustc_span::{
28+
FileName, RealFileName, RemapPathScopeComponents, SourceFileHashAlgorithm, Symbol, sym,
29+
};
2830
use rustc_target::spec::{
2931
FramePointer, LinkSelfContainedComponents, LinkerFeatures, PanicStrategy, SplitDebuginfo,
3032
Target, TargetTuple,
@@ -1315,6 +1317,29 @@ impl OutputFilenames {
13151317
}
13161318
}
13171319

1320+
pub(crate) fn parse_remap_path_scope(
1321+
early_dcx: &EarlyDiagCtxt,
1322+
matches: &getopts::Matches,
1323+
) -> RemapPathScopeComponents {
1324+
if let Some(v) = matches.opt_str("remap-path-scope") {
1325+
let mut slot = RemapPathScopeComponents::empty();
1326+
for s in v.split(',') {
1327+
slot |= match s {
1328+
"macro" => RemapPathScopeComponents::MACRO,
1329+
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
1330+
"debuginfo" => RemapPathScopeComponents::DEBUGINFO,
1331+
"coverage" => RemapPathScopeComponents::COVERAGE,
1332+
"object" => RemapPathScopeComponents::OBJECT,
1333+
"all" => RemapPathScopeComponents::all(),
1334+
_ => early_dcx.early_fatal("argument for `--remap-path-scope` must be a comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `coverage`, `object`, `all`"),
1335+
}
1336+
}
1337+
slot
1338+
} else {
1339+
RemapPathScopeComponents::all()
1340+
}
1341+
}
1342+
13181343
#[derive(Clone, Debug)]
13191344
pub struct Sysroot {
13201345
pub explicit: Option<PathBuf>,
@@ -1351,9 +1376,9 @@ pub fn host_tuple() -> &'static str {
13511376

13521377
fn file_path_mapping(
13531378
remap_path_prefix: Vec<(PathBuf, PathBuf)>,
1354-
unstable_opts: &UnstableOptions,
1379+
remap_path_scope: RemapPathScopeComponents,
13551380
) -> FilePathMapping {
1356-
FilePathMapping::new(remap_path_prefix.clone(), unstable_opts.remap_path_scope)
1381+
FilePathMapping::new(remap_path_prefix.clone(), remap_path_scope)
13571382
}
13581383

13591384
impl Default for Options {
@@ -1365,7 +1390,7 @@ impl Default for Options {
13651390
// to create a default working directory.
13661391
let working_dir = {
13671392
let working_dir = std::env::current_dir().unwrap();
1368-
let file_mapping = file_path_mapping(Vec::new(), &unstable_opts);
1393+
let file_mapping = file_path_mapping(Vec::new(), RemapPathScopeComponents::empty());
13691394
file_mapping.to_real_filename(&RealFileName::empty(), &working_dir)
13701395
};
13711396

@@ -1401,6 +1426,7 @@ impl Default for Options {
14011426
cli_forced_codegen_units: None,
14021427
cli_forced_local_thinlto_off: false,
14031428
remap_path_prefix: Vec::new(),
1429+
remap_path_scope: RemapPathScopeComponents::all(),
14041430
real_rust_source_base_dir: None,
14051431
real_rustc_dev_source_base_dir: None,
14061432
edition: DEFAULT_EDITION,
@@ -1427,7 +1453,7 @@ impl Options {
14271453
}
14281454

14291455
pub fn file_path_mapping(&self) -> FilePathMapping {
1430-
file_path_mapping(self.remap_path_prefix.clone(), &self.unstable_opts)
1456+
file_path_mapping(self.remap_path_prefix.clone(), self.remap_path_scope)
14311457
}
14321458

14331459
/// Returns `true` if there will be an output file generated.
@@ -1864,6 +1890,14 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
18641890
"Remap source names in all output (compiler messages and output files)",
18651891
"<FROM>=<TO>",
18661892
),
1893+
opt(
1894+
Stable,
1895+
Opt,
1896+
"",
1897+
"remap-path-scope",
1898+
"Defines which scopes of paths should be remapped by `--remap-path-prefix`",
1899+
"<macro,diagnostics,debuginfo,coverage,object,all>",
1900+
),
18671901
opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "<VAR>=<VALUE>"),
18681902
];
18691903
options.extend(verbose_only.into_iter().map(|mut opt| {
@@ -2704,6 +2738,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
27042738
let externs = parse_externs(early_dcx, matches, &unstable_opts);
27052739

27062740
let remap_path_prefix = parse_remap_path_prefix(early_dcx, matches, &unstable_opts);
2741+
let remap_path_scope = parse_remap_path_scope(early_dcx, matches);
27072742

27082743
let pretty = parse_pretty(early_dcx, &unstable_opts);
27092744

@@ -2770,7 +2805,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
27702805
early_dcx.early_fatal(format!("Current directory is invalid: {e}"));
27712806
});
27722807

2773-
let file_mapping = file_path_mapping(remap_path_prefix.clone(), &unstable_opts);
2808+
let file_mapping = file_path_mapping(remap_path_prefix.clone(), remap_path_scope);
27742809
file_mapping.to_real_filename(&RealFileName::empty(), &working_dir)
27752810
};
27762811

@@ -2808,6 +2843,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
28082843
cli_forced_codegen_units: codegen_units,
28092844
cli_forced_local_thinlto_off: disable_local_thinlto,
28102845
remap_path_prefix,
2846+
remap_path_scope,
28112847
real_rust_source_base_dir,
28122848
real_rustc_dev_source_base_dir,
28132849
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`
@@ -872,7 +874,6 @@ mod desc {
872874
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)";
873875
pub(crate) const parse_proc_macro_execution_strategy: &str =
874876
"one of supported execution strategies (`same-thread`, or `cross-thread`)";
875-
pub(crate) const parse_remap_path_scope: &str = "comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `coverage`, `object`, `all`";
876877
pub(crate) const parse_inlining_threshold: &str =
877878
"either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number";
878879
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`)";
@@ -1711,29 +1712,6 @@ pub mod parse {
17111712
true
17121713
}
17131714

1714-
pub(crate) fn parse_remap_path_scope(
1715-
slot: &mut RemapPathScopeComponents,
1716-
v: Option<&str>,
1717-
) -> bool {
1718-
if let Some(v) = v {
1719-
*slot = RemapPathScopeComponents::empty();
1720-
for s in v.split(',') {
1721-
*slot |= match s {
1722-
"macro" => RemapPathScopeComponents::MACRO,
1723-
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
1724-
"debuginfo" => RemapPathScopeComponents::DEBUGINFO,
1725-
"coverage" => RemapPathScopeComponents::COVERAGE,
1726-
"object" => RemapPathScopeComponents::OBJECT,
1727-
"all" => RemapPathScopeComponents::all(),
1728-
_ => return false,
1729-
}
1730-
}
1731-
true
1732-
} else {
1733-
false
1734-
}
1735-
}
1736-
17371715
pub(crate) fn parse_relocation_model(slot: &mut Option<RelocModel>, v: Option<&str>) -> bool {
17381716
match v.and_then(|s| RelocModel::from_str(s).ok()) {
17391717
Some(relocation_model) => *slot = Some(relocation_model),
@@ -2584,8 +2562,6 @@ options! {
25842562
"whether ELF relocations can be relaxed"),
25852563
remap_cwd_prefix: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
25862564
"remap paths under the current working directory to this path prefix"),
2587-
remap_path_scope: RemapPathScopeComponents = (RemapPathScopeComponents::all(), parse_remap_path_scope, [TRACKED],
2588-
"remap path scope (default: all)"),
25892565
remark_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
25902566
"directory into which to write optimization remarks (if not specified, they will be \
25912567
written to standard error output)"),

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-consts/rmake.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ fn main() {
9797
location_caller
9898
.crate_type("lib")
9999
.remap_path_prefix(cwd(), "/remapped")
100-
.arg("-Zremap-path-scope=object")
100+
.arg("--remap-path-scope=object")
101101
.input(cwd().join("location-caller.rs"));
102102
location_caller.run();
103103

104104
let mut runner = rustc();
105105
runner
106106
.crate_type("bin")
107107
.remap_path_prefix(cwd(), "/remapped")
108-
.arg("-Zremap-path-scope=diagnostics")
108+
.arg("--remap-path-scope=diagnostics")
109109
.input(cwd().join("runner.rs"))
110110
.output(&runner_bin);
111111
runner.run();

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)