From 36ec58f9a76c4519280b5a9cd956df868a53d5fc Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Mon, 14 Jan 2019 21:53:13 +0000 Subject: [PATCH] rustup: Prevent setting an invalid default host Perform similar checks to when resolving toolchains in order to reduce the possibility that the configuration will end up with an unusable default-host value. This finally addresses the initial point in #745 and thus fixes it. Signed-off-by: Daniel Silverstone --- src/rustup/config.rs | 8 +++++--- tests/cli-rustup.rs | 14 +++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/rustup/config.rs b/src/rustup/config.rs index a13a8e3f54..414a4881d7 100644 --- a/src/rustup/config.rs +++ b/src/rustup/config.rs @@ -478,9 +478,11 @@ impl Cfg { } pub fn set_default_host_triple(&self, host_triple: &str) -> Result<()> { - if dist::PartialTargetTriple::from_str(host_triple).is_none() { - return Err("Invalid host triple".into()); - } + // Ensure that the provided host_triple is capable of resolving + // against the 'stable' toolchain. This provides early errors + // if the supplied triple is insufficient / bad. + dist::PartialToolchainDesc::from_str("stable")? + .resolve(&dist::TargetTriple::from_str(host_triple))?; self.settings_file.with_mut(|s| { s.default_host_triple = Some(host_triple.to_owned()); Ok(()) diff --git a/tests/cli-rustup.rs b/tests/cli-rustup.rs index 266baae328..8a4aafd762 100644 --- a/tests/cli-rustup.rs +++ b/tests/cli-rustup.rs @@ -900,7 +900,19 @@ fn set_default_host_invalid_triple() { expect_err( config, &["rustup", "set", "default-host", "foo"], - "Invalid host triple", + "error: Provided host 'foo' couldn't be converted to partial triple", + ); + }); +} + +// #745 +#[test] +fn set_default_host_invalid_triple_valid_partial() { + setup(&|config| { + expect_err( + config, + &["rustup", "set", "default-host", "x86_64-msvc"], + "error: Provided host 'x86_64-msvc' did not specify an operating system", ); }); }