Skip to content

Log versions during self updates #4331

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
39 changes: 39 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ otel = [
]

# Exports code dependent on private interfaces for the integration test suite
test = ["dep:walkdir"]
test = ["dep:similar-asserts", "dep:walkdir"]

# Sorted by alphabetic order
[dependencies]
Expand Down Expand Up @@ -77,6 +77,7 @@ semver = "1.0"
serde = { version = "1.0", features = ["derive"] }
sha2 = "0.10"
sharded-slab = "0.1.1"
similar-asserts = { version = "1.7", optional = true } # test-only
strsim = "0.11"
tar = "0.4.26"
tempfile = "3.8"
Expand Down
4 changes: 2 additions & 2 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ pub(crate) async fn prepare_update(process: &Process) -> Result<Option<PathBuf>>
let current_version = env!("CARGO_PKG_VERSION");

// Get available version
info!("checking for self-update");
info!("checking for self-update (current version: {current_version})");
let available_version = if let Some(ver) = non_empty_env_var("RUSTUP_VERSION", process)? {
info!("`RUSTUP_VERSION` has been set to `{ver}`");
ver
Expand All @@ -1158,7 +1158,7 @@ pub(crate) async fn prepare_update(process: &Process) -> Result<Option<PathBuf>>
let download_url = utils::parse_url(&url)?;

// Download new version
info!("downloading self-update");
info!("downloading self-update (new version: {available_version})");
download_file(&download_url, &setup_path, None, &|_| (), process).await?;

// Mark as executable
Expand Down
46 changes: 28 additions & 18 deletions src/test/clitools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::{
};

use enum_map::{Enum, EnumMap, enum_map};
use similar_asserts::SimpleDiff;
use tempfile::TempDir;
use url::Url;

Expand Down Expand Up @@ -236,12 +237,14 @@ impl Config {
let out = self.run(args[0], &args[1..], env).await;
if !out.ok || out.stdout != stdout || out.stderr != stderr {
print_command(args, &out);
println!("expected.ok: true");
print_indented("expected.stdout", stdout);
print_indented("expected.stderr", stderr);
dbg!(out.stdout == stdout);
dbg!(out.stderr == stderr);
panic!();
print_diff(stdout, &out.stdout);
print_diff(stderr, &out.stderr);
panic!(
"expected OK, differences found: ok = {}, stdout = {}, stderr = {}",
out.ok,
out.stdout == stdout,
out.stderr == stderr
);
}
}

Expand All @@ -250,18 +253,14 @@ impl Config {
let out = self.run(args[0], &args[1..], &[]).await;
if out.ok || out.stdout != stdout || out.stderr != stderr {
print_command(args, &out);
println!("expected.ok: false");
print_indented("expected.stdout", stdout);
print_indented("expected.stderr", stderr);
if out.ok {
panic!("expected command to fail");
} else if out.stdout != stdout {
panic!("expected stdout to match");
} else if out.stderr != stderr {
panic!("expected stderr to match");
} else {
unreachable!()
}
print_diff(stdout, &out.stdout);
print_diff(stderr, &out.stderr);
panic!(
"expected error, differences found: ok = {}, stdout = {}, stderr = {}",
out.ok,
out.stdout == stdout,
out.stderr == stderr
);
}
}

Expand Down Expand Up @@ -430,6 +429,17 @@ impl Config {
}
}

fn print_diff(expected: &str, actual: &str) {
if expected == actual {
return;
}

println!(
"{}",
SimpleDiff::from_str(expected, actual, "expected", "actual")
);
}

// Describes all the features of the mock dist server.
// Building the mock server is slow, so use simple scenario when possible.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Enum)]
Expand Down
5 changes: 3 additions & 2 deletions tests/suite/cli_exact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ info: installing component 'rustc'
#[tokio::test]
async fn update_once_and_self_update() {
let test_version = "2.0.0";
let current = env!("CARGO_PKG_VERSION");
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
let _dist_guard = cx.with_update_server(test_version);
cx.config
Expand Down Expand Up @@ -111,8 +112,8 @@ info: installing component 'cargo'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: checking for self-update
info: downloading self-update
info: checking for self-update (current version: {current})
info: downloading self-update (new version: 2.0.0)
"
),
)
Expand Down
15 changes: 8 additions & 7 deletions tests/suite/cli_self_upd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,11 @@ struct GcErr(Vec<String>);
#[tokio::test]
async fn update_exact() {
let version = env!("CARGO_PKG_VERSION");
let expected_output = "info: checking for self-update
info: downloading self-update
let expected_output = format!(
"info: checking for self-update (current version: {version})
info: downloading self-update (new version: {TEST_VERSION})
"
.to_string();
);

let mut cx = SelfUpdateTestContext::new(TEST_VERSION).await;
cx.config
Expand All @@ -391,7 +392,7 @@ async fn update_precise() {
let expected_output = format!(
"info: checking for self-update
info: `RUSTUP_VERSION` has been set to `{TEST_VERSION}`
info: downloading self-update
info: downloading self-update (new version: {TEST_VERSION})
"
);

Expand Down Expand Up @@ -563,7 +564,7 @@ async fn update_no_change() {

"
),
r"info: checking for self-update
r"info: checking for self-update (current version: {version})
",
)
.await;
Expand Down Expand Up @@ -647,8 +648,8 @@ async fn rustup_self_update_exact() {
),
for_host!(
r"info: syncing channel updates for 'stable-{0}'
info: checking for self-update
info: downloading self-update
info: checking for self-update (current version: {TEST_VERSION})
info: downloading self-update (new version: {TEST_VERSION})
info: cleaning up downloads & tmp directories
"
),
Expand Down
Loading