Auto merge of #83813 - cbeuw:remap-std, r=michaelwoerister
Fix `--remap-path-prefix` not correctly remapping `rust-src` component paths and unify handling of path mapping with virtualized paths This PR fixes #73167 ("Binaries end up containing path to the rust-src component despite `--remap-path-prefix`") by preventing real local filesystem paths from reaching compilation output if the path is supposed to be remapped. `RealFileName::Named` introduced in #72767 is now renamed as `LocalPath`, because this variant wraps a (most likely) valid local filesystem path. `RealFileName::Devirtualized` is renamed as `Remapped` to be used for remapped path from a real path via `--remap-path-prefix` argument, as well as real path inferred from a virtualized (during compiler bootstrapping) `/rustc/...` path. The `local_path` field is now an `Option<PathBuf>`, as it will be set to `None` before serialisation, so it never reaches any build output. Attempting to serialise a non-`None` `local_path` will cause an assertion faliure. When a path is remapped, a `RealFileName::Remapped` variant is created. The original path is preserved in `local_path` field and the remapped path is saved in `virtual_name` field. Previously, the `local_path` is directly modified which goes against its purpose of "suitable for reading from the file system on the local host". `rustc_span::SourceFile`'s fields `unmapped_path` (introduced by #44940) and `name_was_remapped` (introduced by #41508 when `--remap-path-prefix` feature originally added) are removed, as these two pieces of information can be inferred from the `name` field: if it's anything other than a `FileName::Real(_)`, or if it is a `FileName::Real(RealFileName::LocalPath(_))`, then clearly `name_was_remapped` would've been false and `unmapped_path` would've been `None`. If it is a `FileName::Real(RealFileName::Remapped{local_path, virtual_name})`, then `name_was_remapped` would've been true and `unmapped_path` would've been `Some(local_path)`. cc `@eddyb` who implemented `/rustc/...` path devirtualisation
This commit is contained in:
commit
e1ff91f439
48 changed files with 442 additions and 265 deletions
|
@ -1201,6 +1201,9 @@ options! {
|
|||
"whether ELF relocations can be relaxed"),
|
||||
relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
|
||||
"choose which RELRO level to use"),
|
||||
simulate_remapped_rust_src_base: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
|
||||
"simulate the effect of remap-debuginfo = true at bootstrapping by remapping path \
|
||||
to rust's source base directory. only meant for testing purposes"),
|
||||
report_delayed_bugs: bool = (false, parse_bool, [TRACKED],
|
||||
"immediately print bugs registered with `delay_span_bug` (default: no)"),
|
||||
sanitizer: SanitizerSet = (SanitizerSet::empty(), parse_sanitizers, [TRACKED],
|
||||
|
|
|
@ -23,8 +23,8 @@ use rustc_errors::registry::Registry;
|
|||
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId, ErrorReported};
|
||||
use rustc_lint_defs::FutureBreakage;
|
||||
pub use rustc_span::crate_disambiguator::CrateDisambiguator;
|
||||
use rustc_span::edition::Edition;
|
||||
use rustc_span::source_map::{FileLoader, MultiSpan, RealFileLoader, SourceMap, Span};
|
||||
use rustc_span::{edition::Edition, RealFileName};
|
||||
use rustc_span::{sym, SourceFileHashAlgorithm, Symbol};
|
||||
use rustc_target::asm::InlineAsmArch;
|
||||
use rustc_target::spec::{CodeModel, PanicStrategy, RelocModel, RelroLevel};
|
||||
|
@ -125,9 +125,8 @@ pub struct Session {
|
|||
/// The name of the root source file of the crate, in the local file system.
|
||||
/// `None` means that there is no source file.
|
||||
pub local_crate_source_file: Option<PathBuf>,
|
||||
/// The directory the compiler has been executed in plus a flag indicating
|
||||
/// if the value stored here has been affected by path remapping.
|
||||
pub working_dir: (PathBuf, bool),
|
||||
/// The directory the compiler has been executed in
|
||||
pub working_dir: RealFileName,
|
||||
|
||||
/// Set of `(DiagnosticId, Option<Span>, message)` tuples tracking
|
||||
/// (sub)diagnostics that have been set once, but should not be set again,
|
||||
|
@ -1356,7 +1355,12 @@ pub fn build_session(
|
|||
let working_dir = env::current_dir().unwrap_or_else(|e| {
|
||||
parse_sess.span_diagnostic.fatal(&format!("Current directory is invalid: {}", e)).raise()
|
||||
});
|
||||
let working_dir = file_path_mapping.map_prefix(working_dir);
|
||||
let (path, remapped) = file_path_mapping.map_prefix(working_dir.clone());
|
||||
let working_dir = if remapped {
|
||||
RealFileName::Remapped { local_path: Some(working_dir), virtual_name: path }
|
||||
} else {
|
||||
RealFileName::LocalPath(path)
|
||||
};
|
||||
|
||||
let cgu_reuse_tracker = if sopts.debugging_opts.query_dep_graph {
|
||||
CguReuseTracker::new()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue