|
1 | 1 | use std::fmt::{self, Debug, Display}; |
| 2 | +use std::io; |
2 | 3 | use std::path::{Path, PathBuf}; |
3 | 4 | use std::str::FromStr; |
4 | 5 | use std::sync::Arc; |
5 | | -use std::{env, io}; |
6 | 6 |
|
7 | 7 | use anyhow::{Context, Result, anyhow, bail}; |
8 | 8 | use serde::Deserialize; |
@@ -282,11 +282,12 @@ impl<'a> Cfg<'a> { |
282 | 282 | let default_host_triple = |
283 | 283 | settings_file.with(|s| Ok(get_default_host_triple(s, process)))?; |
284 | 284 | // Environment override |
285 | | - let env_override = non_empty_env_var("RUSTUP_TOOLCHAIN", process)? |
286 | | - .map(ResolvableLocalToolchainName::try_from) |
287 | | - .transpose()? |
288 | | - .map(|t| t.resolve(&default_host_triple)) |
289 | | - .transpose()?; |
| 285 | + let env_override = match process.var_opt("RUSTUP_TOOLCHAIN")? { |
| 286 | + Some(tc) => { |
| 287 | + Some(ResolvableLocalToolchainName::try_from(&tc)?.resolve(&default_host_triple)?) |
| 288 | + } |
| 289 | + None => None, |
| 290 | + }; |
290 | 291 |
|
291 | 292 | let dist_root_server = dist_root_server(process)?; |
292 | 293 |
|
@@ -982,22 +983,21 @@ impl<'a> Cfg<'a> { |
982 | 983 | /// The root path of the release server, without the `/dist` suffix. |
983 | 984 | /// By default, it points to [`dist::DEFAULT_DIST_SERVER`]. |
984 | 985 | pub(crate) fn dist_root_server(process: &Process) -> Result<String> { |
985 | | - Ok( |
986 | | - if let Some(s) = non_empty_env_var("RUSTUP_DIST_SERVER", process)? { |
987 | | - trace!("`RUSTUP_DIST_SERVER` has been set to `{s}`"); |
988 | | - s |
989 | | - } |
990 | | - // For backwards compatibility |
991 | | - else if let Some(mut root) = non_empty_env_var("RUSTUP_DIST_ROOT", process)? { |
992 | | - trace!("`RUSTUP_DIST_ROOT` has been set to `{root}`"); |
993 | | - if let Some(stripped) = root.strip_suffix("/dist") { |
994 | | - root.truncate(stripped.len()); |
995 | | - } |
996 | | - root |
997 | | - } else { |
998 | | - dist::DEFAULT_DIST_SERVER.to_owned() |
999 | | - }, |
1000 | | - ) |
| 986 | + if let Some(s) = process.var_opt("RUSTUP_DIST_SERVER")? { |
| 987 | + trace!("`RUSTUP_DIST_SERVER` has been set to `{s}`"); |
| 988 | + return Ok(s); |
| 989 | + } |
| 990 | + |
| 991 | + // For backwards compatibility |
| 992 | + let Some(mut root) = process.var_opt("RUSTUP_DIST_ROOT")? else { |
| 993 | + return Ok(dist::DEFAULT_DIST_SERVER.to_owned()); |
| 994 | + }; |
| 995 | + |
| 996 | + trace!("`RUSTUP_DIST_ROOT` has been set to `{root}`"); |
| 997 | + if let Some(stripped) = root.strip_suffix("/dist") { |
| 998 | + root.truncate(stripped.len()); |
| 999 | + } |
| 1000 | + Ok(root) |
1001 | 1001 | } |
1002 | 1002 |
|
1003 | 1003 | impl Debug for Cfg<'_> { |
@@ -1043,15 +1043,6 @@ fn get_default_host_triple(s: &Settings, process: &Process) -> TargetTriple { |
1043 | 1043 | .unwrap_or_else(|| TargetTriple::from_host_or_build(process)) |
1044 | 1044 | } |
1045 | 1045 |
|
1046 | | -pub(crate) fn non_empty_env_var(name: &str, process: &Process) -> anyhow::Result<Option<String>> { |
1047 | | - match process.var(name) { |
1048 | | - Ok(s) if !s.is_empty() => Ok(Some(s)), |
1049 | | - Ok(_) => Ok(None), |
1050 | | - Err(env::VarError::NotPresent) => Ok(None), |
1051 | | - Err(err) => Err(err.into()), |
1052 | | - } |
1053 | | -} |
1054 | | - |
1055 | 1046 | fn no_toolchain_error(process: &Process) -> anyhow::Error { |
1056 | 1047 | RustupError::ToolchainNotSelected(process.name().unwrap_or_else(|| "Rust".into())).into() |
1057 | 1048 | } |
|
0 commit comments