-
Notifications
You must be signed in to change notification settings - Fork 1k
Make component removal best-effort and order-independent #4797
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| #![allow(clippy::large_enum_variant)] | ||
|
|
||
| use std::ffi::OsString; | ||
| use std::fmt::Debug; | ||
| use std::fmt::{Debug, Write as FmtWrite}; | ||
| use std::io; | ||
| use std::io::Write; | ||
| use std::path::PathBuf; | ||
|
|
@@ -134,6 +134,11 @@ pub enum RustupError { | |
| component: String, | ||
| suggestion: Option<String>, | ||
| }, | ||
| #[error("{}", unknown_components_msg(.desc, .components))] | ||
| UnknownComponents { | ||
| desc: ToolchainDesc, | ||
| components: Vec<(String, Option<String>)>, | ||
| }, | ||
| #[error( | ||
| "toolchain '{desc}' has no prebuilt artifacts available for target '{platform}'\n\ | ||
| note: this may happen to a low-tier target as per https://doc.rust-lang.org/nightly/rustc/platform-support.html\n\ | ||
|
|
@@ -242,3 +247,27 @@ fn component_unavailable_msg(cs: &[Component], manifest: &Manifest, toolchain: & | |
|
|
||
| String::from_utf8(buf).unwrap() | ||
| } | ||
|
|
||
| fn unknown_components_msg(desc: &ToolchainDesc, components: &[(String, Option<String>)]) -> String { | ||
| let mut buf = String::new(); | ||
|
|
||
| match components { | ||
| [] => panic!("`unknown_components_msg` should not be called with an empty collection"), | ||
| [(component, suggestion)] => { | ||
| let _ = write!( | ||
| buf, | ||
| "toolchain '{desc}' does not contain component '{component}'{}", | ||
| suggest_message(suggestion), | ||
|
Comment on lines
+259
to
+260
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if we insert a newline before calling
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I will update this. |
||
| ); | ||
| } | ||
| components => { | ||
| let _ = writeln!(buf, "toolchain '{desc}' does not contain these components:"); | ||
|
|
||
| for (component, suggestion) in components { | ||
| let _ = writeln!(buf, " - '{component}'{}", suggest_message(suggestion),); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| buf | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2136,6 +2136,145 @@ async fn add_remove_multiple_components() { | |
| } | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn remove_multiple_components_is_best_effort_and_order_independent() { | ||
| let files = [ | ||
| "lib/rustlib/src/rust-src/foo.rs".to_owned(), | ||
| format!("lib/rustlib/{}/analysis/libfoo.json", this_host_triple()), | ||
| ]; | ||
|
|
||
| // Case 1: invalid component first | ||
| let cx = CliTestContext::new(Scenario::SimpleV2).await; | ||
| cx.config | ||
| .expect(&["rustup", "default", "nightly"]) | ||
| .await | ||
| .is_ok(); | ||
| cx.config | ||
| .expect(&["rustup", "component", "add", "rust-src", "rust-analysis"]) | ||
| .await | ||
| .is_ok(); | ||
|
|
||
| for file in &files { | ||
| let path = format!("toolchains/nightly-{}/{}", this_host_triple(), file); | ||
| assert!(cx.config.rustupdir.has(&path)); | ||
| } | ||
|
|
||
| cx.config | ||
| .expect(&[ | ||
| "rustup", | ||
| "component", | ||
| "remove", | ||
| "bad-component", | ||
| "rust-src", | ||
| "rust-analysis", | ||
| ]) | ||
| .await | ||
| .is_err(); | ||
|
|
||
| for file in &files { | ||
| let path = PathBuf::from(format!( | ||
| "toolchains/nightly-{}/{}", | ||
| this_host_triple(), | ||
| file | ||
| )); | ||
| assert!(!cx.config.rustupdir.has(path.parent().unwrap())); | ||
| } | ||
|
|
||
| // Case 2: invalid component last | ||
| let cx = CliTestContext::new(Scenario::SimpleV2).await; | ||
| cx.config | ||
| .expect(&["rustup", "default", "nightly"]) | ||
| .await | ||
| .is_ok(); | ||
| cx.config | ||
| .expect(&["rustup", "component", "add", "rust-src", "rust-analysis"]) | ||
| .await | ||
| .is_ok(); | ||
|
|
||
| for file in &files { | ||
| let path = format!("toolchains/nightly-{}/{}", this_host_triple(), file); | ||
| assert!(cx.config.rustupdir.has(&path)); | ||
| } | ||
|
|
||
| cx.config | ||
| .expect(&[ | ||
| "rustup", | ||
| "component", | ||
| "remove", | ||
| "rust-src", | ||
| "rust-analysis", | ||
| "bad-component", | ||
| ]) | ||
| .await | ||
| .is_err(); | ||
|
|
||
| for file in &files { | ||
| let path = PathBuf::from(format!( | ||
| "toolchains/nightly-{}/{}", | ||
| this_host_triple(), | ||
| file | ||
| )); | ||
| assert!(!cx.config.rustupdir.has(path.parent().unwrap())); | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should also be a third case in which a valid component appears between invalid ones, ensuring that errors are correctly reported for both invalid components.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That’s a useful edge case to cover. I will add it to the test. |
||
|
|
||
| #[tokio::test] | ||
| async fn remove_multiple_components_reports_all_invalid_names() { | ||
| let files = [ | ||
| "lib/rustlib/src/rust-src/foo.rs".to_owned(), | ||
| format!("lib/rustlib/{}/analysis/libfoo.json", this_host_triple()), | ||
| ]; | ||
|
|
||
| let cx = CliTestContext::new(Scenario::SimpleV2).await; | ||
| cx.config | ||
| .expect(["rustup", "default", "nightly"]) | ||
| .await | ||
| .is_ok(); | ||
|
|
||
| cx.config | ||
| .expect(["rustup", "component", "add", "rust-src", "rust-analysis"]) | ||
| .await | ||
| .is_ok(); | ||
|
|
||
| // Ensure components exist | ||
| for file in &files { | ||
| let path = format!("toolchains/nightly-{}/{}", this_host_triple(), file); | ||
| assert!(cx.config.rustupdir.has(&path)); | ||
| } | ||
|
|
||
| cx.config | ||
| .expect([ | ||
| "rustup", | ||
| "component", | ||
| "remove", | ||
| "bad-component-1", | ||
| "rust-src", | ||
| "bad-component-2", | ||
| "rust-analysis", | ||
| ]) | ||
| .await | ||
| .with_stderr(snapbox::str![[r#" | ||
| info: removing component rust-src | ||
| info: removing component rust-analysis | ||
| error: toolchain 'nightly-[HOST_TRIPLE]' does not contain these components: | ||
| - 'bad-component-1' | ||
| - 'bad-component-2' | ||
|
|
||
|
|
||
| "#]]) | ||
| .is_err(); | ||
|
|
||
| // Ensure valid components were removed | ||
| for file in &files { | ||
| let path = PathBuf::from(format!( | ||
| "toolchains/nightly-{}/{}", | ||
| this_host_triple(), | ||
| file | ||
| )); | ||
| assert!(!cx.config.rustupdir.has(path.parent().unwrap())); | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn file_override() { | ||
| let cx = CliTestContext::new(Scenario::SimpleV2).await; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.