Refactor out a repeating pattern with get_or_default_sysroot

This commit is contained in:
Maybe Waffle 2024-02-15 00:03:34 +00:00
parent a03d19ef63
commit 5441523f07
5 changed files with 15 additions and 29 deletions

View file

@ -336,10 +336,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
let early_dcx = EarlyDiagCtxt::new(config.opts.error_format);
let sysroot = match &config.opts.maybe_sysroot {
Some(sysroot) => sysroot.clone(),
None => filesearch::get_or_default_sysroot().expect("Failed finding sysroot"),
};
let sysroot = filesearch::materialize_sysroot(config.opts.maybe_sysroot.clone());
let (codegen_backend, target_cfg) = match config.make_codegen_backend {
None => {

View file

@ -13,7 +13,7 @@ use rustc_session::config::{
use rustc_session::lint::Level;
use rustc_session::search_paths::SearchPath;
use rustc_session::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
use rustc_session::{build_session, getopts, CompilerIO, EarlyDiagCtxt, Session};
use rustc_session::{build_session, filesearch, getopts, CompilerIO, EarlyDiagCtxt, Session};
use rustc_span::edition::{Edition, DEFAULT_EDITION};
use rustc_span::symbol::sym;
use rustc_span::{FileName, SourceFileHashAlgorithm};
@ -38,12 +38,7 @@ fn mk_session(matches: getopts::Matches) -> (Session, Cfg) {
temps_dir,
};
let sysroot = match &sessopts.maybe_sysroot {
Some(sysroot) => sysroot.clone(),
None => {
rustc_session::filesearch::get_or_default_sysroot().expect("Failed finding sysroot")
}
};
let sysroot = filesearch::materialize_sysroot(sessopts.maybe_sysroot.clone());
let target_cfg =
rustc_session::config::build_target_config(&early_dcx, &sessopts, None, &sysroot);