use cargo_metadata to get x version
This commit is contained in:
parent
e9ca6636e1
commit
376dd8a9b3
@ -5310,7 +5310,6 @@ dependencies = [
|
|||||||
"miropt-test-tools",
|
"miropt-test-tools",
|
||||||
"regex",
|
"regex",
|
||||||
"semver",
|
"semver",
|
||||||
"serde_json",
|
|
||||||
"termcolor",
|
"termcolor",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
@ -12,7 +12,6 @@ lazy_static = "1"
|
|||||||
walkdir = "2"
|
walkdir = "2"
|
||||||
ignore = "0.4.18"
|
ignore = "0.4.18"
|
||||||
semver = "1.0.14"
|
semver = "1.0.14"
|
||||||
serde_json = "1.0.91"
|
|
||||||
termcolor = "1.1.3"
|
termcolor = "1.1.3"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
|
@ -107,7 +107,7 @@ macro_rules! check {
|
|||||||
check!(alphabetical, &compiler_path);
|
check!(alphabetical, &compiler_path);
|
||||||
check!(alphabetical, &library_path);
|
check!(alphabetical, &library_path);
|
||||||
|
|
||||||
check!(x_version);
|
check!(x_version, &root_path, &cargo);
|
||||||
|
|
||||||
let collected = {
|
let collected = {
|
||||||
drain_handles(&mut handles);
|
drain_handles(&mut handles);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use semver::Version;
|
use semver::Version;
|
||||||
use serde_json::Value;
|
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
|
use std::path::Path;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
pub fn check(bad: &mut bool) {
|
pub fn check(root: &Path, cargo: &Path, bad: &mut bool) {
|
||||||
let result = Command::new("x").arg("--wrapper-version").stdout(Stdio::piped()).spawn();
|
let result = Command::new("x").arg("--wrapper-version").stdout(Stdio::piped()).spawn();
|
||||||
// This runs the command inside a temporary directory.
|
// 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.
|
// This allows us to compare output of result to see if `--wrapper-version` is not a recognized argument to x.
|
||||||
@ -35,7 +35,7 @@ pub fn check(bad: &mut bool) {
|
|||||||
let version = String::from_utf8_lossy(&output.stdout);
|
let version = String::from_utf8_lossy(&output.stdout);
|
||||||
let version = Version::parse(version.trim_end()).unwrap();
|
let version = Version::parse(version.trim_end()).unwrap();
|
||||||
|
|
||||||
if let Some(expected) = get_x_wrapper_version() {
|
if let Some(expected) = get_x_wrapper_version(root, cargo) {
|
||||||
if version < expected {
|
if version < expected {
|
||||||
return tidy_error!(
|
return tidy_error!(
|
||||||
bad,
|
bad,
|
||||||
@ -54,27 +54,11 @@ pub fn check(bad: &mut bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse latest version out of `x` Cargo.toml
|
// Parse latest version out of `x` Cargo.toml
|
||||||
fn get_x_wrapper_version() -> Option<Version> {
|
fn get_x_wrapper_version(root: &Path, cargo: &Path) -> Option<Version> {
|
||||||
let cmd = Command::new("cargo")
|
let mut cmd = cargo_metadata::MetadataCommand::new();
|
||||||
.arg("metadata")
|
cmd.cargo_path(cargo)
|
||||||
.args(["--no-deps", "--format-version", "1", "--manifest-path", "src/tools/x/Cargo.toml"])
|
.manifest_path(root.join("src/tools/x/Cargo.toml"))
|
||||||
.stdout(Stdio::piped())
|
.features(cargo_metadata::CargoOpt::AllFeatures);
|
||||||
.spawn();
|
let mut metadata = t!(cmd.exec());
|
||||||
|
metadata.packages.pop().map(|x| x.version)
|
||||||
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())
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user