Remove Session::sysroot()
.
Instead of maybe storing its own sysroot and maybe deferring to the one in `Session::opts`, just clone the latter when necessary so one is always directly available. This removes the need for the getter.
This commit is contained in:
parent
0238bcc60d
commit
2640da7d13
5 changed files with 12 additions and 22 deletions
|
@ -48,7 +48,7 @@ use std::cell::{self, Cell, RefCell};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::PathBuf;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
@ -69,7 +69,7 @@ pub struct Session {
|
||||||
pub entry_fn: Once<Option<(NodeId, Span, config::EntryFnType)>>,
|
pub entry_fn: Once<Option<(NodeId, Span, config::EntryFnType)>>,
|
||||||
pub plugin_registrar_fn: Once<Option<ast::NodeId>>,
|
pub plugin_registrar_fn: Once<Option<ast::NodeId>>,
|
||||||
pub proc_macro_decls_static: Once<Option<ast::NodeId>>,
|
pub proc_macro_decls_static: Once<Option<ast::NodeId>>,
|
||||||
pub default_sysroot: Option<PathBuf>,
|
pub sysroot: PathBuf,
|
||||||
/// The name of the root source file of the crate, in the local file system.
|
/// The name of the root source file of the crate, in the local file system.
|
||||||
/// `None` means that there is no source file.
|
/// `None` means that there is no source file.
|
||||||
pub local_crate_source_file: Option<PathBuf>,
|
pub local_crate_source_file: Option<PathBuf>,
|
||||||
|
@ -694,17 +694,9 @@ impl Session {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sysroot<'a>(&'a self) -> &'a Path {
|
|
||||||
match self.opts.maybe_sysroot {
|
|
||||||
Some(ref sysroot) => sysroot,
|
|
||||||
None => self.default_sysroot
|
|
||||||
.as_ref()
|
|
||||||
.expect("missing sysroot and default_sysroot in Session"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn target_filesearch(&self, kind: PathKind) -> filesearch::FileSearch<'_> {
|
pub fn target_filesearch(&self, kind: PathKind) -> filesearch::FileSearch<'_> {
|
||||||
filesearch::FileSearch::new(
|
filesearch::FileSearch::new(
|
||||||
self.sysroot(),
|
&self.sysroot,
|
||||||
self.opts.target_triple.triple(),
|
self.opts.target_triple.triple(),
|
||||||
&self.opts.search_paths,
|
&self.opts.search_paths,
|
||||||
kind,
|
kind,
|
||||||
|
@ -712,7 +704,7 @@ impl Session {
|
||||||
}
|
}
|
||||||
pub fn host_filesearch(&self, kind: PathKind) -> filesearch::FileSearch<'_> {
|
pub fn host_filesearch(&self, kind: PathKind) -> filesearch::FileSearch<'_> {
|
||||||
filesearch::FileSearch::new(
|
filesearch::FileSearch::new(
|
||||||
self.sysroot(),
|
&self.sysroot,
|
||||||
config::host_triple(),
|
config::host_triple(),
|
||||||
&self.opts.search_paths,
|
&self.opts.search_paths,
|
||||||
kind,
|
kind,
|
||||||
|
@ -1109,9 +1101,9 @@ pub fn build_session_(
|
||||||
let target_cfg = config::build_target_config(&sopts, &span_diagnostic);
|
let target_cfg = config::build_target_config(&sopts, &span_diagnostic);
|
||||||
|
|
||||||
let p_s = parse::ParseSess::with_span_handler(span_diagnostic, source_map);
|
let p_s = parse::ParseSess::with_span_handler(span_diagnostic, source_map);
|
||||||
let default_sysroot = match sopts.maybe_sysroot {
|
let sysroot = match &sopts.maybe_sysroot {
|
||||||
Some(_) => None,
|
Some(sysroot) => sysroot.clone(),
|
||||||
None => Some(filesearch::get_or_default_sysroot()),
|
None => filesearch::get_or_default_sysroot(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let file_path_mapping = sopts.file_path_mapping();
|
let file_path_mapping = sopts.file_path_mapping();
|
||||||
|
@ -1147,7 +1139,7 @@ pub fn build_session_(
|
||||||
entry_fn: Once::new(),
|
entry_fn: Once::new(),
|
||||||
plugin_registrar_fn: Once::new(),
|
plugin_registrar_fn: Once::new(),
|
||||||
proc_macro_decls_static: Once::new(),
|
proc_macro_decls_static: Once::new(),
|
||||||
default_sysroot,
|
sysroot,
|
||||||
local_crate_source_file,
|
local_crate_source_file,
|
||||||
working_dir,
|
working_dir,
|
||||||
lint_store: RwLock::new(lint::LintStore::new()),
|
lint_store: RwLock::new(lint::LintStore::new()),
|
||||||
|
|
|
@ -1024,11 +1024,10 @@ fn link_args(cmd: &mut dyn Linker,
|
||||||
// where extern libraries might live, based on the
|
// where extern libraries might live, based on the
|
||||||
// addl_lib_search_paths
|
// addl_lib_search_paths
|
||||||
if sess.opts.cg.rpath {
|
if sess.opts.cg.rpath {
|
||||||
let sysroot = sess.sysroot();
|
|
||||||
let target_triple = sess.opts.target_triple.triple();
|
let target_triple = sess.opts.target_triple.triple();
|
||||||
let mut get_install_prefix_lib_path = || {
|
let mut get_install_prefix_lib_path = || {
|
||||||
let install_prefix = option_env!("CFG_PREFIX").expect("CFG_PREFIX");
|
let install_prefix = option_env!("CFG_PREFIX").expect("CFG_PREFIX");
|
||||||
let tlib = filesearch::relative_target_lib_path(sysroot, target_triple);
|
let tlib = filesearch::relative_target_lib_path(&sess.sysroot, target_triple);
|
||||||
let mut path = PathBuf::from(install_prefix);
|
let mut path = PathBuf::from(install_prefix);
|
||||||
path.push(&tlib);
|
path.push(&tlib);
|
||||||
|
|
||||||
|
|
|
@ -606,8 +606,7 @@ impl<'a> Linker for MsvcLinker<'a> {
|
||||||
self.cmd.arg("/DEBUG");
|
self.cmd.arg("/DEBUG");
|
||||||
|
|
||||||
// This will cause the Microsoft linker to embed .natvis info into the PDB file
|
// This will cause the Microsoft linker to embed .natvis info into the PDB file
|
||||||
let sysroot = self.sess.sysroot();
|
let natvis_dir_path = self.sess.sysroot.join("lib\\rustlib\\etc");
|
||||||
let natvis_dir_path = sysroot.join("lib\\rustlib\\etc");
|
|
||||||
if let Ok(natvis_dir) = fs::read_dir(&natvis_dir_path) {
|
if let Ok(natvis_dir) = fs::read_dir(&natvis_dir_path) {
|
||||||
// LLVM 5.0.0's lld-link frontend doesn't yet recognize, and chokes
|
// LLVM 5.0.0's lld-link frontend doesn't yet recognize, and chokes
|
||||||
// on, the /NATVIS:... flags. LLVM 6 (or earlier) should at worst ignore
|
// on, the /NATVIS:... flags. LLVM 6 (or earlier) should at worst ignore
|
||||||
|
|
|
@ -1042,7 +1042,7 @@ impl RustcDefaultCalls {
|
||||||
targets.sort();
|
targets.sort();
|
||||||
println!("{}", targets.join("\n"));
|
println!("{}", targets.join("\n"));
|
||||||
},
|
},
|
||||||
Sysroot => println!("{}", sess.sysroot().display()),
|
Sysroot => println!("{}", sess.sysroot.display()),
|
||||||
TargetSpec => println!("{}", sess.target.target.to_json().pretty()),
|
TargetSpec => println!("{}", sess.target.target.to_json().pretty()),
|
||||||
FileNames | CrateName => {
|
FileNames | CrateName => {
|
||||||
let input = input.unwrap_or_else(||
|
let input = input.unwrap_or_else(||
|
||||||
|
|
|
@ -678,7 +678,7 @@ impl<'a> Context<'a> {
|
||||||
// candidates are all canonicalized, so we canonicalize the sysroot
|
// candidates are all canonicalized, so we canonicalize the sysroot
|
||||||
// as well.
|
// as well.
|
||||||
if let Some((ref prev, _)) = ret {
|
if let Some((ref prev, _)) = ret {
|
||||||
let sysroot = self.sess.sysroot();
|
let sysroot = &self.sess.sysroot;
|
||||||
let sysroot = sysroot.canonicalize()
|
let sysroot = sysroot.canonicalize()
|
||||||
.unwrap_or_else(|_| sysroot.to_path_buf());
|
.unwrap_or_else(|_| sysroot.to_path_buf());
|
||||||
if prev.starts_with(&sysroot) {
|
if prev.starts_with(&sysroot) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue