Skip to content

Commit 56a6828

Browse files
committed
Implement --remap-path-prefix
Remove experimental -Zremap-path-prefix-from/to, and replace it with the stabilized --remap-path-prefix=from=to variant. This is an implementation for issue of rust-lang#41555.
1 parent b1f8e6f commit 56a6828

File tree

10 files changed

+38
-70
lines changed

10 files changed

+38
-70
lines changed

src/doc/man/rustc.1

+10
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ Print version info and exit.
125125
\fB\-v\fR, \fB\-\-verbose\fR
126126
Use verbose output.
127127
.TP
128+
\fB\-\-remap\-path\-prefix\fR \fIfrom\fR=\fIto\fR
129+
Remap source path prefixes in all output, including compiler diagnostics, debug information,
130+
macro expansions, etc. The \fIfrom\fR=\fIto\fR parameter is scanned from right to left, so \fIfrom\fR
131+
may contain '=', but \fIto\fR may not.
132+
133+
This is useful for normalizing build products, for example by removing the current directory out of
134+
pathnames emitted into the object files. The replacement is purely textual, with no consideration of
135+
the current system's pathname syntax. For example \fI\-\-remap\-path\-prefix foo=bar\fR will
136+
match \fBfoo/lib.rs\fR but not \fB./foo/lib.rs\fR.
137+
.TP
128138
\fB\-\-extern\fR \fINAME\fR=\fIPATH\fR
129139
Specify where an external rust library is located. These should match
130140
\fIextern\fR declarations in the crate's source code.

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

-37
This file was deleted.

src/libproc_macro/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl SourceFile {
316316
/// If the code span associated with this `SourceFile` was generated by an external macro, this
317317
/// may not be an actual path on the filesystem. Use [`is_real`] to check.
318318
///
319-
/// Also note that even if `is_real` returns `true`, if `-Z remap-path-prefix-*` was passed on
319+
/// Also note that even if `is_real` returns `true`, if `--remap-path-prefix` was passed on
320320
/// the command line, the path as given may not actually be valid.
321321
///
322322
/// [`is_real`]: #method.is_real

src/librustc/session/config.rs

+21-26
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ top_level_options!(
435435
// if we otherwise use the defaults of rustc.
436436
cli_forced_codegen_units: Option<usize> [UNTRACKED],
437437
cli_forced_thinlto_off: bool [UNTRACKED],
438+
439+
// Remap source path prefixes in all output (messages, object files, debug, etc)
440+
remap_path_prefix: Vec<(PathBuf, PathBuf)> [UNTRACKED],
438441
}
439442
);
440443

@@ -617,6 +620,7 @@ pub fn basic_options() -> Options {
617620
actually_rustdoc: false,
618621
cli_forced_codegen_units: None,
619622
cli_forced_thinlto_off: false,
623+
remap_path_prefix: Vec::new(),
620624
}
621625
}
622626

@@ -635,11 +639,7 @@ impl Options {
635639
}
636640

637641
pub fn file_path_mapping(&self) -> FilePathMapping {
638-
FilePathMapping::new(
639-
self.debugging_opts.remap_path_prefix_from.iter().zip(
640-
self.debugging_opts.remap_path_prefix_to.iter()
641-
).map(|(src, dst)| (src.clone(), dst.clone())).collect()
642-
)
642+
FilePathMapping::new(self.remap_path_prefix.clone())
643643
}
644644

645645
/// True if there will be an output file generated
@@ -1269,10 +1269,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12691269
"set the optimization fuel quota for a crate"),
12701270
print_fuel: Option<String> = (None, parse_opt_string, [TRACKED],
12711271
"make Rustc print the total optimization fuel used by a crate"),
1272-
remap_path_prefix_from: Vec<PathBuf> = (vec![], parse_pathbuf_push, [UNTRACKED],
1273-
"add a source pattern to the file path remapping config"),
1274-
remap_path_prefix_to: Vec<PathBuf> = (vec![], parse_pathbuf_push, [UNTRACKED],
1275-
"add a mapping target to the file path remapping config"),
12761272
force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
12771273
"force all crates to be `rustc_private` unstable"),
12781274
pre_link_arg: Vec<String> = (vec![], parse_string_push, [UNTRACKED],
@@ -1595,6 +1591,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
15951591
`expanded` (crates expanded), or
15961592
`expanded,identified` (fully parenthesized, AST nodes with IDs).",
15971593
"TYPE"),
1594+
opt::multi_s("", "remap-path-prefix", "remap source names in output", "FROM=TO"),
15981595
]);
15991596
opts
16001597
}
@@ -1718,23 +1715,6 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
17181715
output_types.insert(OutputType::Exe, None);
17191716
}
17201717

1721-
let remap_path_prefix_sources = debugging_opts.remap_path_prefix_from.len();
1722-
let remap_path_prefix_targets = debugging_opts.remap_path_prefix_to.len();
1723-
1724-
if remap_path_prefix_targets < remap_path_prefix_sources {
1725-
for source in &debugging_opts.remap_path_prefix_from[remap_path_prefix_targets..] {
1726-
early_error(error_format,
1727-
&format!("option `-Zremap-path-prefix-from='{}'` does not have \
1728-
a corresponding `-Zremap-path-prefix-to`", source.display()))
1729-
}
1730-
} else if remap_path_prefix_targets > remap_path_prefix_sources {
1731-
for target in &debugging_opts.remap_path_prefix_to[remap_path_prefix_sources..] {
1732-
early_error(error_format,
1733-
&format!("option `-Zremap-path-prefix-to='{}'` does not have \
1734-
a corresponding `-Zremap-path-prefix-from`", target.display()))
1735-
}
1736-
}
1737-
17381718
let mut cg = build_codegen_options(matches, error_format);
17391719
let mut codegen_units = cg.codegen_units;
17401720
let mut disable_thinlto = false;
@@ -1968,6 +1948,20 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
19681948

19691949
let crate_name = matches.opt_str("crate-name");
19701950

1951+
let remap_path_prefix = matches.opt_strs("remap-path-prefix")
1952+
.into_iter()
1953+
.map(|remap| {
1954+
let mut parts = remap.rsplitn(2, '='); // reverse iterator
1955+
let to = parts.next();
1956+
let from = parts.next();
1957+
match (from, to) {
1958+
(Some(from), Some(to)) => (PathBuf::from(from), PathBuf::from(to)),
1959+
_ => early_error(error_format,
1960+
"--remap-path-prefix must contain '=' between FROM and TO"),
1961+
}
1962+
})
1963+
.collect();
1964+
19711965
(Options {
19721966
crate_types,
19731967
optimize: opt_level,
@@ -1995,6 +1989,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
19951989
actually_rustdoc: false,
19961990
cli_forced_codegen_units: codegen_units,
19971991
cli_forced_thinlto_off: disable_thinlto,
1992+
remap_path_prefix,
19981993
},
19991994
cfg)
20001995
}

src/librustc_metadata/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
323323
// paths because any relative paths are potentially relative to
324324
// a wrong directory.
325325
// However, if a path has been modified via
326-
// `-Zremap-path-prefix` we assume the user has already set
326+
// `--remap-path-prefix` we assume the user has already set
327327
// things up the way they want and don't touch the path values
328328
// anymore.
329329
match filemap.name {

src/libsyntax/codemap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ pub struct CodeMap {
129129
pub(super) files: RefCell<Vec<Rc<FileMap>>>,
130130
file_loader: Box<FileLoader>,
131131
// This is used to apply the file path remapping as specified via
132-
// -Zremap-path-prefix to all FileMaps allocated within this CodeMap.
132+
// --remap-path-prefix to all FileMaps allocated within this CodeMap.
133133
path_mapping: FilePathMapping,
134134
stable_id_to_filemap: RefCell<FxHashMap<StableFilemapId, Rc<FileMap>>>,
135135
/// In case we are in a doctest, replace all file names with the PathBuf,

src/libsyntax_pos/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ pub struct FileMap {
664664
/// originate from files has names between angle brackets by convention,
665665
/// e.g. `<anon>`
666666
pub name: FileName,
667-
/// True if the `name` field above has been modified by -Zremap-path-prefix
667+
/// True if the `name` field above has been modified by --remap-path-prefix
668668
pub name_was_remapped: bool,
669669
/// The unmapped path of the file that the source came from.
670670
/// Set to `None` if the FileMap was imported from an external crate.

src/test/codegen/remap_path_prefix/auxiliary/remap_path_prefix_aux.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// ignore-tidy-linelength
1212

13-
// compile-flags: -g -Zremap-path-prefix-from={{cwd}} -Zremap-path-prefix-to=/the/aux-cwd -Zremap-path-prefix-from={{src-base}}/remap_path_prefix/auxiliary -Zremap-path-prefix-to=/the/aux-src
13+
// compile-flags: -g --remap-path-prefix={{cwd}}=/the/aux-cwd --remap-path-prefix={{src-base}}/remap_path_prefix/auxiliary=/the/aux-src
1414

1515
#[inline]
1616
pub fn some_aux_function() -> i32 {

src/test/codegen/remap_path_prefix/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// ignore-windows
1212
// ignore-tidy-linelength
1313

14-
// compile-flags: -g -C no-prepopulate-passes -Zremap-path-prefix-from={{cwd}} -Zremap-path-prefix-to=/the/cwd -Zremap-path-prefix-from={{src-base}} -Zremap-path-prefix-to=/the/src
14+
// compile-flags: -g -C no-prepopulate-passes --remap-path-prefix={{cwd}}=/the/cwd --remap-path-prefix={{src-base}}=/the/src
1515
// aux-build:remap_path_prefix_aux.rs
1616

1717
extern crate remap_path_prefix_aux;

src/test/incremental/remapped_paths_cc/auxiliary/extern_crate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
//[rpass1] compile-flags: -g
1414
//[rpass2] compile-flags: -g
15-
//[rpass3] compile-flags: -g -Zremap-path-prefix-from={{src-base}} -Zremap-path-prefix-to=/the/src
15+
//[rpass3] compile-flags: -g --remap-path-prefix={{src-base}}=/the/src
1616

1717
#![feature(rustc_attrs)]
1818
#![crate_type="rlib"]

0 commit comments

Comments
 (0)