Skip to content
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
17 changes: 13 additions & 4 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ fn show_channel_updates(
pub(crate) async fn update_all_channels(
cfg: &Cfg<'_>,
force_update: bool,
check: bool,
) -> anyhow::Result<ExitCode> {
let profile = cfg.get_profile()?;
let channels = cfg.list_channels()?;
Expand All @@ -241,7 +242,9 @@ pub(crate) async fn update_all_channels(
}))
.await;

let mut toolchains = Vec::new();
let mut toolchains = Vec::with_capacity(channels_with_manifests.len());
let mut has_update_error = false;
let mut has_update = false;
for (desc, distributable, manifest) in channels_with_manifests {
let result = if force_update || manifest.is_some() {
let options = DistOptions::new(&[], &[], &desc, profile, force_update, cfg)?
Expand All @@ -251,16 +254,22 @@ pub(crate) async fn update_all_channels(
Ok(UpdateStatus::Unchanged)
};

if let Err(e) = &result {
error!("{e}");
match &result {
Ok(UpdateStatus::Updated(_)) | Ok(UpdateStatus::Installed) => has_update = true,
Err(e) => {
has_update_error = true;
error!("{e}");
}
_ => (),
}

toolchains.push((desc, result));
}

let has_update_error = toolchains.iter().any(|(_, r)| r.is_err());
let exit_code = if has_update_error {
ExitCode::FAILURE
} else if check && has_update {
ExitCode::UPDATES_AVAILABLE
} else {
ExitCode::SUCCESS
};
Expand Down
12 changes: 11 additions & 1 deletion src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ enum RustupSubcmd {
/// Install toolchains that require an emulator. See https://github.com/rust-lang/rustup/wiki/Non-host-toolchains
#[arg(long)]
force_non_host: bool,

/// Indicate update status via exit code
#[arg(long)]
check: bool,
},

/// Check for updates to Rust toolchains and rustup
Expand Down Expand Up @@ -493,6 +497,10 @@ struct UpdateOpts {
/// Set the installed toolchain as the default toolchain
#[arg(long)]
default: bool,

/// Indicate update status via exit code
#[arg(long)]
check: bool,
}

#[derive(Debug, Default, Args)]
Expand Down Expand Up @@ -765,6 +773,7 @@ pub async fn main(
allow_downgrade,
force,
force_non_host,
check,
} => {
update(
cfg,
Expand All @@ -774,6 +783,7 @@ pub async fn main(
allow_downgrade,
force,
force_non_host,
check,
..UpdateOpts::default()
},
false,
Expand Down Expand Up @@ -1185,7 +1195,7 @@ async fn update(
info!("it's active because: {}", source.to_reason());
exit_code &= self_update_mode.update(should_self_update, &dl_cfg).await?;
} else {
exit_code &= common::update_all_channels(cfg, opts.force).await?;
exit_code &= common::update_all_channels(cfg, opts.force, opts.check).await?;
exit_code &= self_update_mode.update(should_self_update, &dl_cfg).await?;

info!("cleaning up downloads & tmp directories");
Expand Down
51 changes: 51 additions & 0 deletions tests/suite/cli_rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,57 @@ use rustup::{
utils::raw,
};

#[tokio::test]
async fn update_check_no_updates() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustup", "toolchain", "add", "stable"])
.await
.is_ok();

cx.config
Comment thread
rami3l marked this conversation as resolved.
.expect(["rustup", "update", "--check"])
.await
.is_ok()
.with_stdout(snapbox::str![[r#"

stable-[HOST_TUPLE] unchanged - 1.1.0 (hash-stable-1.1.0)


"#]]);
}

#[tokio::test]
async fn update_check_with_partial_updates() {
let mut cx = CliTestContext::new(Scenario::None).await;

{
let cx = cx.with_dist_dir(Scenario::ArchivesV2_2015_01_01);
cx.config
.expect(["rustup", "toolchain", "add", "stable"])
.await
.is_ok();
}

let cx = cx.with_dist_dir(Scenario::SimpleV2);
cx.config
.expect(["rustup", "toolchain", "add", "beta"])
.await
.is_ok();

cx.config
.expect(["rustup", "update", "--check"])
.await
.has_code(100)
.with_stdout(snapbox::str![[r#"

stable-[HOST_TUPLE] updated - 1.1.0 (hash-stable-1.1.0) (from 1.0.0 (hash-stable-1.0.0))
beta-[HOST_TUPLE] unchanged - 1.2.0 (hash-beta-1.2.0)


"#]]);
}

#[tokio::test]
async fn rustup_stable() {
let mut cx = CliTestContext::new(Scenario::None).await;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 22 additions & 20 deletions tests/suite/cli_rustup_ui/rustup_up_cmd_help_flag.stdout.term.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading