diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index b444f66258a8e..527369b37ba47 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1161,7 +1161,10 @@ pub fn rustc_optgroups() -> Vec { 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", ), ]); @@ -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); diff --git a/src/doc/rustc/src/command-line-arguments.md b/src/doc/rustc/src/command-line-arguments.md index 7d3cad7988c8c..eb36e968ad10d 100644 --- a/src/doc/rustc/src/command-line-arguments.md +++ b/src/doc/rustc/src/command-line-arguments.md @@ -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. + ## `--json`: configure json messages printed by the compiler