From 22c5249f68676f7ba8852fd59cd222c49a1523a2 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 14 Jan 2023 13:08:55 +0000 Subject: [PATCH] Don't hard-code rustc path in get_rustc_version and get_default_sysroot --- build_system/build_sysroot.rs | 4 ++-- build_system/prepare.rs | 4 ++-- build_system/rustc_info.rs | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/build_system/build_sysroot.rs b/build_system/build_sysroot.rs index 7902c7005e01..15a5e030193d 100644 --- a/build_system/build_sysroot.rs +++ b/build_system/build_sysroot.rs @@ -53,7 +53,7 @@ pub(crate) fn build_sysroot( spawn_and_wait(build_cargo_wrapper_cmd); } - let default_sysroot = super::rustc_info::get_default_sysroot(); + let default_sysroot = super::rustc_info::get_default_sysroot(&bootstrap_host_compiler.rustc); let host_rustlib_lib = RUSTLIB_DIR.to_path(dirs).join(&bootstrap_host_compiler.triple).join("lib"); @@ -182,7 +182,7 @@ fn build_clif_sysroot_for_triple( process::exit(1); } Ok(source_version) => { - let rustc_version = get_rustc_version(); + let rustc_version = get_rustc_version(&compiler.rustc); if source_version != rustc_version { eprintln!("The patched sysroot source is outdated"); eprintln!("Source version: {}", source_version.trim()); diff --git a/build_system/prepare.rs b/build_system/prepare.rs index 4e898b30b7cc..bc6c3223dc23 100644 --- a/build_system/prepare.rs +++ b/build_system/prepare.rs @@ -35,7 +35,7 @@ pub(crate) fn prepare(dirs: &Dirs) { } fn prepare_sysroot(dirs: &Dirs) { - let sysroot_src_orig = get_default_sysroot().join("lib/rustlib/src/rust"); + let sysroot_src_orig = get_default_sysroot(Path::new("rustc")).join("lib/rustlib/src/rust"); assert!(sysroot_src_orig.exists()); eprintln!("[COPY] sysroot src"); @@ -50,7 +50,7 @@ fn prepare_sysroot(dirs: &Dirs) { &SYSROOT_SRC.to_path(dirs).join("library"), ); - let rustc_version = get_rustc_version(); + let rustc_version = get_rustc_version(Path::new("rustc")); fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap(); eprintln!("[GIT] init"); diff --git a/build_system/rustc_info.rs b/build_system/rustc_info.rs index 8e5ab688e131..6959d1e323cd 100644 --- a/build_system/rustc_info.rs +++ b/build_system/rustc_info.rs @@ -1,9 +1,9 @@ use std::path::{Path, PathBuf}; use std::process::{Command, Stdio}; -pub(crate) fn get_rustc_version() -> String { +pub(crate) fn get_rustc_version(rustc: &Path) -> String { let version_info = - Command::new("rustc").stderr(Stdio::inherit()).args(&["-V"]).output().unwrap().stdout; + Command::new(rustc).stderr(Stdio::inherit()).args(&["-V"]).output().unwrap().stdout; String::from_utf8(version_info).unwrap() } @@ -53,8 +53,8 @@ pub(crate) fn get_rustdoc_path() -> PathBuf { Path::new(String::from_utf8(rustc_path).unwrap().trim()).to_owned() } -pub(crate) fn get_default_sysroot() -> PathBuf { - let default_sysroot = Command::new("rustc") +pub(crate) fn get_default_sysroot(rustc: &Path) -> PathBuf { + let default_sysroot = Command::new(rustc) .stderr(Stdio::inherit()) .args(&["--print", "sysroot"]) .output()