Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install: add --profile flag to override profile #2075

Merged
merged 1 commit into from
Oct 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn main() -> Result<()> {
let matches = cli().get_matches();
let verbose = matches.is_present("verbose");
let quiet = matches.is_present("quiet");
let cfg = &common::set_globals(verbose, quiet)?;
let cfg = &mut common::set_globals(verbose, quiet)?;

if maybe_upgrade_data(cfg, &matches)? {
return Ok(());
Expand Down Expand Up @@ -89,8 +89,8 @@ pub fn main() -> Result<()> {
(_, _) => unreachable!(),
},
("set", Some(c)) => match c.subcommand() {
("default-host", Some(m)) => set_default_host_triple(&cfg, m)?,
("profile", Some(m)) => set_profile(&cfg, m)?,
("default-host", Some(m)) => set_default_host_triple(cfg, m)?,
("profile", Some(m)) => set_profile(cfg, m)?,
(_, _) => unreachable!(),
},
("completions", Some(c)) => {
Expand Down Expand Up @@ -169,6 +169,13 @@ pub fn cli() -> App<'static, 'static> {
.required(true)
.multiple(true),
)
.arg(
Arg::with_name("profile")
.long("profile")
.takes_value(true)
.possible_values(Profile::names())
.required(false)
)
jonhoo marked this conversation as resolved.
Show resolved Hide resolved
.arg(
Arg::with_name("no-self-update")
.help("Don't perform self-update when running the `rustup install` command")
Expand Down Expand Up @@ -258,6 +265,13 @@ pub fn cli() -> App<'static, 'static> {
.required(true)
.multiple(true),
)
.arg(
Arg::with_name("profile")
.long("profile")
.takes_value(true)
.possible_values(Profile::names())
.required(false)
)
.arg(
Arg::with_name("no-self-update")
.help("Don't perform self update when running the `rustup toolchain install` command")
Expand Down Expand Up @@ -772,8 +786,13 @@ fn check_updates(cfg: &Cfg) -> Result<()> {
Ok(())
}

fn update(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
fn update(cfg: &mut Cfg, m: &ArgMatches<'_>) -> Result<()> {
let self_update = !m.is_present("no-self-update") && !self_update::NEVER_SELF_UPDATE;
if let Some(p) = m.value_of("profile") {
let p = Profile::from_str(p)?;
cfg.set_profile_override(p);
}
let cfg = &cfg;
if let Some(names) = m.values_of("toolchain") {
for name in names {
update_bare_triple_check(cfg, name)?;
Expand Down Expand Up @@ -1307,7 +1326,7 @@ fn set_default_host_triple(cfg: &Cfg, m: &ArgMatches<'_>) -> Result<()> {
Ok(())
}

fn set_profile(cfg: &Cfg, m: &ArgMatches) -> Result<()> {
fn set_profile(cfg: &mut Cfg, m: &ArgMatches) -> Result<()> {
cfg.set_profile(&m.value_of("profile-name").unwrap())?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ fn maybe_install_rust(
verbose: bool,
quiet: bool,
) -> Result<()> {
let cfg = common::set_globals(verbose, quiet)?;
let mut cfg = common::set_globals(verbose, quiet)?;
cfg.set_profile(profile_str)?;

// If there is already an install, then `toolchain_str` may not be
Expand Down
12 changes: 11 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl Display for OverrideReason {
}

pub struct Cfg {
pub profile_override: Option<dist::Profile>,
pub rustup_dir: PathBuf,
pub settings_file: SettingsFile,
pub toolchains_dir: PathBuf,
Expand Down Expand Up @@ -94,6 +95,7 @@ impl Cfg {
let dist_root = dist_root_server.clone() + "/dist";

let cfg = Self {
profile_override: None,
rustup_dir,
settings_file,
toolchains_dir,
Expand All @@ -116,6 +118,10 @@ impl Cfg {
Ok(cfg)
}

pub fn set_profile_override(&mut self, profile: dist::Profile) {
self.profile_override = Some(profile);
}

pub fn set_default(&self, toolchain: &str) -> Result<()> {
self.settings_file.with_mut(|s| {
s.default_toolchain = Some(toolchain.to_owned());
Expand All @@ -125,10 +131,11 @@ impl Cfg {
Ok(())
}

pub fn set_profile(&self, profile: &str) -> Result<()> {
pub fn set_profile(&mut self, profile: &str) -> Result<()> {
if !dist::Profile::names().contains(&profile) {
return Err(ErrorKind::UnknownProfile(profile.to_owned()).into());
}
self.profile_override = None;
self.settings_file.with_mut(|s| {
s.profile = Some(profile.to_owned());
Ok(())
Expand All @@ -145,6 +152,9 @@ impl Cfg {
// a user upgrades from a version of Rustup without profiles to a version of
// Rustup with profiles.
pub fn get_profile(&self) -> Result<dist::Profile> {
if let Some(p) = self.profile_override {
return Ok(p);
}
self.settings_file.with(|s| {
let p = match &s.profile {
Some(p) => p,
Expand Down
41 changes: 39 additions & 2 deletions tests/cli-v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
pub mod mock;

use crate::mock::clitools::{
self, expect_err, expect_not_stderr_ok, expect_not_stdout_ok, expect_ok, expect_ok_ex,
expect_stderr_ok, expect_stdout_ok, set_current_dist_date, this_host_triple, Config, Scenario,
self, expect_component_executable, expect_component_not_executable, expect_err,
expect_not_stderr_ok, expect_not_stdout_ok, expect_ok, expect_ok_ex, expect_stderr_ok,
expect_stdout_ok, set_current_dist_date, this_host_triple, Config, Scenario,
};
use std::fs;
use std::io::Write;
Expand Down Expand Up @@ -73,6 +74,42 @@ fn install_toolchain_from_version() {
});
}

#[test]
fn install_with_profile() {
setup_complex(&|config| {
// Start with a config that uses the "complete" profile
set_current_dist_date(config, "2015-01-01");
expect_ok(config, &["rustup", "set", "profile", "complete"]);

// Installing with minimal profile should only install rustc
expect_ok(
config,
&[
"rustup",
"toolchain",
"install",
"--profile",
"minimal",
"nightly",
"--no-self-update",
],
);
expect_ok(config, &["rustup", "default", "nightly"]);

expect_component_executable(config, "rustup");
expect_component_executable(config, "rustc");
expect_component_not_executable(config, "cargo");

// After an update, we should _still_ only have the profile-dictated components
set_current_dist_date(config, "2015-01-02");
expect_ok(config, &["rustup", "update", "nightly", "--no-self-update"]);

expect_component_executable(config, "rustup");
expect_component_executable(config, "rustc");
expect_component_not_executable(config, "cargo");
});
}

#[test]
fn default_existing_toolchain() {
setup(&|config| {
Expand Down