Rollup merge of #48359 - jsgf:remap-path-prefix, r=sanxiyn
Fixes #47311. r? @nrc
This commit is contained in:
commit
fac7d7cfb2
@ -125,6 +125,16 @@ Print version info and exit.
|
||||
\fB\-v\fR, \fB\-\-verbose\fR
|
||||
Use verbose output.
|
||||
.TP
|
||||
\fB\-\-remap\-path\-prefix\fR \fIfrom\fR=\fIto\fR
|
||||
Remap source path prefixes in all output, including compiler diagnostics, debug information,
|
||||
macro expansions, etc. The \fIfrom\fR=\fIto\fR parameter is scanned from right to left, so \fIfrom\fR
|
||||
may contain '=', but \fIto\fR may not.
|
||||
|
||||
This is useful for normalizing build products, for example by removing the current directory out of
|
||||
pathnames emitted into the object files. The replacement is purely textual, with no consideration of
|
||||
the current system's pathname syntax. For example \fI\-\-remap\-path\-prefix foo=bar\fR will
|
||||
match \fBfoo/lib.rs\fR but not \fB./foo/lib.rs\fR.
|
||||
.TP
|
||||
\fB\-\-extern\fR \fINAME\fR=\fIPATH\fR
|
||||
Specify where an external rust library is located. These should match
|
||||
\fIextern\fR declarations in the crate's source code.
|
||||
|
@ -1,37 +0,0 @@
|
||||
# `remap-path-prefix`
|
||||
|
||||
The tracking issue for this feature is: [#41555](https://github.com/rust-lang/rust/issues/41555)
|
||||
|
||||
------------------------
|
||||
|
||||
The `-Z remap-path-prefix-from`, `-Z remap-path-prefix-to` commandline option
|
||||
pair allows to replace prefixes of any file paths the compiler emits in various
|
||||
places. This is useful for bringing debuginfo paths into a well-known form and
|
||||
for achieving reproducible builds independent of the directory the compiler was
|
||||
executed in. All paths emitted by the compiler are affected, including those in
|
||||
error messages.
|
||||
|
||||
In order to map all paths starting with `/home/foo/my-project/src` to
|
||||
`/sources/my-project`, one would invoke the compiler as follows:
|
||||
|
||||
```text
|
||||
rustc -Zremap-path-prefix-from="/home/foo/my-project/src" -Zremap-path-prefix-to="/sources/my-project"
|
||||
```
|
||||
|
||||
Debuginfo for code from the file `/home/foo/my-project/src/foo/mod.rs`,
|
||||
for example, would then point debuggers to `/sources/my-project/foo/mod.rs`
|
||||
instead of the original file.
|
||||
|
||||
The options can be specified multiple times when multiple prefixes should be
|
||||
mapped:
|
||||
|
||||
```text
|
||||
rustc -Zremap-path-prefix-from="/home/foo/my-project/src" \
|
||||
-Zremap-path-prefix-to="/sources/my-project" \
|
||||
-Zremap-path-prefix-from="/home/foo/my-project/build-dir" \
|
||||
-Zremap-path-prefix-to="/stable-build-dir"
|
||||
```
|
||||
|
||||
When the options are given multiple times, the nth `-from` will be matched up
|
||||
with the nth `-to` and they can appear anywhere on the commandline. Mappings
|
||||
specified later on the line will take precedence over earlier ones.
|
@ -316,7 +316,7 @@ impl SourceFile {
|
||||
/// If the code span associated with this `SourceFile` was generated by an external macro, this
|
||||
/// may not be an actual path on the filesystem. Use [`is_real`] to check.
|
||||
///
|
||||
/// Also note that even if `is_real` returns `true`, if `-Z remap-path-prefix-*` was passed on
|
||||
/// Also note that even if `is_real` returns `true`, if `--remap-path-prefix` was passed on
|
||||
/// the command line, the path as given may not actually be valid.
|
||||
///
|
||||
/// [`is_real`]: #method.is_real
|
||||
|
@ -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],
|
||||
@ -1597,6 +1593,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
|
||||
}
|
||||
@ -1720,23 +1717,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;
|
||||
@ -1970,6 +1950,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,
|
||||
@ -1997,6 +1991,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)
|
||||
}
|
||||
|
@ -323,7 +323,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||
// paths because any relative paths are potentially relative to
|
||||
// a wrong directory.
|
||||
// However, if a path has been modified via
|
||||
// `-Zremap-path-prefix` we assume the user has already set
|
||||
// `--remap-path-prefix` we assume the user has already set
|
||||
// things up the way they want and don't touch the path values
|
||||
// anymore.
|
||||
match filemap.name {
|
||||
|
@ -129,7 +129,7 @@ pub struct CodeMap {
|
||||
pub(super) files: RefCell<Vec<Rc<FileMap>>>,
|
||||
file_loader: Box<FileLoader>,
|
||||
// This is used to apply the file path remapping as specified via
|
||||
// -Zremap-path-prefix to all FileMaps allocated within this CodeMap.
|
||||
// --remap-path-prefix to all FileMaps allocated within this CodeMap.
|
||||
path_mapping: FilePathMapping,
|
||||
stable_id_to_filemap: RefCell<FxHashMap<StableFilemapId, Rc<FileMap>>>,
|
||||
/// In case we are in a doctest, replace all file names with the PathBuf,
|
||||
|
@ -670,7 +670,7 @@ pub struct FileMap {
|
||||
/// originate from files has names between angle brackets by convention,
|
||||
/// e.g. `<anon>`
|
||||
pub name: FileName,
|
||||
/// True if the `name` field above has been modified by -Zremap-path-prefix
|
||||
/// True if the `name` field above has been modified by --remap-path-prefix
|
||||
pub name_was_remapped: bool,
|
||||
/// The unmapped path of the file that the source came from.
|
||||
/// Set to `None` if the FileMap was imported from an external crate.
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-tidy-linelength
|
||||
|
||||
// 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
|
||||
// compile-flags: -g --remap-path-prefix={{cwd}}=/the/aux-cwd --remap-path-prefix={{src-base}}/remap_path_prefix/auxiliary=/the/aux-src
|
||||
|
||||
#[inline]
|
||||
pub fn some_aux_function() -> i32 {
|
||||
|
@ -11,7 +11,7 @@
|
||||
// ignore-windows
|
||||
// ignore-tidy-linelength
|
||||
|
||||
// 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
|
||||
// compile-flags: -g -C no-prepopulate-passes --remap-path-prefix={{cwd}}=/the/cwd --remap-path-prefix={{src-base}}=/the/src
|
||||
// aux-build:remap_path_prefix_aux.rs
|
||||
|
||||
extern crate remap_path_prefix_aux;
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
//[rpass1] compile-flags: -g
|
||||
//[rpass2] compile-flags: -g
|
||||
//[rpass3] compile-flags: -g -Zremap-path-prefix-from={{src-base}} -Zremap-path-prefix-to=/the/src
|
||||
//[rpass3] compile-flags: -g --remap-path-prefix={{src-base}}=/the/src
|
||||
|
||||
#![feature(rustc_attrs)]
|
||||
#![crate_type="rlib"]
|
||||
|
Loading…
x
Reference in New Issue
Block a user