Skip to content

Commit b9b33d9

Browse files
committed
spawn x command and compare semvers
1 parent b2cd337 commit b9b33d9

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

Cargo.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4805,9 +4805,9 @@ checksum = "1ef965a420fe14fdac7dd018862966a4c14094f900e1650bbc71ddd7d580c8af"
48054805

48064806
[[package]]
48074807
name = "semver"
4808-
version = "1.0.12"
4808+
version = "1.0.14"
48094809
source = "registry+https://github.com/rust-lang/crates.io-index"
4810-
checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1"
4810+
checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4"
48114811
dependencies = [
48124812
"serde",
48134813
]
@@ -5309,6 +5309,7 @@ dependencies = [
53095309
"lazy_static",
53105310
"miropt-test-tools",
53115311
"regex",
5312+
"semver",
53125313
"termcolor",
53135314
"walkdir",
53145315
]

src/tools/tidy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ miropt-test-tools = { path = "../miropt-test-tools" }
1111
lazy_static = "1"
1212
walkdir = "2"
1313
ignore = "0.4.18"
14+
semver = "1.0.14"
1415
termcolor = "1.1.3"
1516

1617
[[bin]]

src/tools/tidy/src/x_version.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
1-
use std::process::Command;
1+
use semver::{BuildMetadata, Prerelease, Version};
2+
use std::io::ErrorKind;
3+
use std::process::{Command, Stdio};
24

3-
pub fn check(_bad: &mut bool) {
4-
let result = Command::new("x").arg("--version").output();
5-
let output = match result {
6-
Ok(output) => output,
7-
Err(_e) => todo!(),
5+
pub fn check(bad: &mut bool) {
6+
let result = Command::new("x")
7+
.arg("--version")
8+
.stdout(Stdio::piped())
9+
.spawn();
10+
let child = match result {
11+
Ok(child) => child,
12+
Err(e) => match e.kind() {
13+
ErrorKind::NotFound => return (),
14+
_ => return tidy_error!(bad, "{}", e),
15+
},
816
};
917

18+
let output = child.wait_with_output().unwrap();
19+
1020
if output.status.success() {
1121
let version = String::from_utf8_lossy(&output.stdout);
12-
assert_eq!("0.1.0", version.trim_end());
22+
let version = Version::parse(version.trim_end()).unwrap();
23+
let expected = Version {
24+
major: 0,
25+
minor: 1,
26+
patch: 0,
27+
pre: Prerelease::new("").unwrap(),
28+
build: BuildMetadata::EMPTY,
29+
};
30+
if version < expected {
31+
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`");
32+
}
33+
} else {
34+
return tidy_error!(bad, "{}", output.status);
1335
}
14-
// FIXME: throw some kind of tidy error when the version of x isn't
15-
// greater than or equal to the version we'd expect.
16-
//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`")
1736
}

0 commit comments

Comments
 (0)