Skip to content

Commit dbc4ae7

Browse files
committed
Add __RUSTC_CWD within remap-path-prefix.
1 parent c7331d6 commit dbc4ae7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

compiler/rustc_session/src/config.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,10 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
11611161
opt::multi_s(
11621162
"",
11631163
"remap-path-prefix",
1164-
"Remap source names in all output (compiler messages and output files)",
1164+
"Remap source names in all output (compiler messages and output files).
1165+
The metasyntactic variable __RUSTC_CWD can be used to represent the current
1166+
working directory witin the FROM pattern.
1167+
",
11651168
"FROM=TO",
11661169
),
11671170
]);
@@ -1935,11 +1938,15 @@ fn parse_remap_path_prefix(
19351938
error_format,
19361939
"--remap-path-prefix must contain '=' between FROM and TO",
19371940
),
1938-
Some((from, to)) => (PathBuf::from(from), PathBuf::from(to)),
1941+
Some((from, to)) => (pathbuf_understanding_pwd(from), PathBuf::from(to)),
19391942
})
19401943
.collect()
19411944
}
19421945

1946+
fn pathbuf_understanding_pwd(path: &str) -> PathBuf {
1947+
PathBuf::from(std::str::replace(path, "__RUSTC_CWD", std::env::current_dir().unwrap()))
1948+
}
1949+
19431950
pub fn build_session_options(matches: &getopts::Matches) -> Options {
19441951
let color = parse_color(matches);
19451952

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

+4
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,10 @@ replacement is purely textual, with no consideration of the current system's
345345
pathname syntax. For example `--remap-path-prefix foo=bar` will match
346346
`foo/lib.rs` but not `./foo/lib.rs`.
347347

348+
Within the `FROM` pattern, the special string `__RUSTC_CWD` is replaced with
349+
the current working directory. This can be useful to ensure that the `rustc`
350+
command line is identical on different machines.
351+
348352
<a id="option-json"></a>
349353
## `--json`: configure json messages printed by the compiler
350354

0 commit comments

Comments
 (0)