Don't return an error from get_or_default_sysroot
All callers unwrap the result.
This commit is contained in:
parent
0a679514d4
commit
7e8494f0a5
3 changed files with 22 additions and 31 deletions
|
@ -1286,8 +1286,7 @@ fn link_sanitizer_runtime(
|
||||||
if path.exists() {
|
if path.exists() {
|
||||||
sess.target_tlib_path.dir.clone()
|
sess.target_tlib_path.dir.clone()
|
||||||
} else {
|
} else {
|
||||||
let default_sysroot =
|
let default_sysroot = filesearch::get_or_default_sysroot();
|
||||||
filesearch::get_or_default_sysroot().expect("Failed finding sysroot");
|
|
||||||
let default_tlib =
|
let default_tlib =
|
||||||
filesearch::make_target_lib_path(&default_sysroot, sess.opts.target_triple.tuple());
|
filesearch::make_target_lib_path(&default_sysroot, sess.opts.target_triple.tuple());
|
||||||
default_tlib
|
default_tlib
|
||||||
|
|
|
@ -160,8 +160,7 @@ fn current_dll_path() -> Result<PathBuf, String> {
|
||||||
|
|
||||||
pub fn sysroot_candidates() -> SmallVec<[PathBuf; 2]> {
|
pub fn sysroot_candidates() -> SmallVec<[PathBuf; 2]> {
|
||||||
let target = crate::config::host_tuple();
|
let target = crate::config::host_tuple();
|
||||||
let mut sysroot_candidates: SmallVec<[PathBuf; 2]> =
|
let mut sysroot_candidates: SmallVec<[PathBuf; 2]> = smallvec![get_or_default_sysroot()];
|
||||||
smallvec![get_or_default_sysroot().expect("Failed finding sysroot")];
|
|
||||||
let path = current_dll_path().and_then(|s| try_canonicalize(s).map_err(|e| e.to_string()));
|
let path = current_dll_path().and_then(|s| try_canonicalize(s).map_err(|e| e.to_string()));
|
||||||
if let Ok(dll) = path {
|
if let Ok(dll) = path {
|
||||||
// use `parent` twice to chop off the file name and then also the
|
// use `parent` twice to chop off the file name and then also the
|
||||||
|
@ -195,12 +194,12 @@ pub fn sysroot_candidates() -> SmallVec<[PathBuf; 2]> {
|
||||||
/// Returns the provided sysroot or calls [`get_or_default_sysroot`] if it's none.
|
/// Returns the provided sysroot or calls [`get_or_default_sysroot`] if it's none.
|
||||||
/// Panics if [`get_or_default_sysroot`] returns an error.
|
/// Panics if [`get_or_default_sysroot`] returns an error.
|
||||||
pub fn materialize_sysroot(maybe_sysroot: Option<PathBuf>) -> PathBuf {
|
pub fn materialize_sysroot(maybe_sysroot: Option<PathBuf>) -> PathBuf {
|
||||||
maybe_sysroot.unwrap_or_else(|| get_or_default_sysroot().expect("Failed finding sysroot"))
|
maybe_sysroot.unwrap_or_else(|| get_or_default_sysroot())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function checks if sysroot is found using env::args().next(), and if it
|
/// This function checks if sysroot is found using env::args().next(), and if it
|
||||||
/// is not found, finds sysroot from current rustc_driver dll.
|
/// is not found, finds sysroot from current rustc_driver dll.
|
||||||
pub fn get_or_default_sysroot() -> Result<PathBuf, String> {
|
pub fn get_or_default_sysroot() -> PathBuf {
|
||||||
// Follow symlinks. If the resolved path is relative, make it absolute.
|
// Follow symlinks. If the resolved path is relative, make it absolute.
|
||||||
fn canonicalize(path: PathBuf) -> PathBuf {
|
fn canonicalize(path: PathBuf) -> PathBuf {
|
||||||
let path = try_canonicalize(&path).unwrap_or(path);
|
let path = try_canonicalize(&path).unwrap_or(path);
|
||||||
|
@ -255,30 +254,25 @@ pub fn get_or_default_sysroot() -> Result<PathBuf, String> {
|
||||||
// binary able to locate Rust libraries in systems using content-addressable
|
// binary able to locate Rust libraries in systems using content-addressable
|
||||||
// storage (CAS).
|
// storage (CAS).
|
||||||
fn from_env_args_next() -> Option<PathBuf> {
|
fn from_env_args_next() -> Option<PathBuf> {
|
||||||
match env::args_os().next() {
|
let mut p = PathBuf::from(env::args_os().next()?);
|
||||||
Some(first_arg) => {
|
|
||||||
let mut p = PathBuf::from(first_arg);
|
|
||||||
|
|
||||||
// Check if sysroot is found using env::args().next() only if the rustc in argv[0]
|
// Check if sysroot is found using env::args().next() only if the rustc in argv[0]
|
||||||
// is a symlink (see #79253). We might want to change/remove it to conform with
|
// is a symlink (see #79253). We might want to change/remove it to conform with
|
||||||
// https://www.gnu.org/prep/standards/standards.html#Finding-Program-Files in the
|
// https://www.gnu.org/prep/standards/standards.html#Finding-Program-Files in the
|
||||||
// future.
|
// future.
|
||||||
if fs::read_link(&p).is_err() {
|
if fs::read_link(&p).is_err() {
|
||||||
// Path is not a symbolic link or does not exist.
|
// Path is not a symbolic link or does not exist.
|
||||||
return None;
|
return None;
|
||||||
}
|
|
||||||
|
|
||||||
// Pop off `bin/rustc`, obtaining the suspected sysroot.
|
|
||||||
p.pop();
|
|
||||||
p.pop();
|
|
||||||
// Look for the target rustlib directory in the suspected sysroot.
|
|
||||||
let mut rustlib_path = rustc_target::relative_target_rustlib_path(&p, "dummy");
|
|
||||||
rustlib_path.pop(); // pop off the dummy target.
|
|
||||||
rustlib_path.exists().then_some(p)
|
|
||||||
}
|
|
||||||
None => None,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pop off `bin/rustc`, obtaining the suspected sysroot.
|
||||||
|
p.pop();
|
||||||
|
p.pop();
|
||||||
|
// Look for the target rustlib directory in the suspected sysroot.
|
||||||
|
let mut rustlib_path = rustc_target::relative_target_rustlib_path(&p, "dummy");
|
||||||
|
rustlib_path.pop(); // pop off the dummy target.
|
||||||
|
rustlib_path.exists().then_some(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(from_env_args_next().unwrap_or(default_from_rustc_driver_dll()?))
|
from_env_args_next().unwrap_or(default_from_rustc_driver_dll().expect("Failed finding sysroot"))
|
||||||
}
|
}
|
||||||
|
|
|
@ -734,9 +734,7 @@ impl Options {
|
||||||
|
|
||||||
let sysroot = match &maybe_sysroot {
|
let sysroot = match &maybe_sysroot {
|
||||||
Some(s) => s.clone(),
|
Some(s) => s.clone(),
|
||||||
None => {
|
None => rustc_session::filesearch::get_or_default_sysroot(),
|
||||||
rustc_session::filesearch::get_or_default_sysroot().expect("Failed finding sysroot")
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let libs = matches
|
let libs = matches
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue