diff options
| author | DebugSteven <debugsteven@gmail.com> | 2022-12-05 16:18:43 -0700 |
|---|---|---|
| committer | DebugSteven <debugsteven@gmail.com> | 2022-12-31 11:38:41 -0700 |
| commit | b9b33d983d83fde3067a28fdd126fd84061e74c8 (patch) | |
| tree | 7038709fd8da993fdaabeffa5e4af30c5a51763c | |
| parent | b2cd3374e9a7ed637b1b5f1a85cb92a7928d712d (diff) | |
| download | rust-b9b33d983d83fde3067a28fdd126fd84061e74c8.tar.gz rust-b9b33d983d83fde3067a28fdd126fd84061e74c8.zip | |
spawn x command and compare semvers
| -rw-r--r-- | Cargo.lock | 5 | ||||
| -rw-r--r-- | src/tools/tidy/Cargo.toml | 1 | ||||
| -rw-r--r-- | src/tools/tidy/src/x_version.rs | 39 |
3 files changed, 33 insertions, 12 deletions
diff --git a/Cargo.lock b/Cargo.lock index f99e58e59b8..8cafdc83d4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4805,9 +4805,9 @@ checksum = "1ef965a420fe14fdac7dd018862966a4c14094f900e1650bbc71ddd7d580c8af" [[package]] name = "semver" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" dependencies = [ "serde", ] @@ -5309,6 +5309,7 @@ dependencies = [ "lazy_static", "miropt-test-tools", "regex", + "semver", "termcolor", "walkdir", ] diff --git a/src/tools/tidy/Cargo.toml b/src/tools/tidy/Cargo.toml index fff83a1d097..5f5ae3a65ef 100644 --- a/src/tools/tidy/Cargo.toml +++ b/src/tools/tidy/Cargo.toml @@ -11,6 +11,7 @@ miropt-test-tools = { path = "../miropt-test-tools" } lazy_static = "1" walkdir = "2" ignore = "0.4.18" +semver = "1.0.14" termcolor = "1.1.3" [[bin]] diff --git a/src/tools/tidy/src/x_version.rs b/src/tools/tidy/src/x_version.rs index 148f97176f9..bbb2662bdcf 100644 --- a/src/tools/tidy/src/x_version.rs +++ b/src/tools/tidy/src/x_version.rs @@ -1,17 +1,36 @@ -use std::process::Command; +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("--version").output(); - let output = match result { - Ok(output) => output, - Err(_e) => todo!(), +pub fn check(bad: &mut bool) { + let result = Command::new("x") + .arg("--version") + .stdout(Stdio::piped()) + .spawn(); + let child = match result { + Ok(child) => child, + Err(e) => match e.kind() { + ErrorKind::NotFound => return (), + _ => return tidy_error!(bad, "{}", e), + }, }; + let output = child.wait_with_output().unwrap(); + if output.status.success() { let version = String::from_utf8_lossy(&output.stdout); - assert_eq!("0.1.0", version.trim_end()); + 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 { + 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`"); + } + } else { + return tidy_error!(bad, "{}", output.status); } - // FIXME: throw some kind of tidy error when the version of x isn't - // greater than or equal to the version we'd expect. - //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`") } |
