Skip to content

Commit 58000ed

Browse files
committed
Move get_tools_search_paths from FileSearch to Session
It only uses fields of FileSearch that are stored in Session too
1 parent a4a22f0 commit 58000ed

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ fn link_dwarf_object<'a>(sess: &'a Session, executable_out_filename: &Path) {
637637
cmd.arg("-o");
638638
cmd.arg(&dwp_out_filename);
639639

640-
let mut new_path = sess.host_filesearch(PathKind::All).get_tools_search_paths(false);
640+
let mut new_path = sess.get_tools_search_paths(false);
641641
if let Some(path) = env::var_os("PATH") {
642642
new_path.extend(env::split_paths(&path));
643643
}
@@ -2555,8 +2555,7 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
25552555
match ld_impl {
25562556
LdImpl::Lld => {
25572557
if sess.target.lld_flavor == LldFlavor::Ld64 {
2558-
let tools_path =
2559-
sess.host_filesearch(PathKind::All).get_tools_search_paths(false);
2558+
let tools_path = sess.get_tools_search_paths(false);
25602559
let ld64_exe = tools_path
25612560
.into_iter()
25622561
.map(|p| p.join("gcc-ld"))
@@ -2571,8 +2570,7 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
25712570
arg
25722571
});
25732572
} else {
2574-
let tools_path =
2575-
sess.host_filesearch(PathKind::All).get_tools_search_paths(false);
2573+
let tools_path = sess.get_tools_search_paths(false);
25762574
let lld_path = tools_path
25772575
.into_iter()
25782576
.map(|p| p.join("gcc-ld"))

compiler/rustc_codegen_ssa/src/back/linker.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc_middle::middle::dependency_format::Linkage;
1515
use rustc_middle::ty::TyCtxt;
1616
use rustc_serialize::{json, Encoder};
1717
use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip};
18-
use rustc_session::search_paths::PathKind;
1918
use rustc_session::Session;
2019
use rustc_span::symbol::Symbol;
2120
use rustc_target::spec::{LinkOutputKind, LinkerFlavor, LldFlavor};
@@ -101,7 +100,7 @@ pub fn get_linker<'a>(
101100

102101
// The compiler's sysroot often has some bundled tools, so add it to the
103102
// PATH for the child.
104-
let mut new_path = sess.host_filesearch(PathKind::All).get_tools_search_paths(self_contained);
103+
let mut new_path = sess.get_tools_search_paths(self_contained);
105104
let mut msvc_changed_path = false;
106105
if sess.target.is_like_msvc {
107106
if let Some(ref tool) = msvc_tool {

compiler/rustc_session/src/filesearch.rs

-12
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,6 @@ impl<'a> FileSearch<'a> {
8787
pub fn search_path_dirs(&self) -> Vec<PathBuf> {
8888
self.search_paths().map(|sp| sp.dir.to_path_buf()).collect()
8989
}
90-
91-
/// Returns a list of directories where target-specific tool binaries are located.
92-
pub fn get_tools_search_paths(&self, self_contained: bool) -> Vec<PathBuf> {
93-
let rustlib_path = rustc_target::target_rustlib_path(self.sysroot, &self.triple);
94-
let p = std::array::IntoIter::new([
95-
Path::new(&self.sysroot),
96-
Path::new(&rustlib_path),
97-
Path::new("bin"),
98-
])
99-
.collect::<PathBuf>();
100-
if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] }
101-
}
10290
}
10391

10492
pub fn make_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf {

compiler/rustc_session/src/session.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use std::fmt;
3636
use std::io::Write;
3737
use std::num::NonZeroU32;
3838
use std::ops::{Div, Mul};
39-
use std::path::PathBuf;
39+
use std::path::{Path, PathBuf};
4040
use std::str::FromStr;
4141
use std::sync::Arc;
4242
use std::time::Duration;
@@ -799,6 +799,18 @@ impl Session {
799799
)
800800
}
801801

802+
/// Returns a list of directories where target-specific tool binaries are located.
803+
pub fn get_tools_search_paths(&self, self_contained: bool) -> Vec<PathBuf> {
804+
let rustlib_path = rustc_target::target_rustlib_path(&self.sysroot, &config::host_triple());
805+
let p = std::array::IntoIter::new([
806+
Path::new(&self.sysroot),
807+
Path::new(&rustlib_path),
808+
Path::new("bin"),
809+
])
810+
.collect::<PathBuf>();
811+
if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] }
812+
}
813+
802814
pub fn init_incr_comp_session(
803815
&self,
804816
session_dir: PathBuf,

0 commit comments

Comments
 (0)