-
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
Changes from 14 commits
c495558
b2cd337
b9b33d9
a917308
7fe2f73
02173f6
430ea8d
f50ad6c
5e67ce6
e94354e
d7cac97
e62258e
9aebb1e
e9ca663
376dd8a
85f649f
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 |
---|---|---|
|
@@ -69,3 +69,4 @@ pub mod ui_tests; | |
pub mod unit_tests; | ||
pub mod unstable_book; | ||
pub mod walk; | ||
pub mod x_version; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,80 @@ | ||||||||||||||||||
use semver::Version; | ||||||||||||||||||
use serde_json::Value; | ||||||||||||||||||
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 temporary 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), | ||||||||||||||||||
(Err(e), _) | (_, Err(e)) => match e.kind() { | ||||||||||||||||||
ErrorKind::NotFound => return, | ||||||||||||||||||
_ => return tidy_error!(bad, "failed to run `x`: {}", e), | ||||||||||||||||||
}, | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
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(); | ||||||||||||||||||
|
||||||||||||||||||
if let Some(expected) = get_x_wrapper_version() { | ||||||||||||||||||
if version < expected { | ||||||||||||||||||
return tidy_error!( | ||||||||||||||||||
bad, | ||||||||||||||||||
"Current version of x is {version}, but the latest version is {expected}\nConsider updating to the newer version of x by running `cargo install --path src/tools/x`" | ||||||||||||||||||
); | ||||||||||||||||||
} | ||||||||||||||||||
} else { | ||||||||||||||||||
return tidy_error!( | ||||||||||||||||||
bad, | ||||||||||||||||||
"Unable to parse the latest version of `x` at `src/tools/x/Cargo.toml`" | ||||||||||||||||||
); | ||||||||||||||||||
} | ||||||||||||||||||
} else { | ||||||||||||||||||
return tidy_error!(bad, "failed to check version of `x`: {}", output.status); | ||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
// Parse latest version out of `x` Cargo.toml | ||||||||||||||||||
fn get_x_wrapper_version() -> Option<Version> { | ||||||||||||||||||
let cmd = Command::new("cargo") | ||||||||||||||||||
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. Do we know this will be run from the root of the rust-lang/rust checkout? 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. You can test by running 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. err sorry - actually can you use rust/src/tools/tidy/src/deps.rs Lines 347 to 354 in e9ca663
root as an argument which avoids this question altogether.
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. Running both of the above commands didn't end up working for me, even with the new change to use I end up getting tidy errors for autogenerated files in the build directory... This seems like a separate issue though.
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. ah yeah that's from when I asked you to test |
||||||||||||||||||
.arg("metadata") | ||||||||||||||||||
.args(["--no-deps", "--format-version", "1", "--manifest-path", "src/tools/x/Cargo.toml"]) | ||||||||||||||||||
.stdout(Stdio::piped()) | ||||||||||||||||||
.spawn(); | ||||||||||||||||||
|
||||||||||||||||||
let child = match cmd { | ||||||||||||||||||
Ok(child) => child, | ||||||||||||||||||
Err(e) => { | ||||||||||||||||||
println!("failed to get version of `x`: {}", e); | ||||||||||||||||||
return None; | ||||||||||||||||||
} | ||||||||||||||||||
}; | ||||||||||||||||||
|
||||||||||||||||||
let cargo_output = child.wait_with_output().unwrap(); | ||||||||||||||||||
let cargo_output_str = | ||||||||||||||||||
String::from_utf8(cargo_output.stdout).expect("Unable to parse `src/tools/x/Cargo.toml`"); | ||||||||||||||||||
|
||||||||||||||||||
let v: Value = serde_json::from_str(&cargo_output_str).unwrap(); | ||||||||||||||||||
let vesrion_str = &v["packages"][0]["version"].as_str()?; | ||||||||||||||||||
|
||||||||||||||||||
Some(Version::parse(vesrion_str).unwrap()) | ||||||||||||||||||
} |
Uh oh!
There was an error while loading. Please reload this page.