@@ -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 ] ,
@@ -1597,6 +1593,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
1597
1593
`expanded` (crates expanded), or
1598
1594
`expanded,identified` (fully parenthesized, AST nodes with IDs)." ,
1599
1595
"TYPE" ) ,
1596
+ opt:: multi_s( "" , "remap-path-prefix" , "remap source names in output" , "FROM=TO" ) ,
1600
1597
] ) ;
1601
1598
opts
1602
1599
}
@@ -1720,23 +1717,6 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
1720
1717
output_types. insert ( OutputType :: Exe , None ) ;
1721
1718
}
1722
1719
1723
- let remap_path_prefix_sources = debugging_opts. remap_path_prefix_from . len ( ) ;
1724
- let remap_path_prefix_targets = debugging_opts. remap_path_prefix_to . len ( ) ;
1725
-
1726
- if remap_path_prefix_targets < remap_path_prefix_sources {
1727
- for source in & debugging_opts. remap_path_prefix_from [ remap_path_prefix_targets..] {
1728
- early_error ( error_format,
1729
- & format ! ( "option `-Zremap-path-prefix-from='{}'` does not have \
1730
- a corresponding `-Zremap-path-prefix-to`", source. display( ) ) )
1731
- }
1732
- } else if remap_path_prefix_targets > remap_path_prefix_sources {
1733
- for target in & debugging_opts. remap_path_prefix_to [ remap_path_prefix_sources..] {
1734
- early_error ( error_format,
1735
- & format ! ( "option `-Zremap-path-prefix-to='{}'` does not have \
1736
- a corresponding `-Zremap-path-prefix-from`", target. display( ) ) )
1737
- }
1738
- }
1739
-
1740
1720
let mut cg = build_codegen_options ( matches, error_format) ;
1741
1721
let mut codegen_units = cg. codegen_units ;
1742
1722
let mut disable_thinlto = false ;
@@ -1970,6 +1950,20 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
1970
1950
1971
1951
let crate_name = matches. opt_str ( "crate-name" ) ;
1972
1952
1953
+ let remap_path_prefix = matches. opt_strs ( "remap-path-prefix" )
1954
+ . into_iter ( )
1955
+ . map ( |remap| {
1956
+ let mut parts = remap. rsplitn ( 2 , '=' ) ; // reverse iterator
1957
+ let to = parts. next ( ) ;
1958
+ let from = parts. next ( ) ;
1959
+ match ( from, to) {
1960
+ ( Some ( from) , Some ( to) ) => ( PathBuf :: from ( from) , PathBuf :: from ( to) ) ,
1961
+ _ => early_error ( error_format,
1962
+ "--remap-path-prefix must contain '=' between FROM and TO" ) ,
1963
+ }
1964
+ } )
1965
+ . collect ( ) ;
1966
+
1973
1967
( Options {
1974
1968
crate_types,
1975
1969
optimize : opt_level,
@@ -1997,6 +1991,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
1997
1991
actually_rustdoc : false ,
1998
1992
cli_forced_codegen_units : codegen_units,
1999
1993
cli_forced_thinlto_off : disable_thinlto,
1994
+ remap_path_prefix,
2000
1995
} ,
2001
1996
cfg)
2002
1997
}
0 commit comments