Replace RemapFileNameExt::for_codegen
with explicit calls
This commit is contained in:
parent
777c6b46cc
commit
106146fd95
9 changed files with 55 additions and 52 deletions
|
@ -84,7 +84,9 @@ 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 should_remap_filepaths =
|
||||||
|
tcx.sess.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO);
|
||||||
|
|
||||||
let producer = producer(tcx.sess);
|
let producer = producer(tcx.sess);
|
||||||
let comp_dir = tcx
|
let comp_dir = tcx
|
||||||
|
|
|
@ -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,7 +258,8 @@ pub fn target_machine_factory(
|
||||||
};
|
};
|
||||||
let debuginfo_compression = SmallCStr::new(&debuginfo_compression);
|
let debuginfo_compression = SmallCStr::new(&debuginfo_compression);
|
||||||
|
|
||||||
let should_prefer_remapped_paths = sess.should_prefer_remapped_for_codegen();
|
let should_prefer_remapped_paths =
|
||||||
|
sess.should_prefer_remapped(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 {
|
||||||
|
|
|
@ -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,13 @@ 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;
|
use rustc_session::{config::RemapPathScopeComponents, RemapFileNameExt};
|
||||||
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 cx.sess().should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO) {
|
||||||
let filename = cx
|
let filename = cx
|
||||||
.sess()
|
.sess()
|
||||||
.source_map()
|
.source_map()
|
||||||
|
@ -623,7 +623,13 @@ 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
|
||||||
|
.for_scope(cx.sess(), RemapPathScopeComponents::DEBUGINFO)
|
||||||
|
.to_string_lossy()
|
||||||
|
.into_owned(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -862,9 +868,14 @@ 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;
|
use rustc_session::{config::RemapPathScopeComponents, 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
|
output_filenames
|
||||||
|
@ -875,7 +886,7 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
|
||||||
)
|
)
|
||||||
// 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| {
|
.map(|f| {
|
||||||
if tcx.sess.should_prefer_remapped_for_codegen() {
|
if tcx.sess.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO) {
|
||||||
tcx.sess.source_map().path_mapping().map_prefix(f).0
|
tcx.sess.source_map().path_mapping().map_prefix(f).0
|
||||||
} else {
|
} else {
|
||||||
f.into()
|
f.into()
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -252,7 +252,8 @@ impl Session {
|
||||||
|
|
||||||
pub fn local_crate_source_file(&self) -> Option<PathBuf> {
|
pub fn local_crate_source_file(&self) -> Option<PathBuf> {
|
||||||
let path = self.io.input.opt_path()?;
|
let path = self.io.input.opt_path()?;
|
||||||
if self.should_prefer_remapped_for_codegen() {
|
// FIXME: The remap path scope should probably not be hardcoded.
|
||||||
|
if self.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO) {
|
||||||
Some(self.opts.file_path_mapping().map_prefix(path).0.into_owned())
|
Some(self.opts.file_path_mapping().map_prefix(path).0.into_owned())
|
||||||
} else {
|
} else {
|
||||||
Some(path.to_path_buf())
|
Some(path.to_path_buf())
|
||||||
|
@ -886,8 +887,8 @@ 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 should_prefer_remapped(&self, scope: RemapPathScopeComponents) -> bool {
|
||||||
self.opts.unstable_opts.remap_path_scope.contains(RemapPathScopeComponents::DEBUGINFO)
|
self.opts.unstable_opts.remap_path_scope.contains(scope)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1439,12 +1440,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 {
|
||||||
|
@ -1461,14 +1458,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 {
|
||||||
|
@ -1485,12 +1474,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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,9 @@ 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue