Skip to content

Commit

Permalink
Verify the provided toolchain and host triple on install
Browse files Browse the repository at this point in the history
When rustup-init is running, we need to verify that the provided
host triple and toolchain channel can be used together to determine
a full toolchain triple (quadruple?).  If we can't do this during
the sanity checks, error out early.
  • Loading branch information
kinnison committed Dec 16, 2018
1 parent 6b1d027 commit b9f786a
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/rustup-cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 219,7 @@ fn canonical_cargo_home() -> Result<String> {
/// `CARGO_HOME`/bin, hardlinking the various Rust tools to it,
/// and adding `CARGO_HOME`/bin to PATH.
pub fn install(no_prompt: bool, verbose: bool, mut opts: InstallOpts) -> Result<()> {
do_pre_install_sanity_checks()?;
do_pre_install_sanity_checks(&opts)?;
check_existence_of_rustc_or_cargo_in_path(no_prompt)?;
do_anti_sudo_check(no_prompt)?;

Expand Down Expand Up @@ -374,7 374,7 @@ fn check_existence_of_rustc_or_cargo_in_path(no_prompt: bool) -> Result<()> {
}
}

fn do_pre_install_sanity_checks() -> Result<()> {
fn do_pre_install_sanity_checks(opts: &InstallOpts) -> Result<()> {
let multirust_manifest_path = PathBuf::from("/usr/local/lib/rustlib/manifest-multirust");
let rustc_manifest_path = PathBuf::from("/usr/local/lib/rustlib/manifest-rustc");
let uninstaller_path = PathBuf::from("/usr/local/lib/rustlib/uninstall.sh");
Expand Down Expand Up @@ -455,6 455,26 @@ fn do_pre_install_sanity_checks() -> Result<()> {
return Err("cannot install while rustup.sh is installed".into());
}

// Verify that the installation options are vaguely sane
(|| {
let host_triple = dist::TargetTriple::from_str(&opts.default_host_triple);
let partial_channel = dist::PartialToolchainDesc::from_str(&opts.default_toolchain)?;
let resolved = partial_channel.resolve(&host_triple)?.to_string();
debug!(
"Successfully resolved installation toolchain as: {}",
resolved
);
Ok(())
})()
.map_err(|e: Box<std::error::Error>| {
format!(
"Pre-checks for host and toolchain failed: {}\n\
If you are unsure of suitable values, the 'stable' toolchain is the default.\n\
Valid host triples look something like: {}",
e,
dist::TargetTriple::from_host_or_build().as_ref()
)
})?;
Ok(())
}

Expand Down

0 comments on commit b9f786a

Please sign in to comment.