Auto merge of #122450 - Urgau:simplify-trim-paths-feature, r=michaelwoerister
Simplify trim-paths feature by merging all debuginfo options together This PR simplifies the trim-paths feature by merging all debuginfo options together, as described in https://github.com/rust-lang/rust/issues/111540#issuecomment-1994010274. And also do some correctness fixes found during the review. cc `@weihanglo` r? `@michaelwoerister`
This commit is contained in:
commit
685927aae6
18 changed files with 142 additions and 184 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 {
|
||||||
|
@ -84,22 +84,18 @@ impl DebugContext {
|
||||||
|
|
||||||
let mut dwarf = DwarfUnit::new(encoding);
|
let mut dwarf = DwarfUnit::new(encoding);
|
||||||
|
|
||||||
let should_remap_filepaths = tcx.sess.should_prefer_remapped_for_codegen();
|
use rustc_session::config::RemapPathScopeComponents;
|
||||||
|
|
||||||
|
let filename_display_preference =
|
||||||
|
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
|
|
||||||
.to_string_lossy(if should_remap_filepaths {
|
|
||||||
FileNameDisplayPreference::Remapped
|
|
||||||
} else {
|
|
||||||
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.to_string_lossy().into_owned();
|
let name = path.to_string_lossy(filename_display_preference).to_string();
|
||||||
(name, None)
|
(name, None)
|
||||||
}
|
}
|
||||||
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),
|
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),
|
||||||
|
@ -156,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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,8 @@ use rustc_data_structures::small_c_str::SmallCStr;
|
||||||
use rustc_errors::{DiagCtxt, FatalError, Level};
|
use rustc_errors::{DiagCtxt, FatalError, Level};
|
||||||
use rustc_fs_util::{link_or_copy, path_to_c_string};
|
use rustc_fs_util::{link_or_copy, path_to_c_string};
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::config::{self, Lto, OutputType, Passes, SplitDwarfKind, SwitchWithOptPath};
|
use rustc_session::config::{self, Lto, OutputType, Passes};
|
||||||
|
use rustc_session::config::{RemapPathScopeComponents, SplitDwarfKind, SwitchWithOptPath};
|
||||||
use rustc_session::Session;
|
use rustc_session::Session;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::InnerSpan;
|
use rustc_span::InnerSpan;
|
||||||
|
@ -257,18 +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_for_split_debuginfo_paths =
|
let file_name_display_preference =
|
||||||
sess.should_prefer_remapped_for_split_debuginfo_paths();
|
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 = if should_prefer_remapped_for_split_debuginfo_paths {
|
let path = path_mapping
|
||||||
path_mapping.map_prefix(path).0
|
.to_real_filename(path)
|
||||||
} else {
|
.to_string_lossy(file_name_display_preference)
|
||||||
path.into()
|
.into_owned();
|
||||||
};
|
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);
|
||||||
|
|
|
@ -173,8 +173,14 @@ impl GlobalFileTable {
|
||||||
// Since rustc generates coverage maps with relative paths, the
|
// Since rustc generates coverage maps with relative paths, the
|
||||||
// compilation directory can be combined with the relative paths
|
// compilation directory can be combined with the relative paths
|
||||||
// to get absolute paths, if needed.
|
// to get absolute paths, if needed.
|
||||||
|
use rustc_session::config::RemapPathScopeComponents;
|
||||||
use rustc_session::RemapFileNameExt;
|
use rustc_session::RemapFileNameExt;
|
||||||
let working_dir: &str = &tcx.sess.opts.working_dir.for_codegen(tcx.sess).to_string_lossy();
|
let working_dir: &str = &tcx
|
||||||
|
.sess
|
||||||
|
.opts
|
||||||
|
.working_dir
|
||||||
|
.for_scope(tcx.sess, RemapPathScopeComponents::MACRO)
|
||||||
|
.to_string_lossy();
|
||||||
|
|
||||||
llvm::build_byte_buffer(|buffer| {
|
llvm::build_byte_buffer(|buffer| {
|
||||||
coverageinfo::write_filenames_section_to_buffer(
|
coverageinfo::write_filenames_section_to_buffer(
|
||||||
|
|
|
@ -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::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_for_codegen() {
|
if filename_display_preference == FileNameDisplayPreference::Remapped {
|
||||||
let filename = cx
|
let filename = cx
|
||||||
.sess()
|
.sess()
|
||||||
.source_map()
|
.source_map()
|
||||||
|
@ -623,7 +626,7 @@ pub fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) ->
|
||||||
}
|
}
|
||||||
other => {
|
other => {
|
||||||
debug!(?other);
|
debug!(?other);
|
||||||
("".into(), other.for_codegen(cx.sess()).to_string_lossy().into_owned())
|
("".into(), other.display(filename_display_preference).to_string())
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -832,9 +835,11 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
|
||||||
codegen_unit_name: &str,
|
codegen_unit_name: &str,
|
||||||
debug_context: &CodegenUnitDebugContext<'ll, 'tcx>,
|
debug_context: &CodegenUnitDebugContext<'ll, 'tcx>,
|
||||||
) -> &'ll DIDescriptor {
|
) -> &'ll DIDescriptor {
|
||||||
|
use rustc_session::{config::RemapPathScopeComponents, RemapFileNameExt};
|
||||||
let mut name_in_debuginfo = tcx
|
let mut name_in_debuginfo = tcx
|
||||||
.sess
|
.sess
|
||||||
.local_crate_source_file()
|
.local_crate_source_file()
|
||||||
|
.map(|src| src.for_scope(&tcx.sess, RemapPathScopeComponents::DEBUGINFO).to_path_buf())
|
||||||
.unwrap_or_else(|| PathBuf::from(tcx.crate_name(LOCAL_CRATE).as_str()));
|
.unwrap_or_else(|| PathBuf::from(tcx.crate_name(LOCAL_CRATE).as_str()));
|
||||||
|
|
||||||
// To avoid breaking split DWARF, we need to ensure that each codegen unit
|
// To avoid breaking split DWARF, we need to ensure that each codegen unit
|
||||||
|
@ -862,30 +867,29 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
|
||||||
// FIXME(#41252) Remove "clang LLVM" if we can get GDB and LLVM to play nice.
|
// FIXME(#41252) Remove "clang LLVM" if we can get GDB and LLVM to play nice.
|
||||||
let producer = format!("clang LLVM ({rustc_producer})");
|
let producer = format!("clang LLVM ({rustc_producer})");
|
||||||
|
|
||||||
use rustc_session::RemapFileNameExt;
|
|
||||||
let name_in_debuginfo = name_in_debuginfo.to_string_lossy();
|
let name_in_debuginfo = name_in_debuginfo.to_string_lossy();
|
||||||
let work_dir = tcx.sess.opts.working_dir.for_codegen(tcx.sess).to_string_lossy();
|
let work_dir = tcx
|
||||||
|
.sess
|
||||||
|
.opts
|
||||||
|
.working_dir
|
||||||
|
.for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO)
|
||||||
|
.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
|
Some(tcx.sess.source_map().path_mapping().to_real_filename(f))
|
||||||
.map(|f| {
|
|
||||||
if tcx.sess.should_prefer_remapped_for_split_debuginfo_paths() {
|
|
||||||
tcx.sess.source_map().path_mapping().map_prefix(f).0
|
|
||||||
} else {
|
|
||||||
f.into()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
};
|
||||||
.unwrap_or_default();
|
let split_name = split_name
|
||||||
let split_name = split_name.to_str().unwrap();
|
.as_ref()
|
||||||
|
.map(|f| f.for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO).to_string_lossy())
|
||||||
|
.unwrap_or_default();
|
||||||
let kind = DebugEmissionKind::from_generic(tcx.sess.opts.debuginfo);
|
let kind = DebugEmissionKind::from_generic(tcx.sess.opts.debuginfo);
|
||||||
|
|
||||||
let dwarf_version =
|
let dwarf_version =
|
||||||
|
|
|
@ -549,17 +549,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
||||||
|
|
||||||
match source_file.name {
|
match source_file.name {
|
||||||
FileName::Real(ref original_file_name) => {
|
FileName::Real(ref original_file_name) => {
|
||||||
let adapted_file_name = if self.tcx.sess.should_prefer_remapped_for_codegen() {
|
// FIXME: This should probably to conditionally remapped under
|
||||||
source_map.path_mapping().to_embeddable_absolute_path(
|
// a RemapPathScopeComponents but which one?
|
||||||
original_file_name.clone(),
|
let adapted_file_name = source_map
|
||||||
working_directory,
|
.path_mapping()
|
||||||
)
|
.to_embeddable_absolute_path(original_file_name.clone(), working_directory);
|
||||||
} else {
|
|
||||||
source_map.path_mapping().to_local_embeddable_absolute_path(
|
|
||||||
original_file_name.clone(),
|
|
||||||
working_directory,
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
adapted_source_file.name = FileName::Real(adapted_file_name);
|
adapted_source_file.name = FileName::Real(adapted_file_name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::fmt::{self, Debug, Display, Formatter};
|
use std::fmt::{self, Debug, Display, Formatter};
|
||||||
|
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_session::RemapFileNameExt;
|
use rustc_session::{config::RemapPathScopeComponents, RemapFileNameExt};
|
||||||
use rustc_span::{Span, DUMMY_SP};
|
use rustc_span::{Span, DUMMY_SP};
|
||||||
use rustc_target::abi::{HasDataLayout, Size};
|
use rustc_target::abi::{HasDataLayout, Size};
|
||||||
|
|
||||||
|
@ -516,7 +516,11 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
let caller = self.sess.source_map().lookup_char_pos(topmost.lo());
|
let caller = self.sess.source_map().lookup_char_pos(topmost.lo());
|
||||||
self.const_caller_location(
|
self.const_caller_location(
|
||||||
rustc_span::symbol::Symbol::intern(
|
rustc_span::symbol::Symbol::intern(
|
||||||
&caller.file.name.for_codegen(self.sess).to_string_lossy(),
|
&caller
|
||||||
|
.file
|
||||||
|
.name
|
||||||
|
.for_scope(self.sess, RemapPathScopeComponents::MACRO)
|
||||||
|
.to_string_lossy(),
|
||||||
),
|
),
|
||||||
caller.line as u32,
|
caller.line as u32,
|
||||||
caller.col_display as u32 + 1,
|
caller.col_display as u32 + 1,
|
||||||
|
|
|
@ -123,8 +123,11 @@ fn create_mappings<'tcx>(
|
||||||
let body_span = hir_info.body_span;
|
let body_span = hir_info.body_span;
|
||||||
|
|
||||||
let source_file = source_map.lookup_source_file(body_span.lo());
|
let source_file = source_map.lookup_source_file(body_span.lo());
|
||||||
use rustc_session::RemapFileNameExt;
|
|
||||||
let file_name = Symbol::intern(&source_file.name.for_codegen(tcx.sess).to_string_lossy());
|
use rustc_session::{config::RemapPathScopeComponents, RemapFileNameExt};
|
||||||
|
let file_name = Symbol::intern(
|
||||||
|
&source_file.name.for_scope(tcx.sess, RemapPathScopeComponents::MACRO).to_string_lossy(),
|
||||||
|
);
|
||||||
|
|
||||||
let term_for_bcb = |bcb| {
|
let term_for_bcb = |bcb| {
|
||||||
coverage_counters
|
coverage_counters
|
||||||
|
|
|
@ -7,6 +7,7 @@ use rustc_hir::{ItemId, Node, CRATE_HIR_ID};
|
||||||
use rustc_middle::query::Providers;
|
use rustc_middle::query::Providers;
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::config::{sigpipe, CrateType, EntryFnType};
|
use rustc_session::config::{sigpipe, CrateType, EntryFnType};
|
||||||
|
use rustc_session::{config::RemapPathScopeComponents, RemapFileNameExt};
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_span::{Span, Symbol};
|
use rustc_span::{Span, Symbol};
|
||||||
|
|
||||||
|
@ -165,10 +166,14 @@ fn no_main_err(tcx: TyCtxt<'_>, visitor: &EntryContext<'_>) {
|
||||||
|
|
||||||
// There is no main function.
|
// There is no main function.
|
||||||
let mut has_filename = true;
|
let mut has_filename = true;
|
||||||
let filename = tcx.sess.local_crate_source_file().unwrap_or_else(|| {
|
let filename = tcx
|
||||||
has_filename = false;
|
.sess
|
||||||
Default::default()
|
.local_crate_source_file()
|
||||||
});
|
.map(|src| src.for_scope(&tcx.sess, RemapPathScopeComponents::DIAGNOSTICS).to_path_buf())
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
has_filename = false;
|
||||||
|
Default::default()
|
||||||
|
});
|
||||||
let main_def_opt = tcx.resolutions(()).main_def;
|
let main_def_opt = tcx.resolutions(()).main_def;
|
||||||
let code = E0601;
|
let code = E0601;
|
||||||
let add_teach_note = tcx.sess.teach(code);
|
let add_teach_note = tcx.sess.teach(code);
|
||||||
|
|
|
@ -990,22 +990,12 @@ bitflags::bitflags! {
|
||||||
const MACRO = 1 << 0;
|
const MACRO = 1 << 0;
|
||||||
/// Apply remappings to printed compiler diagnostics
|
/// Apply remappings to printed compiler diagnostics
|
||||||
const DIAGNOSTICS = 1 << 1;
|
const DIAGNOSTICS = 1 << 1;
|
||||||
/// Apply remappings to debug information only when they are written to
|
/// Apply remappings to debug informations
|
||||||
/// compiled executables or libraries, but not when they are in split
|
const DEBUGINFO = 1 << 3;
|
||||||
/// debuginfo files
|
|
||||||
const UNSPLIT_DEBUGINFO = 1 << 2;
|
|
||||||
/// Apply remappings to debug information only when they are written to
|
|
||||||
/// split debug information files, but not in compiled executables or
|
|
||||||
/// libraries
|
|
||||||
const SPLIT_DEBUGINFO = 1 << 3;
|
|
||||||
/// Apply remappings to the paths pointing to split debug information
|
|
||||||
/// files. Does nothing when these files are not generated.
|
|
||||||
const SPLIT_DEBUGINFO_PATH = 1 << 4;
|
|
||||||
|
|
||||||
/// An alias for macro,unsplit-debuginfo,split-debuginfo-path. This
|
/// An alias for `macro` and `debuginfo`. This ensures all paths in compiled
|
||||||
/// ensures all paths in compiled executables or libraries are remapped
|
/// executables or libraries are remapped but not elsewhere.
|
||||||
/// but not elsewhere.
|
const OBJECT = Self::MACRO.bits() | Self::DEBUGINFO.bits();
|
||||||
const OBJECT = Self::MACRO.bits() | Self::UNSPLIT_DEBUGINFO.bits() | Self::SPLIT_DEBUGINFO_PATH.bits();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2852,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;
|
||||||
|
|
||||||
|
|
|
@ -433,7 +433,8 @@ mod desc {
|
||||||
"a `,` separated combination of `bti`, `b-key`, `pac-ret`, or `leaf`";
|
"a `,` separated combination of `bti`, `b-key`, `pac-ret`, or `leaf`";
|
||||||
pub const parse_proc_macro_execution_strategy: &str =
|
pub const parse_proc_macro_execution_strategy: &str =
|
||||||
"one of supported execution strategies (`same-thread`, or `cross-thread`)";
|
"one of supported execution strategies (`same-thread`, or `cross-thread`)";
|
||||||
pub const parse_remap_path_scope: &str = "comma separated list of scopes: `macro`, `diagnostics`, `unsplit-debuginfo`, `split-debuginfo`, `split-debuginfo-path`, `object`, `all`";
|
pub const parse_remap_path_scope: &str =
|
||||||
|
"comma separated list of scopes: `macro`, `diagnostics`, `debuginfo`, `object`, `all`";
|
||||||
pub const parse_inlining_threshold: &str =
|
pub const parse_inlining_threshold: &str =
|
||||||
"either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number";
|
"either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number";
|
||||||
pub const parse_llvm_module_flag: &str = "<key>:<type>:<value>:<behavior>. Type must currently be `u32`. Behavior should be one of (`error`, `warning`, `require`, `override`, `append`, `appendunique`, `max`, `min`)";
|
pub const parse_llvm_module_flag: &str = "<key>:<type>:<value>:<behavior>. Type must currently be `u32`. Behavior should be one of (`error`, `warning`, `require`, `override`, `append`, `appendunique`, `max`, `min`)";
|
||||||
|
@ -1156,9 +1157,7 @@ mod parse {
|
||||||
*slot |= match s {
|
*slot |= match s {
|
||||||
"macro" => RemapPathScopeComponents::MACRO,
|
"macro" => RemapPathScopeComponents::MACRO,
|
||||||
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
|
"diagnostics" => RemapPathScopeComponents::DIAGNOSTICS,
|
||||||
"unsplit-debuginfo" => RemapPathScopeComponents::UNSPLIT_DEBUGINFO,
|
"debuginfo" => RemapPathScopeComponents::DEBUGINFO,
|
||||||
"split-debuginfo" => RemapPathScopeComponents::SPLIT_DEBUGINFO,
|
|
||||||
"split-debuginfo-path" => RemapPathScopeComponents::SPLIT_DEBUGINFO_PATH,
|
|
||||||
"object" => RemapPathScopeComponents::OBJECT,
|
"object" => RemapPathScopeComponents::OBJECT,
|
||||||
"all" => RemapPathScopeComponents::all(),
|
"all" => RemapPathScopeComponents::all(),
|
||||||
_ => return false,
|
_ => return false,
|
||||||
|
|
|
@ -29,6 +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::{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};
|
||||||
|
@ -250,13 +251,8 @@ impl Session {
|
||||||
self.miri_unleashed_features.lock().push((span, feature_gate));
|
self.miri_unleashed_features.lock().push((span, feature_gate));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn local_crate_source_file(&self) -> Option<PathBuf> {
|
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()?))
|
||||||
if self.should_prefer_remapped_for_codegen() {
|
|
||||||
Some(self.opts.file_path_mapping().map_prefix(path).0.into_owned())
|
|
||||||
} else {
|
|
||||||
Some(path.to_path_buf())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_miri_unleashed_features(&self) -> Option<ErrorGuaranteed> {
|
fn check_miri_unleashed_features(&self) -> Option<ErrorGuaranteed> {
|
||||||
|
@ -886,38 +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_for_codegen(&self) -> bool {
|
pub fn filename_display_preference(
|
||||||
let has_split_debuginfo = match self.split_debuginfo() {
|
&self,
|
||||||
SplitDebuginfo::Off => false,
|
scope: RemapPathScopeComponents,
|
||||||
SplitDebuginfo::Packed => true,
|
) -> FileNameDisplayPreference {
|
||||||
SplitDebuginfo::Unpacked => true,
|
assert!(
|
||||||
};
|
scope.bits().count_ones() == 1,
|
||||||
|
"one and only one scope should be passed to `Session::filename_display_preference`"
|
||||||
let remap_path_scopes = &self.opts.unstable_opts.remap_path_scope;
|
);
|
||||||
let mut prefer_remapped = false;
|
if self.opts.unstable_opts.remap_path_scope.contains(scope) {
|
||||||
|
FileNameDisplayPreference::Remapped
|
||||||
if remap_path_scopes.contains(RemapPathScopeComponents::UNSPLIT_DEBUGINFO) {
|
} else {
|
||||||
prefer_remapped |= !has_split_debuginfo;
|
FileNameDisplayPreference::Local
|
||||||
}
|
}
|
||||||
|
|
||||||
if remap_path_scopes.contains(RemapPathScopeComponents::SPLIT_DEBUGINFO) {
|
|
||||||
prefer_remapped |= has_split_debuginfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
prefer_remapped
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn should_prefer_remapped_for_split_debuginfo_paths(&self) -> bool {
|
|
||||||
let has_split_debuginfo = match self.split_debuginfo() {
|
|
||||||
SplitDebuginfo::Off => false,
|
|
||||||
SplitDebuginfo::Packed | SplitDebuginfo::Unpacked => true,
|
|
||||||
};
|
|
||||||
|
|
||||||
self.opts
|
|
||||||
.unstable_opts
|
|
||||||
.remap_path_scope
|
|
||||||
.contains(RemapPathScopeComponents::SPLIT_DEBUGINFO_PATH)
|
|
||||||
&& has_split_debuginfo
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1469,12 +1446,8 @@ pub trait RemapFileNameExt {
|
||||||
|
|
||||||
/// Returns a possibly remapped filename based on the passed scope and remap cli options.
|
/// Returns a possibly remapped filename based on the passed scope and remap cli options.
|
||||||
///
|
///
|
||||||
/// One and only one scope should be passed to this method. For anything related to
|
/// One and only one scope should be passed to this method, it will panic otherwise.
|
||||||
/// "codegen" see the [`RemapFileNameExt::for_codegen`] method.
|
|
||||||
fn for_scope(&self, sess: &Session, scope: RemapPathScopeComponents) -> Self::Output<'_>;
|
fn for_scope(&self, sess: &Session, scope: RemapPathScopeComponents) -> Self::Output<'_>;
|
||||||
|
|
||||||
/// Return a possibly remapped filename, to be used in "codegen" related parts.
|
|
||||||
fn for_codegen(&self, sess: &Session) -> Self::Output<'_>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RemapFileNameExt for rustc_span::FileName {
|
impl RemapFileNameExt for rustc_span::FileName {
|
||||||
|
@ -1491,14 +1464,6 @@ impl RemapFileNameExt for rustc_span::FileName {
|
||||||
self.prefer_local()
|
self.prefer_local()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn for_codegen(&self, sess: &Session) -> Self::Output<'_> {
|
|
||||||
if sess.should_prefer_remapped_for_codegen() {
|
|
||||||
self.prefer_remapped_unconditionaly()
|
|
||||||
} else {
|
|
||||||
self.prefer_local()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RemapFileNameExt for rustc_span::RealFileName {
|
impl RemapFileNameExt for rustc_span::RealFileName {
|
||||||
|
@ -1515,12 +1480,4 @@ impl RemapFileNameExt for rustc_span::RealFileName {
|
||||||
self.local_path_if_available()
|
self.local_path_if_available()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn for_codegen(&self, sess: &Session) -> Self::Output<'_> {
|
|
||||||
if sess.should_prefer_remapped_for_codegen() {
|
|
||||||
self.remapped_path_if_available()
|
|
||||||
} else {
|
|
||||||
self.local_path_if_available()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(),
|
||||||
|
|
|
@ -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).
|
||||||
///
|
///
|
||||||
|
|
|
@ -10,11 +10,9 @@ This flag accepts a comma-separated list of values and may be specified multiple
|
||||||
|
|
||||||
- `macro` - apply remappings to the expansion of `std::file!()` macro. This is where paths in embedded panic messages come from
|
- `macro` - apply remappings to the expansion of `std::file!()` macro. This is where paths in embedded panic messages come from
|
||||||
- `diagnostics` - apply remappings to printed compiler diagnostics
|
- `diagnostics` - apply remappings to printed compiler diagnostics
|
||||||
- `unsplit-debuginfo` - apply remappings to debug information only when they are written to compiled executables or libraries, but not when they are in split debuginfo files
|
- `debuginfo` - apply remappings to debug informations
|
||||||
- `split-debuginfo` - apply remappings to debug information only when they are written to split debug information files, but not in compiled executables or libraries
|
- `object` - apply remappings to all paths in compiled executables or libraries, but not elsewhere. Currently an alias for `macro,debuginfo`.
|
||||||
- `split-debuginfo-path` - apply remappings to the paths pointing to split debug information files. Does nothing when these files are not generated.
|
- `all` - an alias for all of the above, also equivalent to supplying only `--remap-path-prefix` without `--remap-path-scope`.
|
||||||
- `object` - an alias for `macro,unsplit-debuginfo,split-debuginfo-path`. This ensures all paths in compiled executables or libraries are remapped, but not elsewhere.
|
|
||||||
- `all` and `true` - an alias for all of the above, also equivalent to supplying only `--remap-path-prefix` without `--remap-path-scope`.
|
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
```sh
|
```sh
|
||||||
|
|
|
@ -2506,7 +2506,7 @@ fn render_call_locations<W: fmt::Write>(mut w: W, cx: &mut Context<'_>, item: &c
|
||||||
// Look for the example file in the source map if it exists, otherwise return a dummy span
|
// Look for the example file in the source map if it exists, otherwise return a dummy span
|
||||||
let file_span = (|| {
|
let file_span = (|| {
|
||||||
let source_map = tcx.sess.source_map();
|
let source_map = tcx.sess.source_map();
|
||||||
let crate_src = tcx.sess.local_crate_source_file()?;
|
let crate_src = tcx.sess.local_crate_source_file()?.into_local_path()?;
|
||||||
let abs_crate_src = crate_src.canonicalize().ok()?;
|
let abs_crate_src = crate_src.canonicalize().ok()?;
|
||||||
let crate_root = abs_crate_src.parent()?.parent()?;
|
let crate_root = abs_crate_src.parent()?.parent()?;
|
||||||
let rel_path = path.strip_prefix(crate_root).ok()?;
|
let rel_path = path.strip_prefix(crate_root).ok()?;
|
||||||
|
|
|
@ -21,19 +21,10 @@ remap-with-scope:
|
||||||
grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
|
grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
|
||||||
! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
|
! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
|
||||||
|
|
||||||
$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=diagnostics $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs
|
$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=macro $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs
|
||||||
! grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
|
grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
|
||||||
grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
|
! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
|
||||||
|
|
||||||
$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=diagnostics,object $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs
|
$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=diagnostics,object $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs
|
||||||
grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
|
grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
|
||||||
! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
|
! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
|
||||||
|
|
||||||
$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=split-debuginfo $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs
|
|
||||||
! grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
|
|
||||||
grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
|
|
||||||
|
|
||||||
# FIXME: We should test the split debuginfo files, but we don't currently a good infra for that
|
|
||||||
$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=split-debuginfo -Zunstable-options -Csplit-debuginfo=packed --crate-type=lib --emit=metadata auxiliary/lib.rs
|
|
||||||
grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
|
|
||||||
! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ packed-remapped-single:
|
||||||
packed-remapped-scope:
|
packed-remapped-scope:
|
||||||
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=packed -C debuginfo=2 \
|
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=packed -C debuginfo=2 \
|
||||||
-Z split-dwarf-kind=single --remap-path-prefix $(TMPDIR)=/a \
|
-Z split-dwarf-kind=single --remap-path-prefix $(TMPDIR)=/a \
|
||||||
-Z remap-path-scope=split-debuginfo-path foo.rs -g
|
-Z remap-path-scope=debuginfo foo.rs -g
|
||||||
objdump -Wi $(TMPDIR)/foo | grep DW_AT_GNU_dwo_name | (! grep $(TMPDIR)) || exit 1
|
objdump -Wi $(TMPDIR)/foo | grep DW_AT_GNU_dwo_name | (! grep $(TMPDIR)) || exit 1
|
||||||
ls $(TMPDIR)/*.o && exit 1 || exit 0
|
ls $(TMPDIR)/*.o && exit 1 || exit 0
|
||||||
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
|
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
|
||||||
|
@ -298,7 +298,7 @@ unpacked-remapped-single:
|
||||||
unpacked-remapped-scope:
|
unpacked-remapped-scope:
|
||||||
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=unpacked -C debuginfo=2 \
|
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=unpacked -C debuginfo=2 \
|
||||||
-Z split-dwarf-kind=single --remap-path-prefix $(TMPDIR)=/a \
|
-Z split-dwarf-kind=single --remap-path-prefix $(TMPDIR)=/a \
|
||||||
-Z remap-path-scope=split-debuginfo-path foo.rs -g
|
-Z remap-path-scope=debuginfo foo.rs -g
|
||||||
objdump -Wi $(TMPDIR)/foo | grep DW_AT_GNU_dwo_name | (! grep $(TMPDIR)) || exit 1
|
objdump -Wi $(TMPDIR)/foo | grep DW_AT_GNU_dwo_name | (! grep $(TMPDIR)) || exit 1
|
||||||
rm $(TMPDIR)/*.o
|
rm $(TMPDIR)/*.o
|
||||||
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
|
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue