diff --git a/Cargo.lock b/Cargo.lock index 8cafdc83d4f..784aca237f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4814,9 +4814,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.147" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" dependencies = [ "serde_derive", ] @@ -4833,9 +4833,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.147" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" dependencies = [ "proc-macro2", "quote", @@ -4853,9 +4853,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.85" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" +checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883" dependencies = [ "indexmap", "itoa", @@ -5133,9 +5133,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.102" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ "proc-macro2", "quote", @@ -5310,6 +5310,7 @@ dependencies = [ "miropt-test-tools", "regex", "semver", + "serde_json", "termcolor", "walkdir", ] diff --git a/src/tools/tidy/Cargo.toml b/src/tools/tidy/Cargo.toml index 5f5ae3a65ef..a13ecbe955a 100644 --- a/src/tools/tidy/Cargo.toml +++ b/src/tools/tidy/Cargo.toml @@ -12,6 +12,7 @@ lazy_static = "1" walkdir = "2" ignore = "0.4.18" semver = "1.0.14" +serde_json = "1.0.91" termcolor = "1.1.3" [[bin]] diff --git a/src/tools/tidy/src/x_version.rs b/src/tools/tidy/src/x_version.rs index 868b3d925d3..6cadc18fd3e 100644 --- a/src/tools/tidy/src/x_version.rs +++ b/src/tools/tidy/src/x_version.rs @@ -1,4 +1,5 @@ -use semver::{BuildMetadata, Prerelease, Version}; +use semver::Version; +use serde_json::Value; use std::io::ErrorKind; use std::process::{Command, Stdio}; @@ -33,20 +34,47 @@ pub fn check(bad: &mut bool) { if output.status.success() { let version = String::from_utf8_lossy(&output.stdout); let version = Version::parse(version.trim_end()).unwrap(); - let expected = Version { - major: 0, - minor: 1, - patch: 0, - pre: Prerelease::new("").unwrap(), - build: BuildMetadata::EMPTY, - }; - if version < expected { + + 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, - "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`" + "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 { + let cmd = Command::new("cargo") + .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()) +}