@@ -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}
0 commit comments