-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
give rustc_driver users a chance to overwrite the default sysroot #122993
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ use rustc_span::{BytePos, Pos, SpanData, SpanDecoder, SyntaxContext, DUMMY_SP}; | |
|
||
use proc_macro::bridge::client::ProcMacro; | ||
use std::iter::TrustedLen; | ||
use std::path::Path; | ||
use std::path::{Path, PathBuf}; | ||
use std::{io, iter, mem}; | ||
|
||
pub(super) use cstore_impl::provide; | ||
|
@@ -1589,10 +1589,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { | |
/// Proc macro crates don't currently export spans, so this function does not have | ||
/// to work for them. | ||
fn imported_source_file(self, source_file_index: u32, sess: &Session) -> ImportedSourceFile { | ||
fn filter<'a>(sess: &Session, path: Option<&'a Path>) -> Option<&'a Path> { | ||
fn filter<'a>( | ||
sess: &Session, | ||
real_rust_source_base_dir: &Option<PathBuf>, | ||
path: Option<&'a Path>, | ||
) -> Option<&'a Path> { | ||
path.filter(|_| { | ||
// Only spend time on further checks if we have what to translate *to*. | ||
sess.opts.real_rust_source_base_dir.is_some() | ||
real_rust_source_base_dir.is_some() | ||
// Some tests need the translation to be always skipped. | ||
&& sess.opts.unstable_opts.translate_remapped_path_to_local_path | ||
}) | ||
|
@@ -1604,25 +1608,34 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { | |
}) | ||
} | ||
|
||
let real_rust_source_base_dir = sess.real_rust_source_base_dir(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fn called a lot, you should wrap real_rust_source_base_dir into some once_cell. |
||
let try_to_translate_virtual_to_real = |name: &mut rustc_span::FileName| { | ||
// Translate the virtual `/rustc/$hash` prefix back to a real directory | ||
// that should hold actual sources, where possible. | ||
// | ||
// NOTE: if you update this, you might need to also update bootstrap's code for generating | ||
// the `rust-src` component in `Src::run` in `src/bootstrap/dist.rs`. | ||
let virtual_rust_source_base_dir = [ | ||
filter(sess, option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").map(Path::new)), | ||
filter(sess, sess.opts.unstable_opts.simulate_remapped_rust_src_base.as_deref()), | ||
filter( | ||
sess, | ||
&real_rust_source_base_dir, | ||
option_env!("CFG_VIRTUAL_RUST_SOURCE_BASE_DIR").map(Path::new), | ||
), | ||
filter( | ||
sess, | ||
&real_rust_source_base_dir, | ||
sess.opts.unstable_opts.simulate_remapped_rust_src_base.as_deref(), | ||
), | ||
]; | ||
|
||
debug!( | ||
"try_to_translate_virtual_to_real(name={:?}): \ | ||
virtual_rust_source_base_dir={:?}, real_rust_source_base_dir={:?}", | ||
name, virtual_rust_source_base_dir, sess.opts.real_rust_source_base_dir, | ||
name, virtual_rust_source_base_dir, real_rust_source_base_dir, | ||
); | ||
|
||
for virtual_dir in virtual_rust_source_base_dir.iter().flatten() { | ||
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir { | ||
if let Some(real_dir) = &real_rust_source_base_dir { | ||
if let rustc_span::FileName::Real(old_name) = name { | ||
if let rustc_span::RealFileName::Remapped { local_path: _, virtual_name } = | ||
old_name | ||
|
@@ -1713,7 +1726,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { | |
// `try_to_translate_virtual_to_real` don't have to worry about how the | ||
// compiler is bootstrapped. | ||
if let Some(virtual_dir) = &sess.opts.unstable_opts.simulate_remapped_rust_src_base | ||
&& let Some(real_dir) = &sess.opts.real_rust_source_base_dir | ||
&& let Some(real_dir) = &real_rust_source_base_dir | ||
&& let rustc_span::FileName::Real(ref mut old_name) = name | ||
{ | ||
let relative_path = match old_name { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only place where
real_rust_source_base_dir
gets called. Should I just move that logic into this file?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, should I be worried about perf here? We now re-compute
real_rust_source_base_dir
each timeimported_source_file
gets called. Not sure what would be the right place for a cache though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before #84233 this got computed after the
config
callback, inbuild_session
. That would be a lot better. But it seems that was changed for good reasons.