Skip to content

Commit fac7d7c

Browse files
committed
Rollup merge of rust-lang#48359 - jsgf:remap-path-prefix, r=sanxiyn
Fixes rust-lang#47311. r? @nrc
2 parents f59ab8e + 56a6828 commit fac7d7c

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],
@@ -1597,6 +1593,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
15971593
`expanded` (crates expanded), or
15981594
`expanded,identified` (fully parenthesized, AST nodes with IDs).",
15991595
"TYPE"),
1596+
opt::multi_s("", "remap-path-prefix", "remap source names in output", "FROM=TO"),
16001597
]);
16011598
opts
16021599
}
@@ -1720,23 +1717,6 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
17201717
output_types.insert(OutputType::Exe, None);
17211718
}
17221719

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-
17401720
let mut cg = build_codegen_options(matches, error_format);
17411721
let mut codegen_units = cg.codegen_units;
17421722
let mut disable_thinlto = false;
@@ -1970,6 +1950,20 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
19701950

19711951
let crate_name = matches.opt_str("crate-name");
19721952

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+
19731967
(Options {
19741968
crate_types,
19751969
optimize: opt_level,
@@ -1997,6 +1991,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
19971991
actually_rustdoc: false,
19981992
cli_forced_codegen_units: codegen_units,
19991993
cli_forced_thinlto_off: disable_thinlto,
1994+
remap_path_prefix,
20001995
},
20011996
cfg)
20021997
}

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
@@ -670,7 +670,7 @@ pub struct FileMap {
670670
/// originate from files has names between angle brackets by convention,
671671
/// e.g. `<anon>`
672672
pub name: FileName,
673-
/// True if the `name` field above has been modified by -Zremap-path-prefix
673+
/// True if the `name` field above has been modified by --remap-path-prefix
674674
pub name_was_remapped: bool,
675675
/// The unmapped path of the file that the source came from.
676676
/// 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)