-
Notifications
You must be signed in to change notification settings - Fork 13.4k
warn newer available version of the x tool #104552
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c495558
warn when there's a newer version of the x tool available
DebugSteven b2cd337
remove leading comma from macro expansion
DebugSteven b9b33d9
spawn x command and compare semvers
DebugSteven a917308
remove commented out old code
DebugSteven 7fe2f73
formatting
DebugSteven 02173f6
Update error message
DebugSteven 430ea8d
Update error message
DebugSteven f50ad6c
rename wrapper-version argument for x to differentiate it from the bo…
DebugSteven 5e67ce6
handle error case where --wrapper-version argument doesn't exist
DebugSteven e94354e
fix formatting
DebugSteven d7cac97
combine error branches
DebugSteven e62258e
fix typo
DebugSteven 9aebb1e
improve error message
DebugSteven e9ca663
get latest x version from parsing cargo command
DebugSteven 376dd8a
use cargo_metadata to get x version
DebugSteven 85f649f
no_deps
DebugSteven 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
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
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
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 |
---|---|---|
|
@@ -69,3 +69,4 @@ pub mod ui_tests; | |
pub mod unit_tests; | ||
pub mod unstable_book; | ||
pub mod walk; | ||
pub mod x_version; |
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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use semver::{BuildMetadata, Prerelease, Version}; | ||
use std::io::ErrorKind; | ||
use std::process::{Command, Stdio}; | ||
|
||
pub fn check(bad: &mut bool) { | ||
let result = Command::new("x").arg("--wrapper-version").stdout(Stdio::piped()).spawn(); | ||
// This runs the command inside a temporarily directory. | ||
// This allows us to compare output of result to see if `--wrapper-version` is not a recognized argument to x. | ||
let temp_result = Command::new("x") | ||
.arg("--wrapper-version") | ||
.current_dir(std::env::temp_dir()) | ||
.stdout(Stdio::piped()) | ||
.spawn(); | ||
|
||
let (child, temp_child) = match (result, temp_result) { | ||
(Ok(child), Ok(temp_child)) => (child, temp_child), | ||
// what would it mean if the temp cmd error'd? | ||
(Ok(_child), Err(_e)) => todo!(), | ||
(Err(e), _) => match e.kind() { | ||
ErrorKind::NotFound => return, | ||
_ => return tidy_error!(bad, "failed to run `x`: {}", e), | ||
jyn514 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}; | ||
|
||
let output = child.wait_with_output().unwrap(); | ||
let temp_output = temp_child.wait_with_output().unwrap(); | ||
|
||
if output != temp_output { | ||
return tidy_error!( | ||
bad, | ||
"Current version of x does not support the `--wrapper-version` argument\nConsider updating to the newer version of x by running `cargo install --path src/tools/x`" | ||
); | ||
} | ||
|
||
if output.status.success() { | ||
let version = String::from_utf8_lossy(&output.stdout); | ||
let version = Version::parse(version.trim_end()).unwrap(); | ||
jyn514 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let expected = Version { | ||
major: 0, | ||
minor: 1, | ||
patch: 0, | ||
pre: Prerelease::new("").unwrap(), | ||
build: BuildMetadata::EMPTY, | ||
}; | ||
jyn514 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if version < expected { | ||
return tidy_error!( | ||
bad, | ||
"Current version of x is {version} Consider updating to the newer version of x by running `cargo install --path src/tools/x`" | ||
DebugSteven marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
} | ||
} else { | ||
return tidy_error!(bad, "failed to check version of `x`: {}", output.status); | ||
} | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.