Skip to content

Commit

Permalink
Installation: Do not set default host triple if not specified
Browse files Browse the repository at this point in the history
In order to reduce surprise, if the user did not explicitly supply
or explicitly set a default host triple during installation then
we do not override whatever the configuration picks by default
from the host/build.

Signed-off-by: Daniel Silverstone <[email protected]>
  • Loading branch information
kinnison committed Oct 26, 2019
1 parent df5498d commit 6a92580
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
37 changes: 26 additions & 11 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use crate::common::{self, Confirm};
use crate::errors::*;
use crate::markdown::md;
use crate::term2;
use rustup::dist::dist::{self, Profile};
use rustup::dist::dist::{self, Profile, TargetTriple};
use rustup::utils::utils;
use rustup::utils::Notification;
use rustup::{DUP_TOOLS, TOOLS};
Expand All @@ -46,7 +46,7 @@ use std::path::{Component, Path, PathBuf};
use std::process::{self, Command};

pub struct InstallOpts<'a> {
pub default_host_triple: String,
pub default_host_triple: Option<String>,
pub default_toolchain: String,
pub profile: String,
pub no_modify_path: bool,
Expand Down Expand Up @@ -284,7 +284,7 @@ pub fn install(no_prompt: bool, verbose: bool, quiet: bool, mut opts: InstallOpt
maybe_install_rust(
&opts.default_toolchain,
&opts.profile,
&opts.default_host_triple,
opts.default_host_triple.as_ref(),
opts.components,
opts.targets,
verbose,
Expand Down Expand Up @@ -432,7 +432,11 @@ fn do_pre_install_options_sanity_checks(opts: &InstallOpts) -> Result<()> {
use std::str::FromStr;
// Verify that the installation options are vaguely sane
(|| {
let host_triple = dist::TargetTriple::new(&opts.default_host_triple);
let host_triple = opts
.default_host_triple
.as_ref()
.map(|s| dist::TargetTriple::new(s))
.unwrap_or_else(|| TargetTriple::from_host_or_build());
let toolchain_to_use = if opts.default_toolchain == "none" {
"stable"
} else {
Expand Down Expand Up @@ -604,7 +608,10 @@ fn current_install_opts(opts: &InstallOpts) -> String {
- ` `profile: `{}`
- modify PATH variable: `{}`
",
opts.default_host_triple,
opts.default_host_triple
.as_ref()
.map(|s| TargetTriple::new(s))
.unwrap_or_else(|| TargetTriple::from_host_or_build()),
opts.default_toolchain,
opts.profile,
if !opts.no_modify_path { "yes" } else { "no" }
Expand All @@ -620,8 +627,12 @@ fn customize_install(mut opts: InstallOpts) -> Result<InstallOpts> {

println!();

opts.default_host_triple =
common::question_str("Default host triple?", &opts.default_host_triple)?;
opts.default_host_triple = Some(common::question_str(
"Default host triple?",
&opts
.default_host_triple
.unwrap_or_else(|| TargetTriple::from_host_or_build().to_string()),
)?);

opts.default_toolchain = common::question_str(
"Default toolchain? (stable/beta/nightly/none)",
Expand Down Expand Up @@ -740,7 +751,7 @@ pub fn install_proxies() -> Result<()> {
fn maybe_install_rust(
toolchain_str: &str,
profile_str: &str,
default_host_triple: &str,
default_host_triple: Option<&String>,
components: &[&str],
targets: &[&str],
verbose: bool,
Expand All @@ -749,9 +760,13 @@ fn maybe_install_rust(
let mut cfg = common::set_globals(verbose, quiet)?;
cfg.set_profile(profile_str)?;

// Set host triple now as it will affect resolution of toolchain_str
info!("setting default host triple to {}", default_host_triple);
cfg.set_default_host_triple(default_host_triple)?;
if let Some(default_host_triple) = default_host_triple {
// Set host triple now as it will affect resolution of toolchain_str
info!("setting default host triple to {}", default_host_triple);
cfg.set_default_host_triple(default_host_triple)?;
} else {
info!("default host triple is {}", cfg.get_default_host_triple()?);
}

// If there is already an install, then `toolchain_str` may not be
// a toolchain the user actually wants. Don't do anything. FIXME:
Expand Down
5 changes: 2 additions & 3 deletions src/cli/setup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::common;
use crate::errors::*;
use crate::self_update::{self, InstallOpts};
use clap::{App, AppSettings, Arg};
use rustup::dist::dist::{Profile, TargetTriple};
use rustup::dist::dist::Profile;
use std::env;

pub fn main() -> Result<()> {
Expand Down Expand Up @@ -89,8 +89,7 @@ pub fn main() -> Result<()> {
let quiet = matches.is_present("quiet");
let default_host = matches
.value_of("default-host")
.map(std::borrow::ToOwned::to_owned)
.unwrap_or_else(|| TargetTriple::from_host_or_build().to_string());
.map(std::borrow::ToOwned::to_owned);
let default_toolchain = matches.value_of("default-toolchain").unwrap_or("stable");
let profile = matches
.value_of("profile")
Expand Down

0 comments on commit 6a92580

Please sign in to comment.