Skip to content

Commit

Permalink
Add __RUSTC_CWD within remap-path-prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
adetaylor committed Jul 18, 2021
1 parent c7331d6 commit dbc4ae7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,10 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
opt::multi_s(
"",
"remap-path-prefix",
"Remap source names in all output (compiler messages and output files)",
"Remap source names in all output (compiler messages and output files).
The metasyntactic variable __RUSTC_CWD can be used to represent the current
working directory witin the FROM pattern.
",
"FROM=TO",
),
]);
Expand Down Expand Up @@ -1935,11 +1938,15 @@ fn parse_remap_path_prefix(
error_format,
"--remap-path-prefix must contain '=' between FROM and TO",
),
Some((from, to)) => (PathBuf::from(from), PathBuf::from(to)),
Some((from, to)) => (pathbuf_understanding_pwd(from), PathBuf::from(to)),
})
.collect()
}

fn pathbuf_understanding_pwd(path: &str) -> PathBuf {
PathBuf::from(std::str::replace(path, "__RUSTC_CWD", std::env::current_dir().unwrap()))
}

pub fn build_session_options(matches: &getopts::Matches) -> Options {
let color = parse_color(matches);

Expand Down
4 changes: 4 additions & 0 deletions src/doc/rustc/src/command-line-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ replacement is purely textual, with no consideration of the current system's
pathname syntax. For example `--remap-path-prefix foo=bar` will match
`foo/lib.rs` but not `./foo/lib.rs`.

Within the `FROM` pattern, the special string `__RUSTC_CWD` is replaced with
the current working directory. This can be useful to ensure that the `rustc`
command line is identical on different machines.

<a id="option-json"></a>
## `--json`: configure json messages printed by the compiler

Expand Down

0 comments on commit dbc4ae7

Please sign in to comment.