Skip to content

Commit

Permalink
rustup: Prevent setting an invalid default host
Browse files Browse the repository at this point in the history
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 <dsilvers@digital-scurf.org>
  • Loading branch information
kinnison committed Jan 16, 2019
1 parent 239b34a commit 36ec58f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/rustup/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
14 changes: 13 additions & 1 deletion tests/cli-rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
});
}
Expand Down

0 comments on commit 36ec58f

Please sign in to comment.