Skip to content

Commit 36ec58f

Browse files
committed
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 <[email protected]>
1 parent 239b34a commit 36ec58f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/rustup/config.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,11 @@ impl Cfg {
478478
}
479479

480480
pub fn set_default_host_triple(&self, host_triple: &str) -> Result<()> {
481-
if dist::PartialTargetTriple::from_str(host_triple).is_none() {
482-
return Err("Invalid host triple".into());
483-
}
481+
// Ensure that the provided host_triple is capable of resolving
482+
// against the 'stable' toolchain. This provides early errors
483+
// if the supplied triple is insufficient / bad.
484+
dist::PartialToolchainDesc::from_str("stable")?
485+
.resolve(&dist::TargetTriple::from_str(host_triple))?;
484486
self.settings_file.with_mut(|s| {
485487
s.default_host_triple = Some(host_triple.to_owned());
486488
Ok(())

tests/cli-rustup.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,19 @@ fn set_default_host_invalid_triple() {
900900
expect_err(
901901
config,
902902
&["rustup", "set", "default-host", "foo"],
903-
"Invalid host triple",
903+
"error: Provided host 'foo' couldn't be converted to partial triple",
904+
);
905+
});
906+
}
907+
908+
// #745
909+
#[test]
910+
fn set_default_host_invalid_triple_valid_partial() {
911+
setup(&|config| {
912+
expect_err(
913+
config,
914+
&["rustup", "set", "default-host", "x86_64-msvc"],
915+
"error: Provided host 'x86_64-msvc' did not specify an operating system",
904916
);
905917
});
906918
}

0 commit comments

Comments
 (0)