Rollup merge of #88751 - bjorn3:move_filesearch, r=oli-obk
Couple of changes to FileSearch and SearchPath * Turn a couple of regular comments into doc comments * Move `get_tools_search_paths` from `FileSearch` to `Session` * Use Lrc instead of Option to avoid duplication of a `SearchPath`
This commit is contained in:
commit
a84d39c7d4
6 changed files with 42 additions and 48 deletions
|
@ -36,7 +36,7 @@ use std::fmt;
|
|||
use std::io::Write;
|
||||
use std::num::NonZeroU32;
|
||||
use std::ops::{Div, Mul};
|
||||
use std::path::PathBuf;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
@ -131,9 +131,8 @@ pub struct Session {
|
|||
pub target: Target,
|
||||
pub host: Target,
|
||||
pub opts: config::Options,
|
||||
pub host_tlib_path: SearchPath,
|
||||
/// `None` if the host and target are the same.
|
||||
pub target_tlib_path: Option<SearchPath>,
|
||||
pub host_tlib_path: Lrc<SearchPath>,
|
||||
pub target_tlib_path: Lrc<SearchPath>,
|
||||
pub parse_sess: ParseSess,
|
||||
pub sysroot: PathBuf,
|
||||
/// The name of the root source file of the crate, in the local file system.
|
||||
|
@ -787,8 +786,7 @@ impl Session {
|
|||
&self.sysroot,
|
||||
self.opts.target_triple.triple(),
|
||||
&self.opts.search_paths,
|
||||
// `target_tlib_path == None` means it's the same as `host_tlib_path`.
|
||||
self.target_tlib_path.as_ref().unwrap_or(&self.host_tlib_path),
|
||||
&self.target_tlib_path,
|
||||
kind,
|
||||
)
|
||||
}
|
||||
|
@ -802,6 +800,18 @@ impl Session {
|
|||
)
|
||||
}
|
||||
|
||||
/// Returns a list of directories where target-specific tool binaries are located.
|
||||
pub fn get_tools_search_paths(&self, self_contained: bool) -> Vec<PathBuf> {
|
||||
let rustlib_path = rustc_target::target_rustlib_path(&self.sysroot, &config::host_triple());
|
||||
let p = std::array::IntoIter::new([
|
||||
Path::new(&self.sysroot),
|
||||
Path::new(&rustlib_path),
|
||||
Path::new("bin"),
|
||||
])
|
||||
.collect::<PathBuf>();
|
||||
if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] }
|
||||
}
|
||||
|
||||
pub fn init_incr_comp_session(
|
||||
&self,
|
||||
session_dir: PathBuf,
|
||||
|
@ -1245,11 +1255,13 @@ pub fn build_session(
|
|||
|
||||
let host_triple = config::host_triple();
|
||||
let target_triple = sopts.target_triple.triple();
|
||||
let host_tlib_path = SearchPath::from_sysroot_and_triple(&sysroot, host_triple);
|
||||
let host_tlib_path = Lrc::new(SearchPath::from_sysroot_and_triple(&sysroot, host_triple));
|
||||
let target_tlib_path = if host_triple == target_triple {
|
||||
None
|
||||
// Use the same `SearchPath` if host and target triple are identical to avoid unnecessary
|
||||
// rescanning of the target lib path and an unnecessary allocation.
|
||||
host_tlib_path.clone()
|
||||
} else {
|
||||
Some(SearchPath::from_sysroot_and_triple(&sysroot, target_triple))
|
||||
Lrc::new(SearchPath::from_sysroot_and_triple(&sysroot, target_triple))
|
||||
};
|
||||
|
||||
let file_path_mapping = sopts.file_path_mapping();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue