Replace Session should_remap_filepaths with filename_display_preference
This commit is contained in:
parent
4f4fa42b0e
commit
fefb8f1f9c
6 changed files with 48 additions and 50 deletions
|
@ -89,11 +89,7 @@ impl DebugContext {
|
||||||
match &source_file.name {
|
match &source_file.name {
|
||||||
FileName::Real(path) => {
|
FileName::Real(path) => {
|
||||||
let (dir_path, file_name) =
|
let (dir_path, file_name) =
|
||||||
split_path_dir_and_file(if self.should_remap_filepaths {
|
split_path_dir_and_file(path.to_path(self.filename_display_preference));
|
||||||
path.remapped_path_if_available()
|
|
||||||
} else {
|
|
||||||
path.local_path_if_available()
|
|
||||||
});
|
|
||||||
let dir_name = osstr_as_utf8_bytes(dir_path.as_os_str());
|
let dir_name = osstr_as_utf8_bytes(dir_path.as_os_str());
|
||||||
let file_name = osstr_as_utf8_bytes(file_name);
|
let file_name = osstr_as_utf8_bytes(file_name);
|
||||||
|
|
||||||
|
@ -115,14 +111,7 @@ impl DebugContext {
|
||||||
filename => {
|
filename => {
|
||||||
let dir_id = line_program.default_directory();
|
let dir_id = line_program.default_directory();
|
||||||
let dummy_file_name = LineString::new(
|
let dummy_file_name = LineString::new(
|
||||||
filename
|
filename.display(self.filename_display_preference).to_string().into_bytes(),
|
||||||
.display(if self.should_remap_filepaths {
|
|
||||||
FileNameDisplayPreference::Remapped
|
|
||||||
} else {
|
|
||||||
FileNameDisplayPreference::Local
|
|
||||||
})
|
|
||||||
.to_string()
|
|
||||||
.into_bytes(),
|
|
||||||
line_program.encoding(),
|
line_program.encoding(),
|
||||||
line_strings,
|
line_strings,
|
||||||
);
|
);
|
||||||
|
|
|
@ -42,7 +42,7 @@ pub(crate) struct DebugContext {
|
||||||
namespace_map: DefIdMap<UnitEntryId>,
|
namespace_map: DefIdMap<UnitEntryId>,
|
||||||
array_size_type: UnitEntryId,
|
array_size_type: UnitEntryId,
|
||||||
|
|
||||||
should_remap_filepaths: bool,
|
filename_display_preference: FileNameDisplayPreference,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct FunctionDebugContext {
|
pub(crate) struct FunctionDebugContext {
|
||||||
|
@ -85,26 +85,17 @@ 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 filename_display_preference =
|
||||||
tcx.sess.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO);
|
tcx.sess.filename_display_preference(RemapPathScopeComponents::DEBUGINFO);
|
||||||
|
|
||||||
let producer = producer(tcx.sess);
|
let producer = producer(tcx.sess);
|
||||||
let comp_dir = tcx
|
let comp_dir =
|
||||||
.sess
|
tcx.sess.opts.working_dir.to_string_lossy(filename_display_preference).to_string();
|
||||||
.opts
|
|
||||||
.working_dir
|
|
||||||
.for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO)
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
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(filename_display_preference).to_string();
|
||||||
.for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO)
|
|
||||||
.to_string_lossy()
|
|
||||||
.to_string();
|
|
||||||
(name, None)
|
(name, None)
|
||||||
}
|
}
|
||||||
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),
|
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),
|
||||||
|
@ -161,7 +152,7 @@ impl DebugContext {
|
||||||
stack_pointer_register,
|
stack_pointer_register,
|
||||||
namespace_map: DefIdMap::default(),
|
namespace_map: DefIdMap::default(),
|
||||||
array_size_type,
|
array_size_type,
|
||||||
should_remap_filepaths,
|
filename_display_preference,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -258,19 +258,17 @@ pub fn target_machine_factory(
|
||||||
};
|
};
|
||||||
let debuginfo_compression = SmallCStr::new(&debuginfo_compression);
|
let debuginfo_compression = SmallCStr::new(&debuginfo_compression);
|
||||||
|
|
||||||
let should_prefer_remapped_paths =
|
let file_name_display_preference =
|
||||||
sess.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO);
|
sess.filename_display_preference(RemapPathScopeComponents::DEBUGINFO);
|
||||||
|
|
||||||
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 = path_mapping
|
||||||
let path = if should_prefer_remapped_paths {
|
.to_real_filename(path)
|
||||||
path.remapped_path_if_available()
|
.to_string_lossy(file_name_display_preference)
|
||||||
} else {
|
.into_owned();
|
||||||
path.local_path_if_available()
|
CString::new(path).unwrap()
|
||||||
};
|
|
||||||
CString::new(path.to_str().unwrap()).unwrap()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let split_dwarf_file = path_to_cstring_helper(config.split_dwarf_file);
|
let split_dwarf_file = path_to_cstring_helper(config.split_dwarf_file);
|
||||||
|
|
|
@ -554,13 +554,16 @@ pub fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) ->
|
||||||
) -> &'ll DIFile {
|
) -> &'ll DIFile {
|
||||||
debug!(?source_file.name);
|
debug!(?source_file.name);
|
||||||
|
|
||||||
use rustc_session::{config::RemapPathScopeComponents, RemapFileNameExt};
|
let filename_display_preference =
|
||||||
|
cx.sess().filename_display_preference(RemapPathScopeComponents::DEBUGINFO);
|
||||||
|
|
||||||
|
use rustc_session::config::RemapPathScopeComponents;
|
||||||
let (directory, file_name) = match &source_file.name {
|
let (directory, file_name) = match &source_file.name {
|
||||||
FileName::Real(filename) => {
|
FileName::Real(filename) => {
|
||||||
let working_directory = &cx.sess().opts.working_dir;
|
let working_directory = &cx.sess().opts.working_dir;
|
||||||
debug!(?working_directory);
|
debug!(?working_directory);
|
||||||
|
|
||||||
if cx.sess().should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO) {
|
if filename_display_preference == FileNameDisplayPreference::Remapped {
|
||||||
let filename = cx
|
let filename = cx
|
||||||
.sess()
|
.sess()
|
||||||
.source_map()
|
.source_map()
|
||||||
|
@ -623,13 +626,7 @@ pub fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) ->
|
||||||
}
|
}
|
||||||
other => {
|
other => {
|
||||||
debug!(?other);
|
debug!(?other);
|
||||||
(
|
("".into(), other.display(filename_display_preference).to_string())
|
||||||
"".into(),
|
|
||||||
other
|
|
||||||
.for_scope(cx.sess(), RemapPathScopeComponents::DEBUGINFO)
|
|
||||||
.to_string_lossy()
|
|
||||||
.into_owned(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ use rustc_macros::HashStable_Generic;
|
||||||
pub use rustc_span::def_id::StableCrateId;
|
pub use rustc_span::def_id::StableCrateId;
|
||||||
use rustc_span::edition::Edition;
|
use rustc_span::edition::Edition;
|
||||||
use rustc_span::source_map::{FileLoader, FilePathMapping, RealFileLoader, SourceMap};
|
use rustc_span::source_map::{FileLoader, FilePathMapping, RealFileLoader, SourceMap};
|
||||||
use rustc_span::RealFileName;
|
use rustc_span::{FileNameDisplayPreference, RealFileName};
|
||||||
use rustc_span::{SourceFileHashAlgorithm, Span, Symbol};
|
use rustc_span::{SourceFileHashAlgorithm, Span, Symbol};
|
||||||
use rustc_target::asm::InlineAsmArch;
|
use rustc_target::asm::InlineAsmArch;
|
||||||
use rustc_target::spec::{CodeModel, PanicStrategy, RelocModel, RelroLevel};
|
use rustc_target::spec::{CodeModel, PanicStrategy, RelocModel, RelroLevel};
|
||||||
|
@ -882,8 +882,19 @@ impl Session {
|
||||||
self.opts.cg.link_dead_code.unwrap_or(false)
|
self.opts.cg.link_dead_code.unwrap_or(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn should_prefer_remapped(&self, scope: RemapPathScopeComponents) -> bool {
|
pub fn filename_display_preference(
|
||||||
self.opts.unstable_opts.remap_path_scope.contains(scope)
|
&self,
|
||||||
|
scope: RemapPathScopeComponents,
|
||||||
|
) -> FileNameDisplayPreference {
|
||||||
|
assert!(
|
||||||
|
scope.bits().count_ones() == 1,
|
||||||
|
"one and only one scope should be passed to `Session::filename_display_preference`"
|
||||||
|
);
|
||||||
|
if self.opts.unstable_opts.remap_path_scope.contains(scope) {
|
||||||
|
FileNameDisplayPreference::Remapped
|
||||||
|
} else {
|
||||||
|
FileNameDisplayPreference::Local
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -271,6 +271,18 @@ impl RealFileName {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the path remmapped or not depending on the [`FileNameDisplayPreference`].
|
||||||
|
///
|
||||||
|
/// For the purpose of this function, local and short preference are equal.
|
||||||
|
pub fn to_path(&self, display_pref: FileNameDisplayPreference) -> &Path {
|
||||||
|
match display_pref {
|
||||||
|
FileNameDisplayPreference::Local | FileNameDisplayPreference::Short => {
|
||||||
|
self.local_path_if_available()
|
||||||
|
}
|
||||||
|
FileNameDisplayPreference::Remapped => self.remapped_path_if_available(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn to_string_lossy(&self, display_pref: FileNameDisplayPreference) -> Cow<'_, str> {
|
pub fn to_string_lossy(&self, display_pref: FileNameDisplayPreference) -> Cow<'_, str> {
|
||||||
match display_pref {
|
match display_pref {
|
||||||
FileNameDisplayPreference::Local => self.local_path_if_available().to_string_lossy(),
|
FileNameDisplayPreference::Local => self.local_path_if_available().to_string_lossy(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue