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 #41555.
This commit is contained in:
Jeremy Fitzhardinge 2018-02-18 15:05:24 -08:00 committed by Jeremy Fitzhardinge
parent b1f8e6fb06
commit 56a6828533
10 changed files with 38 additions and 70 deletions

View file

@ -435,6 +435,9 @@ top_level_options!(
// if we otherwise use the defaults of rustc.
cli_forced_codegen_units: Option<usize> [UNTRACKED],
cli_forced_thinlto_off: bool [UNTRACKED],
// Remap source path prefixes in all output (messages, object files, debug, etc)
remap_path_prefix: Vec<(PathBuf, PathBuf)> [UNTRACKED],
}
);
@ -617,6 +620,7 @@ pub fn basic_options() -> Options {
actually_rustdoc: false,
cli_forced_codegen_units: None,
cli_forced_thinlto_off: false,
remap_path_prefix: Vec::new(),
}
}
@ -635,11 +639,7 @@ impl Options {
}
pub fn file_path_mapping(&self) -> FilePathMapping {
FilePathMapping::new(
self.debugging_opts.remap_path_prefix_from.iter().zip(
self.debugging_opts.remap_path_prefix_to.iter()
).map(|(src, dst)| (src.clone(), dst.clone())).collect()
)
FilePathMapping::new(self.remap_path_prefix.clone())
}
/// True if there will be an output file generated
@ -1269,10 +1269,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"set the optimization fuel quota for a crate"),
print_fuel: Option<String> = (None, parse_opt_string, [TRACKED],
"make Rustc print the total optimization fuel used by a crate"),
remap_path_prefix_from: Vec<PathBuf> = (vec![], parse_pathbuf_push, [UNTRACKED],
"add a source pattern to the file path remapping config"),
remap_path_prefix_to: Vec<PathBuf> = (vec![], parse_pathbuf_push, [UNTRACKED],
"add a mapping target to the file path remapping config"),
force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
"force all crates to be `rustc_private` unstable"),
pre_link_arg: Vec<String> = (vec![], parse_string_push, [UNTRACKED],
@ -1595,6 +1591,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
`expanded` (crates expanded), or
`expanded,identified` (fully parenthesized, AST nodes with IDs).",
"TYPE"),
opt::multi_s("", "remap-path-prefix", "remap source names in output", "FROM=TO"),
]);
opts
}
@ -1718,23 +1715,6 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
output_types.insert(OutputType::Exe, None);
}
let remap_path_prefix_sources = debugging_opts.remap_path_prefix_from.len();
let remap_path_prefix_targets = debugging_opts.remap_path_prefix_to.len();
if remap_path_prefix_targets < remap_path_prefix_sources {
for source in &debugging_opts.remap_path_prefix_from[remap_path_prefix_targets..] {
early_error(error_format,
&format!("option `-Zremap-path-prefix-from='{}'` does not have \
a corresponding `-Zremap-path-prefix-to`", source.display()))
}
} else if remap_path_prefix_targets > remap_path_prefix_sources {
for target in &debugging_opts.remap_path_prefix_to[remap_path_prefix_sources..] {
early_error(error_format,
&format!("option `-Zremap-path-prefix-to='{}'` does not have \
a corresponding `-Zremap-path-prefix-from`", target.display()))
}
}
let mut cg = build_codegen_options(matches, error_format);
let mut codegen_units = cg.codegen_units;
let mut disable_thinlto = false;
@ -1968,6 +1948,20 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
let crate_name = matches.opt_str("crate-name");
let remap_path_prefix = matches.opt_strs("remap-path-prefix")
.into_iter()
.map(|remap| {
let mut parts = remap.rsplitn(2, '='); // reverse iterator
let to = parts.next();
let from = parts.next();
match (from, to) {
(Some(from), Some(to)) => (PathBuf::from(from), PathBuf::from(to)),
_ => early_error(error_format,
"--remap-path-prefix must contain '=' between FROM and TO"),
}
})
.collect();
(Options {
crate_types,
optimize: opt_level,
@ -1995,6 +1989,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
actually_rustdoc: false,
cli_forced_codegen_units: codegen_units,
cli_forced_thinlto_off: disable_thinlto,
remap_path_prefix,
},
cfg)
}