-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(toolchain): include err in rustc_version output #4741
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
Draft
Bogay
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
Bogay:improve-rustc-version-error-message
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+37
−29
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -284,47 +284,55 @@ impl<'a> Toolchain<'a> { | |
| #[tracing::instrument(level = "trace")] | ||
| pub fn rustc_version(&self) -> String { | ||
| match self.create_command("rustc") { | ||
| Err(e) => format!("(rustc does not exist: {e})"), | ||
| Ok(mut cmd) => { | ||
| cmd.arg("--version"); | ||
| cmd.stdin(Stdio::null()); | ||
| cmd.stdout(Stdio::piped()); | ||
| cmd.stderr(Stdio::piped()); | ||
| self.set_ldpath(&mut cmd); | ||
|
|
||
| // some toolchains are faulty with some combinations of platforms and | ||
| // may fail to launch but also to timely terminate. | ||
| // (known cases include Rust 1.3.0 through 1.10.0 in recent macOS Sierra.) | ||
| // we guard against such cases by enforcing a reasonable timeout to read. | ||
| let mut line1 = None; | ||
| if let Ok(mut child) = cmd.spawn() { | ||
| let timeout = Duration::new(10, 0); | ||
| match child.wait_timeout(timeout) { | ||
| Ok(Some(status)) if status.success() => { | ||
| let out = child | ||
| .stdout | ||
| .expect("Child::stdout requested but not present"); | ||
| let mut line = String::new(); | ||
| if BufReader::new(out).read_line(&mut line).is_ok() { | ||
| let lineend = line.trim_end_matches(&['\r', '\n'][..]).len(); | ||
| line.truncate(lineend); | ||
| line1 = Some(line); | ||
| match cmd.spawn() { | ||
|
Comment on lines
294
to
+295
Member
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. Nit: could try to reduce some rightward drift here and in sections below. Something along the lines of: let mut child = match cmd.spawn() {
Err(e) => return format!("(error reading rustc version: {e})"),
Ok(child) => child,
};
[..] |
||
| Err(e) => { | ||
| format!("(error reading rustc version: {e})") | ||
| } | ||
| // some toolchains are faulty with some combinations of platforms and | ||
| // may fail to launch but also to timely terminate. | ||
| // (known cases include Rust 1.3.0 through 1.10.0 in recent macOS Sierra.) | ||
| // we guard against such cases by enforcing a reasonable timeout to read. | ||
| Ok(mut child) => { | ||
| let timeout = Duration::new(10, 0); | ||
| match child.wait_timeout(timeout) { | ||
| Ok(None) => { | ||
| let _ = child.kill(); | ||
| String::from("(timeout reading rustc version)") | ||
| } | ||
| Err(e) => { | ||
| format!("(error reading rustc version: {e})") | ||
| } | ||
| Ok(Some(status)) => { | ||
| if !status.success() { | ||
| return format!("(error reading rustc version: {status})"); | ||
| } | ||
|
|
||
| let out = child | ||
| .stdout | ||
| .expect("Child::stdout requested but not present"); | ||
| let mut line = String::new(); | ||
| match BufReader::new(out).read_line(&mut line) { | ||
| Ok(_) => { | ||
| let lineend = | ||
| line.trim_end_matches(&['\r', '\n'][..]).len(); | ||
| line.truncate(lineend); | ||
| line | ||
| } | ||
| Err(e) => format!("(error reading rustc version: {e})"), | ||
| } | ||
| } | ||
| } | ||
| Ok(None) => { | ||
| let _ = child.kill(); | ||
| return String::from("(timeout reading rustc version)"); | ||
| } | ||
| Ok(Some(_)) | Err(_) => {} | ||
| } | ||
| } | ||
|
|
||
| if let Some(line1) = line1 { | ||
| line1 | ||
| } else { | ||
| String::from("(error reading rustc version)") | ||
| } | ||
| } | ||
| Err(_) => String::from("(rustc does not exist)"), | ||
| } | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest adding some snapshot tests to better demonstrate this new feature.