mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Make real_rust_path_dir
a TRACKED_NO_CRATE_HASH option
This also adds support for doc-comments to Options.
This commit is contained in:
parent
272015190d
commit
39648ea467
@ -459,6 +459,10 @@ fn test_top_level_options_tracked_no_crate() {
|
||||
// Make sure that changing a [TRACKED_NO_CRATE_HASH] option leaves the crate hash unchanged but changes the incremental hash.
|
||||
// This list is in alphabetical order.
|
||||
tracked!(remap_path_prefix, vec![("/home/bors/rust".into(), "src".into())]);
|
||||
tracked!(
|
||||
real_rust_source_base_dir,
|
||||
Some("/home/bors/rust/.rustup/toolchains/nightly/lib/rustlib/src/rust".into())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -1617,7 +1617,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||
.map(Path::new)
|
||||
.filter(|_| {
|
||||
// Only spend time on further checks if we have what to translate *to*.
|
||||
sess.real_rust_source_base_dir.is_some()
|
||||
sess.opts.real_rust_source_base_dir.is_some()
|
||||
})
|
||||
.filter(|virtual_dir| {
|
||||
// Don't translate away `/rustc/$hash` if we're still remapping to it,
|
||||
@ -1629,11 +1629,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||
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.real_rust_source_base_dir,
|
||||
name, virtual_rust_source_base_dir, sess.opts.real_rust_source_base_dir,
|
||||
);
|
||||
|
||||
if let Some(virtual_dir) = virtual_rust_source_base_dir {
|
||||
if let Some(real_dir) = &sess.real_rust_source_base_dir {
|
||||
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir {
|
||||
if let rustc_span::FileName::Real(old_name) = name {
|
||||
if let rustc_span::RealFileName::Named(one_path) = old_name {
|
||||
if let Ok(rest) = one_path.strip_prefix(virtual_dir) {
|
||||
|
@ -702,6 +702,7 @@ impl Default for Options {
|
||||
cli_forced_codegen_units: None,
|
||||
cli_forced_thinlto_off: false,
|
||||
remap_path_prefix: Vec::new(),
|
||||
real_rust_source_base_dir: None,
|
||||
edition: DEFAULT_EDITION,
|
||||
json_artifact_notifications: false,
|
||||
json_unused_externs: false,
|
||||
@ -1980,6 +1981,34 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||
}
|
||||
}
|
||||
|
||||
// Try to find a directory containing the Rust `src`, for more details see
|
||||
// the doc comment on the `real_rust_source_base_dir` field.
|
||||
let tmp_buf;
|
||||
let sysroot = match &sysroot_opt {
|
||||
Some(s) => s,
|
||||
None => {
|
||||
tmp_buf = crate::filesearch::get_or_default_sysroot();
|
||||
&tmp_buf
|
||||
}
|
||||
};
|
||||
let real_rust_source_base_dir = {
|
||||
// This is the location used by the `rust-src` `rustup` component.
|
||||
let mut candidate = sysroot.join("lib/rustlib/src/rust");
|
||||
if let Ok(metadata) = candidate.symlink_metadata() {
|
||||
// Replace the symlink rustbuild creates, with its destination.
|
||||
// We could try to use `fs::canonicalize` instead, but that might
|
||||
// produce unnecessarily verbose path.
|
||||
if metadata.file_type().is_symlink() {
|
||||
if let Ok(symlink_dest) = std::fs::read_link(&candidate) {
|
||||
candidate = symlink_dest;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only use this directory if it has a file we can expect to always find.
|
||||
if candidate.join("library/std/src/lib.rs").is_file() { Some(candidate) } else { None }
|
||||
};
|
||||
|
||||
Options {
|
||||
crate_types,
|
||||
optimize: opt_level,
|
||||
@ -2010,6 +2039,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
|
||||
cli_forced_codegen_units: codegen_units,
|
||||
cli_forced_thinlto_off: disable_thinlto,
|
||||
remap_path_prefix,
|
||||
real_rust_source_base_dir,
|
||||
edition,
|
||||
json_artifact_notifications,
|
||||
json_unused_externs,
|
||||
|
@ -54,11 +54,15 @@ macro_rules! hash_substruct {
|
||||
|
||||
macro_rules! top_level_options {
|
||||
(pub struct Options { $(
|
||||
$( #[$attr:meta] )*
|
||||
$opt:ident : $t:ty [$dep_tracking_marker:ident],
|
||||
)* } ) => (
|
||||
#[derive(Clone)]
|
||||
pub struct Options {
|
||||
$(pub $opt: $t),*
|
||||
$(
|
||||
$( #[$attr] )*
|
||||
pub $opt: $t
|
||||
),*
|
||||
}
|
||||
|
||||
impl Options {
|
||||
@ -174,6 +178,14 @@ top_level_options!(
|
||||
|
||||
// Remap source path prefixes in all output (messages, object files, debug, etc.).
|
||||
remap_path_prefix: Vec<(PathBuf, PathBuf)> [TRACKED_NO_CRATE_HASH],
|
||||
/// Base directory containing the `src/` for the Rust standard library, and
|
||||
/// potentially `rustc` as well, if we can can find it. Right now it's always
|
||||
/// `$sysroot/lib/rustlib/src/rust` (i.e. the `rustup` `rust-src` component).
|
||||
///
|
||||
/// This directory is what the virtual `/rustc/$hash` is translated back to,
|
||||
/// if Rust was built with path remapping to `/rustc/$hash` enabled
|
||||
/// (the `rust.remap-debuginfo` option in `config.toml`).
|
||||
real_rust_source_base_dir: Option<PathBuf> [TRACKED_NO_CRATE_HASH],
|
||||
|
||||
edition: Edition [TRACKED],
|
||||
|
||||
@ -254,13 +266,13 @@ macro_rules! options {
|
||||
}
|
||||
|
||||
impl $struct_name {
|
||||
fn dep_tracking_hash(&self, for_crate_hash: bool, error_format: ErrorOutputType) -> u64 {
|
||||
fn dep_tracking_hash(&self, _for_crate_hash: bool, error_format: ErrorOutputType) -> u64 {
|
||||
let mut sub_hashes = BTreeMap::new();
|
||||
$({
|
||||
hash_opt!($opt,
|
||||
&self.$opt,
|
||||
&mut sub_hashes,
|
||||
for_crate_hash,
|
||||
_for_crate_hash,
|
||||
[$dep_tracking_marker]);
|
||||
})*
|
||||
let mut hasher = DefaultHasher::new();
|
||||
|
@ -214,15 +214,6 @@ pub struct Session {
|
||||
/// drown everything else in noise.
|
||||
miri_unleashed_features: Lock<Vec<(Span, Option<Symbol>)>>,
|
||||
|
||||
/// Base directory containing the `src/` for the Rust standard library, and
|
||||
/// potentially `rustc` as well, if we can can find it. Right now it's always
|
||||
/// `$sysroot/lib/rustlib/src/rust` (i.e. the `rustup` `rust-src` component).
|
||||
///
|
||||
/// This directory is what the virtual `/rustc/$hash` is translated back to,
|
||||
/// if Rust was built with path remapping to `/rustc/$hash` enabled
|
||||
/// (the `rust.remap-debuginfo` option in `config.toml`).
|
||||
pub real_rust_source_base_dir: Option<PathBuf>,
|
||||
|
||||
/// Architecture to use for interpreting asm!.
|
||||
pub asm_arch: Option<InlineAsmArch>,
|
||||
|
||||
@ -1390,26 +1381,6 @@ pub fn build_session(
|
||||
_ => CtfeBacktrace::Disabled,
|
||||
});
|
||||
|
||||
// Try to find a directory containing the Rust `src`, for more details see
|
||||
// the doc comment on the `real_rust_source_base_dir` field.
|
||||
let real_rust_source_base_dir = {
|
||||
// This is the location used by the `rust-src` `rustup` component.
|
||||
let mut candidate = sysroot.join("lib/rustlib/src/rust");
|
||||
if let Ok(metadata) = candidate.symlink_metadata() {
|
||||
// Replace the symlink rustbuild creates, with its destination.
|
||||
// We could try to use `fs::canonicalize` instead, but that might
|
||||
// produce unnecessarily verbose path.
|
||||
if metadata.file_type().is_symlink() {
|
||||
if let Ok(symlink_dest) = std::fs::read_link(&candidate) {
|
||||
candidate = symlink_dest;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only use this directory if it has a file we can expect to always find.
|
||||
if candidate.join("library/std/src/lib.rs").is_file() { Some(candidate) } else { None }
|
||||
};
|
||||
|
||||
let asm_arch =
|
||||
if target_cfg.allow_asm { InlineAsmArch::from_str(&target_cfg.arch).ok() } else { None };
|
||||
|
||||
@ -1453,7 +1424,6 @@ pub fn build_session(
|
||||
system_library_path: OneThread::new(RefCell::new(Default::default())),
|
||||
ctfe_backtrace,
|
||||
miri_unleashed_features: Lock::new(Default::default()),
|
||||
real_rust_source_base_dir,
|
||||
asm_arch,
|
||||
target_features: FxHashSet::default(),
|
||||
known_attrs: Lock::new(MarkedAttrs::new()),
|
||||
|
Loading…
Reference in New Issue
Block a user