1 use semver::{BuildMetadata, Prerelease, Version};
2 use std::io::ErrorKind;
3 use std::process::{Command, Stdio};
5 pub fn check(bad: &mut bool) {
6 let result = Command::new("x").arg("--wrapper-version").stdout(Stdio::piped()).spawn();
7 // This runs the command inside a temporary directory.
8 // This allows us to compare output of result to see if `--wrapper-version` is not a recognized argument to x.
9 let temp_result = Command::new("x")
10 .arg("--wrapper-version")
11 .current_dir(std::env::temp_dir())
12 .stdout(Stdio::piped())
15 let (child, temp_child) = match (result, temp_result) {
16 (Ok(child), Ok(temp_child)) => (child, temp_child),
17 (Err(e), _) | (_, Err(e)) => match e.kind() {
18 ErrorKind::NotFound => return,
19 _ => return tidy_error!(bad, "failed to run `x`: {}", e),
23 let output = child.wait_with_output().unwrap();
24 let temp_output = temp_child.wait_with_output().unwrap();
26 if output != temp_output {
29 "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`"
33 if output.status.success() {
34 let version = String::from_utf8_lossy(&output.stdout);
35 let version = Version::parse(version.trim_end()).unwrap();
36 let expected = Version {
40 pre: Prerelease::new("").unwrap(),
41 build: BuildMetadata::EMPTY,
43 if version < expected {
46 "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`"
50 return tidy_error!(bad, "failed to check version of `x`: {}", output.status);