@@ -435,6 +435,9 @@ top_level_options!(
435
435
// if we otherwise use the defaults of rustc.
436
436
cli_forced_codegen_units: Option <usize > [ UNTRACKED ] ,
437
437
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 ] ,
438
441
}
439
442
) ;
440
443
@@ -617,6 +620,7 @@ pub fn basic_options() -> Options {
617
620
actually_rustdoc : false ,
618
621
cli_forced_codegen_units : None ,
619
622
cli_forced_thinlto_off : false ,
623
+ remap_path_prefix : Vec :: new ( ) ,
620
624
}
621
625
}
622
626
@@ -635,11 +639,7 @@ impl Options {
635
639
}
636
640
637
641
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 ( ) )
643
643
}
644
644
645
645
/// True if there will be an output file generated
@@ -1269,10 +1269,6 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
1269
1269
"set the optimization fuel quota for a crate" ) ,
1270
1270
print_fuel: Option <String > = ( None , parse_opt_string, [ TRACKED ] ,
1271
1271
"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" ) ,
1276
1272
force_unstable_if_unmarked: bool = ( false , parse_bool, [ TRACKED ] ,
1277
1273
"force all crates to be `rustc_private` unstable" ) ,
1278
1274
pre_link_arg: Vec <String > = ( vec![ ] , parse_string_push, [ UNTRACKED ] ,
@@ -1595,6 +1591,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
1595
1591
`expanded` (crates expanded), or
1596
1592
`expanded,identified` (fully parenthesized, AST nodes with IDs)." ,
1597
1593
"TYPE" ) ,
1594
+ opt:: multi_s( "" , "remap-path-prefix" , "remap source names in output" , "FROM=TO" ) ,
1598
1595
] ) ;
1599
1596
opts
1600
1597
}
@@ -1718,23 +1715,6 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
1718
1715
output_types. insert ( OutputType :: Exe , None ) ;
1719
1716
}
1720
1717
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
-
1738
1718
let mut cg = build_codegen_options ( matches, error_format) ;
1739
1719
let mut codegen_units = cg. codegen_units ;
1740
1720
let mut disable_thinlto = false ;
@@ -1968,6 +1948,20 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
1968
1948
1969
1949
let crate_name = matches. opt_str ( "crate-name" ) ;
1970
1950
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
+
1971
1965
( Options {
1972
1966
crate_types,
1973
1967
optimize : opt_level,
@@ -1995,6 +1989,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
1995
1989
actually_rustdoc : false ,
1996
1990
cli_forced_codegen_units : codegen_units,
1997
1991
cli_forced_thinlto_off : disable_thinlto,
1992
+ remap_path_prefix,
1998
1993
} ,
1999
1994
cfg)
2000
1995
}
0 commit comments