Introduce FileNameMapping::to_real_filename
and use it everywhere
This commit is contained in:
parent
ee2898d3f1
commit
4f4fa42b0e
6 changed files with 42 additions and 41 deletions
|
@ -85,6 +85,8 @@ impl DebugContext {
|
||||||
let mut dwarf = DwarfUnit::new(encoding);
|
let mut dwarf = DwarfUnit::new(encoding);
|
||||||
|
|
||||||
use rustc_session::config::RemapPathScopeComponents;
|
use rustc_session::config::RemapPathScopeComponents;
|
||||||
|
use rustc_session::RemapFileNameExt;
|
||||||
|
|
||||||
let should_remap_filepaths =
|
let should_remap_filepaths =
|
||||||
tcx.sess.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO);
|
tcx.sess.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO);
|
||||||
|
|
||||||
|
@ -93,22 +95,16 @@ impl DebugContext {
|
||||||
.sess
|
.sess
|
||||||
.opts
|
.opts
|
||||||
.working_dir
|
.working_dir
|
||||||
.to_string_lossy(if should_remap_filepaths {
|
.for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO)
|
||||||
FileNameDisplayPreference::Remapped
|
.to_string_lossy()
|
||||||
} else {
|
.to_string();
|
||||||
FileNameDisplayPreference::Local
|
|
||||||
})
|
|
||||||
.into_owned();
|
|
||||||
|
|
||||||
let (name, file_info) = match tcx.sess.local_crate_source_file() {
|
let (name, file_info) = match tcx.sess.local_crate_source_file() {
|
||||||
Some(path) => {
|
Some(path) => {
|
||||||
let name = path
|
let name = path
|
||||||
.to_string_lossy(if should_remap_filepaths {
|
.for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO)
|
||||||
FileNameDisplayPreference::Remapped
|
.to_string_lossy()
|
||||||
} else {
|
.to_string();
|
||||||
FileNameDisplayPreference::Local
|
|
||||||
})
|
|
||||||
.into_owned();
|
|
||||||
(name, None)
|
(name, None)
|
||||||
}
|
}
|
||||||
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),
|
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),
|
||||||
|
|
|
@ -264,10 +264,11 @@ pub fn target_machine_factory(
|
||||||
Arc::new(move |config: TargetMachineFactoryConfig| {
|
Arc::new(move |config: TargetMachineFactoryConfig| {
|
||||||
let path_to_cstring_helper = |path: Option<PathBuf>| -> CString {
|
let path_to_cstring_helper = |path: Option<PathBuf>| -> CString {
|
||||||
let path = path.unwrap_or_default();
|
let path = path.unwrap_or_default();
|
||||||
|
let path = path_mapping.to_real_filename(path);
|
||||||
let path = if should_prefer_remapped_paths {
|
let path = if should_prefer_remapped_paths {
|
||||||
path_mapping.map_prefix(path).0
|
path.remapped_path_if_available()
|
||||||
} else {
|
} else {
|
||||||
path.into()
|
path.local_path_if_available()
|
||||||
};
|
};
|
||||||
CString::new(path.to_str().unwrap()).unwrap()
|
CString::new(path.to_str().unwrap()).unwrap()
|
||||||
};
|
};
|
||||||
|
|
|
@ -878,26 +878,21 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
|
||||||
.for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO)
|
.for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO)
|
||||||
.to_string_lossy();
|
.to_string_lossy();
|
||||||
let output_filenames = tcx.output_filenames(());
|
let output_filenames = tcx.output_filenames(());
|
||||||
let split_name = if tcx.sess.target_can_use_split_dwarf() {
|
let split_name = if tcx.sess.target_can_use_split_dwarf()
|
||||||
output_filenames
|
&& let Some(f) = output_filenames.split_dwarf_path(
|
||||||
.split_dwarf_path(
|
|
||||||
tcx.sess.split_debuginfo(),
|
tcx.sess.split_debuginfo(),
|
||||||
tcx.sess.opts.unstable_opts.split_dwarf_kind,
|
tcx.sess.opts.unstable_opts.split_dwarf_kind,
|
||||||
Some(codegen_unit_name),
|
Some(codegen_unit_name),
|
||||||
)
|
) {
|
||||||
// We get a path relative to the working directory from split_dwarf_path
|
// We get a path relative to the working directory from split_dwarf_path
|
||||||
.map(|f| {
|
Some(tcx.sess.source_map().path_mapping().to_real_filename(f))
|
||||||
if tcx.sess.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO) {
|
|
||||||
tcx.sess.source_map().path_mapping().map_prefix(f).0
|
|
||||||
} else {
|
|
||||||
f.into()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
};
|
||||||
|
let split_name = split_name
|
||||||
|
.as_ref()
|
||||||
|
.map(|f| f.for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO).to_string_lossy())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let split_name = split_name.to_str().unwrap();
|
|
||||||
let kind = DebugEmissionKind::from_generic(tcx.sess.opts.debuginfo);
|
let kind = DebugEmissionKind::from_generic(tcx.sess.opts.debuginfo);
|
||||||
|
|
||||||
let dwarf_version =
|
let dwarf_version =
|
||||||
|
|
|
@ -2842,13 +2842,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
|
||||||
early_dcx.early_fatal(format!("Current directory is invalid: {e}"));
|
early_dcx.early_fatal(format!("Current directory is invalid: {e}"));
|
||||||
});
|
});
|
||||||
|
|
||||||
let remap = file_path_mapping(remap_path_prefix.clone(), &unstable_opts);
|
let file_mapping = file_path_mapping(remap_path_prefix.clone(), &unstable_opts);
|
||||||
let (path, remapped) = remap.map_prefix(&working_dir);
|
let working_dir = file_mapping.to_real_filename(&working_dir);
|
||||||
let working_dir = if remapped {
|
|
||||||
RealFileName::Remapped { virtual_name: path.into_owned(), local_path: Some(working_dir) }
|
|
||||||
} else {
|
|
||||||
RealFileName::LocalPath(path.into_owned())
|
|
||||||
};
|
|
||||||
|
|
||||||
let verbose = matches.opt_present("verbose") || unstable_opts.verbose_internals;
|
let verbose = matches.opt_present("verbose") || unstable_opts.verbose_internals;
|
||||||
|
|
||||||
|
|
|
@ -252,8 +252,7 @@ impl Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn local_crate_source_file(&self) -> Option<RealFileName> {
|
pub fn local_crate_source_file(&self) -> Option<RealFileName> {
|
||||||
let path = self.io.input.opt_path()?;
|
Some(self.source_map().path_mapping().to_real_filename(self.io.input.opt_path()?))
|
||||||
Some(RealFileName::LocalPath(path.to_path_buf()))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_miri_unleashed_features(&self) -> Option<ErrorGuaranteed> {
|
fn check_miri_unleashed_features(&self) -> Option<ErrorGuaranteed> {
|
||||||
|
|
|
@ -1129,6 +1129,21 @@ impl FilePathMapping {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Applies any path prefix substitution as defined by the mapping.
|
||||||
|
/// The return value is the local path with a "virtual path" representing the remapped
|
||||||
|
/// part if any remapping was performed.
|
||||||
|
pub fn to_real_filename<'a>(&self, local_path: impl Into<Cow<'a, Path>>) -> RealFileName {
|
||||||
|
let local_path = local_path.into();
|
||||||
|
if let (remapped_path, true) = self.map_prefix(&*local_path) {
|
||||||
|
RealFileName::Remapped {
|
||||||
|
virtual_name: remapped_path.into_owned(),
|
||||||
|
local_path: Some(local_path.into_owned()),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
RealFileName::LocalPath(local_path.into_owned())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Expand a relative path to an absolute path with remapping taken into account.
|
/// Expand a relative path to an absolute path with remapping taken into account.
|
||||||
/// Use this when absolute paths are required (e.g. debuginfo or crate metadata).
|
/// Use this when absolute paths are required (e.g. debuginfo or crate metadata).
|
||||||
///
|
///
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue