mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-28 07:46:28 +00:00
perf(rust): avoid calling rustup
in more conditions (#4174)
This commit is contained in:
parent
61438484bd
commit
d8ac940098
@ -55,9 +55,10 @@ impl RustToolingEnvironmentInfo {
|
||||
// To display appropriate versions preventing `rustc` from downloading toolchains, we have to
|
||||
// check
|
||||
// 1. `$RUSTUP_TOOLCHAIN`
|
||||
// 2. `rustup override list`
|
||||
// 2. The override list from ~/.rustup/settings.toml (like `rustup override list`)
|
||||
// 3. `rust-toolchain` or `rust-toolchain.toml` in `.` or parent directories
|
||||
// 4. `rustup default`
|
||||
// 4. The `default_toolchain` from ~/.rustup/settings.toml (like `rustup default`)
|
||||
// 5. `rustup default` (in addition to the above, this also looks at global fallback config files)
|
||||
// as `rustup` does.
|
||||
// https://github.com/rust-lang/rustup.rs/tree/eb694fcada7becc5d9d160bf7c623abe84f8971d#override-precedence
|
||||
//
|
||||
@ -74,6 +75,11 @@ impl RustToolingEnvironmentInfo {
|
||||
.lookup_override(context.current_dir.as_path())
|
||||
})
|
||||
.or_else(|| find_rust_toolchain_file(context))
|
||||
.or_else(|| {
|
||||
self.get_rustup_settings(context)
|
||||
.default_toolchain()
|
||||
.map(std::string::ToString::to_string)
|
||||
})
|
||||
.or_else(|| execute_rustup_default(context));
|
||||
|
||||
log::debug!("Environmental toolchain override is {:?}", out);
|
||||
@ -87,12 +93,32 @@ impl RustToolingEnvironmentInfo {
|
||||
fn get_rustup_rustc_version(&self, context: &Context) -> &RustupRunRustcVersionOutcome {
|
||||
self.rustup_rustc_output.get_or_init(|| {
|
||||
let out = if let Some(toolchain) = self.get_env_toolchain_override(context) {
|
||||
create_command("rustup")
|
||||
.and_then(|mut cmd| {
|
||||
cmd.args(&["run", toolchain, "rustc", "--version"])
|
||||
.current_dir(&context.current_dir)
|
||||
.output()
|
||||
// First try runnig ~/.rustup/toolchains/<toolchain>/bin/rustc --version
|
||||
rustup_home()
|
||||
.map(|rustup_folder| {
|
||||
rustup_folder
|
||||
.join("toolchains")
|
||||
.join(toolchain)
|
||||
.join("bin")
|
||||
.join("rustc")
|
||||
})
|
||||
.and_then(|rustc| {
|
||||
log::trace!("Running rustc --version directly with {:?}", rustc);
|
||||
create_command(rustc).map(|mut cmd| {
|
||||
cmd.arg("--version");
|
||||
cmd
|
||||
})
|
||||
})
|
||||
.or_else(|_| {
|
||||
// If that fails, try running rustup rustup run <toolchain> rustc --version
|
||||
// Depending on the source of the toolchain override, it might not have been a full toolchain name ("stable" or "nightly").
|
||||
log::trace!("Running rustup {toolchain} rustc --version");
|
||||
create_command("rustup").map(|mut cmd| {
|
||||
cmd.args(&["run", toolchain, "rustc", "--version"]);
|
||||
cmd
|
||||
})
|
||||
})
|
||||
.and_then(|mut cmd| cmd.current_dir(&context.current_dir).output())
|
||||
.map(extract_toolchain_from_rustup_run_rustc_version)
|
||||
.unwrap_or(RustupRunRustcVersionOutcome::RustupNotWorking)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user