From c49555821f9735239bf12281b9151eac3b4596d4 Mon Sep 17 00:00:00 2001 From: DebugSteven Date: Thu, 17 Nov 2022 13:21:36 -0700 Subject: [PATCH 01/16] warn when there's a newer version of the x tool available --- src/tools/tidy/src/lib.rs | 1 + src/tools/tidy/src/main.rs | 20 +++++++++++++++++++- src/tools/tidy/src/x.rs | 19 +++++++++++++++++++ src/tools/x/src/main.rs | 8 ++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/tools/tidy/src/x.rs diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs index ce7e7ac5cd4ca..bfcf0907365ad 100644 --- a/src/tools/tidy/src/lib.rs +++ b/src/tools/tidy/src/lib.rs @@ -69,3 +69,4 @@ pub mod ui_tests; pub mod unit_tests; pub mod unstable_book; pub mod walk; +pub mod x; diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs index 6714c63ee62a1..f01d4673368e9 100644 --- a/src/tools/tidy/src/main.rs +++ b/src/tools/tidy/src/main.rs @@ -53,6 +53,21 @@ fn main() { VecDeque::with_capacity(concurrency.get()); macro_rules! check { + ($p:ident) => { + while handles.len() >= concurrency.get() { + handles.pop_front().unwrap().join().unwrap(); + } + + let handle = s.spawn(|| { + let mut flag = false; + $p::check(&mut flag); + if (flag) { + bad.store(true, Ordering::Relaxed); + } + }); + handles.push_back(handle); + }; + ($p:ident $(, $args:expr)* ) => { drain_handles(&mut handles); @@ -64,7 +79,8 @@ fn main() { } }); handles.push_back(handle); - } + }; + } check!(target_specific_tests, &src_path); @@ -107,6 +123,8 @@ fn main() { check!(alphabetical, &compiler_path); check!(alphabetical, &library_path); + check!(x); + let collected = { drain_handles(&mut handles); diff --git a/src/tools/tidy/src/x.rs b/src/tools/tidy/src/x.rs new file mode 100644 index 0000000000000..2cbbde8de8246 --- /dev/null +++ b/src/tools/tidy/src/x.rs @@ -0,0 +1,19 @@ +use std::process::Command; + +pub fn check(_bad: &mut bool) { + let result = Command::new("x") + .arg("--version") + .output(); + let output = match result { + Ok(output) => output, + Err(_e) => todo!(), + }; + + if output.status.success() { + let version = String::from_utf8_lossy(&output.stdout); + assert_eq!("0.1.0", version.trim_end()); + } + // 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`") +} diff --git a/src/tools/x/src/main.rs b/src/tools/x/src/main.rs index f07ff43efe987..db5d03710d762 100644 --- a/src/tools/x/src/main.rs +++ b/src/tools/x/src/main.rs @@ -52,6 +52,14 @@ fn exec_or_status(command: &mut Command) -> io::Result { } fn main() { + match env::args().skip(1).next().as_deref() { + Some("--version") => { + let version = env!("CARGO_PKG_VERSION"); + println!("{}", version); + return; + } + _ => {} + } let current = match env::current_dir() { Ok(dir) => dir, Err(err) => { From b2cd3374e9a7ed637b1b5f1a85cb92a7928d712d Mon Sep 17 00:00:00 2001 From: DebugSteven Date: Mon, 28 Nov 2022 16:08:00 -0700 Subject: [PATCH 02/16] remove leading comma from macro expansion --- src/bootstrap/bootstrap.py | 4 ++-- src/tools/tidy/src/lib.rs | 2 +- src/tools/tidy/src/main.rs | 22 +++------------------- src/tools/tidy/src/{x.rs => x_version.rs} | 4 +--- 4 files changed, 7 insertions(+), 25 deletions(-) rename src/tools/tidy/src/{x.rs => x_version.rs} (88%) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 9cf43fc7a2193..d7ba015982a45 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -934,8 +934,8 @@ def main(): if len(sys.argv) > 1 and sys.argv[1] == 'help': sys.argv = [sys.argv[0], '-h'] + sys.argv[2:] - help_triggered = ( - '-h' in sys.argv) or ('--help' in sys.argv) or (len(sys.argv) == 1) + # help_triggered = ('-h' in sys.argv) or ('--help' in sys.argv) or (len(sys.argv) == 1) + help_triggered = len(sys.argv) == 1 or any(x in ["-h", "--help", "--version"] for x in sys.argv) try: bootstrap(help_triggered) if not help_triggered: diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs index bfcf0907365ad..4075f2616b0fd 100644 --- a/src/tools/tidy/src/lib.rs +++ b/src/tools/tidy/src/lib.rs @@ -69,4 +69,4 @@ pub mod ui_tests; pub mod unit_tests; pub mod unstable_book; pub mod walk; -pub mod x; +pub mod x_version; diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs index f01d4673368e9..56fcc561a3f89 100644 --- a/src/tools/tidy/src/main.rs +++ b/src/tools/tidy/src/main.rs @@ -53,34 +53,18 @@ fn main() { VecDeque::with_capacity(concurrency.get()); macro_rules! check { - ($p:ident) => { - while handles.len() >= concurrency.get() { - handles.pop_front().unwrap().join().unwrap(); - } - - let handle = s.spawn(|| { - let mut flag = false; - $p::check(&mut flag); - if (flag) { - bad.store(true, Ordering::Relaxed); - } - }); - handles.push_back(handle); - }; - ($p:ident $(, $args:expr)* ) => { drain_handles(&mut handles); let handle = s.spawn(|| { let mut flag = false; - $p::check($($args),* , &mut flag); + $p::check($($args, )* &mut flag); if (flag) { bad.store(true, Ordering::Relaxed); } }); handles.push_back(handle); - }; - + } } check!(target_specific_tests, &src_path); @@ -123,7 +107,7 @@ fn main() { check!(alphabetical, &compiler_path); check!(alphabetical, &library_path); - check!(x); + check!(x_version); let collected = { drain_handles(&mut handles); diff --git a/src/tools/tidy/src/x.rs b/src/tools/tidy/src/x_version.rs similarity index 88% rename from src/tools/tidy/src/x.rs rename to src/tools/tidy/src/x_version.rs index 2cbbde8de8246..148f97176f969 100644 --- a/src/tools/tidy/src/x.rs +++ b/src/tools/tidy/src/x_version.rs @@ -1,9 +1,7 @@ use std::process::Command; pub fn check(_bad: &mut bool) { - let result = Command::new("x") - .arg("--version") - .output(); + let result = Command::new("x").arg("--version").output(); let output = match result { Ok(output) => output, Err(_e) => todo!(), From b9b33d983d83fde3067a28fdd126fd84061e74c8 Mon Sep 17 00:00:00 2001 From: DebugSteven Date: Mon, 5 Dec 2022 16:18:43 -0700 Subject: [PATCH 03/16] spawn x command and compare semvers --- Cargo.lock | 5 +++-- src/tools/tidy/Cargo.toml | 1 + src/tools/tidy/src/x_version.rs | 39 ++++++++++++++++++++++++--------- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f99e58e59b8e5..8cafdc83d4f4d 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 fff83a1d097b3..5f5ae3a65efa8 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 148f97176f969..bbb2662bdcf68 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`") } From a917308d9180b3203c1e65a394c28c7e7d92b9bb Mon Sep 17 00:00:00 2001 From: DebugSteven Date: Mon, 5 Dec 2022 16:19:10 -0700 Subject: [PATCH 04/16] remove commented out old code --- src/bootstrap/bootstrap.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index d7ba015982a45..f3998e98583ec 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -934,7 +934,6 @@ def main(): if len(sys.argv) > 1 and sys.argv[1] == 'help': sys.argv = [sys.argv[0], '-h'] + sys.argv[2:] - # help_triggered = ('-h' in sys.argv) or ('--help' in sys.argv) or (len(sys.argv) == 1) help_triggered = len(sys.argv) == 1 or any(x in ["-h", "--help", "--version"] for x in sys.argv) try: bootstrap(help_triggered) From 7fe2f73ecdde41ec3bc0bd9bfdee5cd064536d53 Mon Sep 17 00:00:00 2001 From: DebugSteven Date: Mon, 5 Dec 2022 16:42:08 -0700 Subject: [PATCH 05/16] formatting --- src/tools/tidy/src/x_version.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tools/tidy/src/x_version.rs b/src/tools/tidy/src/x_version.rs index bbb2662bdcf68..c54414836ed77 100644 --- a/src/tools/tidy/src/x_version.rs +++ b/src/tools/tidy/src/x_version.rs @@ -3,14 +3,11 @@ use std::io::ErrorKind; use std::process::{Command, Stdio}; pub fn check(bad: &mut bool) { - let result = Command::new("x") - .arg("--version") - .stdout(Stdio::piped()) - .spawn(); + 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 (), + ErrorKind::NotFound => return, _ => return tidy_error!(bad, "{}", e), }, }; @@ -28,7 +25,10 @@ pub fn check(bad: &mut bool) { 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`"); + 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); From 02173f6ab514cf98b73f053cbc0e7b9881c18783 Mon Sep 17 00:00:00 2001 From: J Haigh Date: Wed, 7 Dec 2022 13:28:57 -0700 Subject: [PATCH 06/16] Update error message Co-authored-by: Joshua Nelson --- src/tools/tidy/src/x_version.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tidy/src/x_version.rs b/src/tools/tidy/src/x_version.rs index c54414836ed77..df9d780ea148a 100644 --- a/src/tools/tidy/src/x_version.rs +++ b/src/tools/tidy/src/x_version.rs @@ -8,7 +8,7 @@ pub fn check(bad: &mut bool) { Ok(child) => child, Err(e) => match e.kind() { ErrorKind::NotFound => return, - _ => return tidy_error!(bad, "{}", e), + _ => return tidy_error!(bad, "failed to run `x`: {}", e), }, }; From 430ea8d440f5fc22dec7c4b6bda0536ae38baa00 Mon Sep 17 00:00:00 2001 From: J Haigh Date: Wed, 7 Dec 2022 13:29:10 -0700 Subject: [PATCH 07/16] Update error message Co-authored-by: Joshua Nelson --- src/tools/tidy/src/x_version.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tidy/src/x_version.rs b/src/tools/tidy/src/x_version.rs index df9d780ea148a..f0c7a308cfae6 100644 --- a/src/tools/tidy/src/x_version.rs +++ b/src/tools/tidy/src/x_version.rs @@ -31,6 +31,6 @@ pub fn check(bad: &mut bool) { ); } } else { - return tidy_error!(bad, "{}", output.status); + return tidy_error!(bad, "failed to check version of `x`: {}", output.status); } } From f50ad6cd8ce48c8f159bee064ba9ae9dd28f6868 Mon Sep 17 00:00:00 2001 From: DebugSteven Date: Wed, 7 Dec 2022 14:00:40 -0700 Subject: [PATCH 08/16] rename wrapper-version argument for x to differentiate it from the bootstrap version --- src/tools/tidy/src/x_version.rs | 2 +- src/tools/x/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/tidy/src/x_version.rs b/src/tools/tidy/src/x_version.rs index f0c7a308cfae6..dddf72f474718 100644 --- a/src/tools/tidy/src/x_version.rs +++ b/src/tools/tidy/src/x_version.rs @@ -3,7 +3,7 @@ use std::io::ErrorKind; use std::process::{Command, Stdio}; pub fn check(bad: &mut bool) { - let result = Command::new("x").arg("--version").stdout(Stdio::piped()).spawn(); + let result = Command::new("x").arg("--wrapper-version").stdout(Stdio::piped()).spawn(); let child = match result { Ok(child) => child, Err(e) => match e.kind() { diff --git a/src/tools/x/src/main.rs b/src/tools/x/src/main.rs index db5d03710d762..01f7187851e38 100644 --- a/src/tools/x/src/main.rs +++ b/src/tools/x/src/main.rs @@ -53,7 +53,7 @@ fn exec_or_status(command: &mut Command) -> io::Result { fn main() { match env::args().skip(1).next().as_deref() { - Some("--version") => { + Some("--wrapper-version") => { let version = env!("CARGO_PKG_VERSION"); println!("{}", version); return; From 5e67ce6803c5d1d67ccfce653a80257aba41f43a Mon Sep 17 00:00:00 2001 From: DebugSteven Date: Sun, 1 Jan 2023 13:20:32 -0700 Subject: [PATCH 09/16] handle error case where --wrapper-version argument doesn't exist --- src/tools/tidy/src/x_version.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/tools/tidy/src/x_version.rs b/src/tools/tidy/src/x_version.rs index dddf72f474718..1505775c6cc65 100644 --- a/src/tools/tidy/src/x_version.rs +++ b/src/tools/tidy/src/x_version.rs @@ -4,15 +4,29 @@ use std::process::{Command, Stdio}; pub fn check(bad: &mut bool) { let result = Command::new("x").arg("--wrapper-version").stdout(Stdio::piped()).spawn(); - let child = match result { - Ok(child) => child, - Err(e) => match e.kind() { + // This runs the command inside a temporarily directory. + // This allows us to compare output of result to see if `--wrapper-version` is not a recognized argument to x. + let temp_result = Command::new("x").arg("--wrapper-version").current_dir(std::env::temp_dir()).stdout(Stdio::piped()).spawn(); + + let (child, temp_child) = match (result, temp_result) { + (Ok(child), Ok(temp_child)) => (child, temp_child), + // what would it mean if the temp cmd error'd? + (Ok(_child), Err(_e)) => todo!(), + (Err(e), _) => match e.kind() { ErrorKind::NotFound => return, _ => return tidy_error!(bad, "failed to run `x`: {}", e), }, }; let output = child.wait_with_output().unwrap(); + let temp_output = temp_child.wait_with_output().unwrap(); + + if output != temp_output { + return tidy_error!( + bad, + "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`" + ) + } if output.status.success() { let version = String::from_utf8_lossy(&output.stdout); From e94354e3632e76c6ccff91f40fa054f68e2e87f4 Mon Sep 17 00:00:00 2001 From: DebugSteven Date: Sun, 1 Jan 2023 13:41:47 -0700 Subject: [PATCH 10/16] fix formatting --- src/tools/tidy/src/x_version.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/tools/tidy/src/x_version.rs b/src/tools/tidy/src/x_version.rs index 1505775c6cc65..9cb762b9419f1 100644 --- a/src/tools/tidy/src/x_version.rs +++ b/src/tools/tidy/src/x_version.rs @@ -6,7 +6,11 @@ pub fn check(bad: &mut bool) { let result = Command::new("x").arg("--wrapper-version").stdout(Stdio::piped()).spawn(); // This runs the command inside a temporarily directory. // This allows us to compare output of result to see if `--wrapper-version` is not a recognized argument to x. - let temp_result = Command::new("x").arg("--wrapper-version").current_dir(std::env::temp_dir()).stdout(Stdio::piped()).spawn(); + let temp_result = Command::new("x") + .arg("--wrapper-version") + .current_dir(std::env::temp_dir()) + .stdout(Stdio::piped()) + .spawn(); let (child, temp_child) = match (result, temp_result) { (Ok(child), Ok(temp_child)) => (child, temp_child), @@ -23,9 +27,9 @@ pub fn check(bad: &mut bool) { if output != temp_output { return tidy_error!( - bad, - "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`" - ) + bad, + "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`" + ); } if output.status.success() { From d7cac976dc3ce23fcd119e8194b1cb824e1800df Mon Sep 17 00:00:00 2001 From: DebugSteven Date: Sun, 1 Jan 2023 14:34:40 -0700 Subject: [PATCH 11/16] combine error branches --- src/tools/tidy/src/x_version.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/tools/tidy/src/x_version.rs b/src/tools/tidy/src/x_version.rs index 9cb762b9419f1..0a5055f61915d 100644 --- a/src/tools/tidy/src/x_version.rs +++ b/src/tools/tidy/src/x_version.rs @@ -14,9 +14,7 @@ pub fn check(bad: &mut bool) { let (child, temp_child) = match (result, temp_result) { (Ok(child), Ok(temp_child)) => (child, temp_child), - // what would it mean if the temp cmd error'd? - (Ok(_child), Err(_e)) => todo!(), - (Err(e), _) => match e.kind() { + (Err(e), _) | (_, Err(e)) => match e.kind() { ErrorKind::NotFound => return, _ => return tidy_error!(bad, "failed to run `x`: {}", e), }, From e62258ebf45840721ff1aed0e3edb378205af0d3 Mon Sep 17 00:00:00 2001 From: J Haigh Date: Sun, 1 Jan 2023 14:36:11 -0700 Subject: [PATCH 12/16] fix typo Co-authored-by: Joshua Nelson --- src/tools/tidy/src/x_version.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tidy/src/x_version.rs b/src/tools/tidy/src/x_version.rs index 0a5055f61915d..cf91749b9a4d3 100644 --- a/src/tools/tidy/src/x_version.rs +++ b/src/tools/tidy/src/x_version.rs @@ -4,7 +4,7 @@ use std::process::{Command, Stdio}; pub fn check(bad: &mut bool) { let result = Command::new("x").arg("--wrapper-version").stdout(Stdio::piped()).spawn(); - // This runs the command inside a temporarily 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. let temp_result = Command::new("x") .arg("--wrapper-version") From 9aebb1e09950591413103545d5bc1a40ec46bd9e Mon Sep 17 00:00:00 2001 From: J Haigh Date: Sun, 1 Jan 2023 14:36:51 -0700 Subject: [PATCH 13/16] improve error message Co-authored-by: Joshua Nelson --- src/tools/tidy/src/x_version.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/tidy/src/x_version.rs b/src/tools/tidy/src/x_version.rs index cf91749b9a4d3..868b3d925d3c0 100644 --- a/src/tools/tidy/src/x_version.rs +++ b/src/tools/tidy/src/x_version.rs @@ -43,7 +43,7 @@ pub fn check(bad: &mut bool) { 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`" + "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 { From e9ca6636e108cb4380d38a45c5ebb1d485079210 Mon Sep 17 00:00:00 2001 From: DebugSteven Date: Mon, 2 Jan 2023 16:36:29 -0700 Subject: [PATCH 14/16] get latest x version from parsing cargo command --- Cargo.lock | 17 ++++++------ src/tools/tidy/Cargo.toml | 1 + src/tools/tidy/src/x_version.rs | 48 ++++++++++++++++++++++++++------- 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8cafdc83d4f4d..784aca237f042 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 5f5ae3a65efa8..a13ecbe955ac1 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 868b3d925d3c0..6cadc18fd3e9c 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()) +} From 376dd8a9b36eb4d0c192f3767562ca0bdab60ff9 Mon Sep 17 00:00:00 2001 From: DebugSteven Date: Mon, 2 Jan 2023 19:31:18 -0700 Subject: [PATCH 15/16] use cargo_metadata to get x version --- Cargo.lock | 1 - src/tools/tidy/Cargo.toml | 1 - src/tools/tidy/src/main.rs | 2 +- src/tools/tidy/src/x_version.rs | 36 +++++++++------------------------ 4 files changed, 11 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 784aca237f042..4cb64882cb7e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5310,7 +5310,6 @@ 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 a13ecbe955ac1..5f5ae3a65efa8 100644 --- a/src/tools/tidy/Cargo.toml +++ b/src/tools/tidy/Cargo.toml @@ -12,7 +12,6 @@ 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/main.rs b/src/tools/tidy/src/main.rs index 56fcc561a3f89..7bb8ddc6949ef 100644 --- a/src/tools/tidy/src/main.rs +++ b/src/tools/tidy/src/main.rs @@ -107,7 +107,7 @@ fn main() { check!(alphabetical, &compiler_path); check!(alphabetical, &library_path); - check!(x_version); + check!(x_version, &root_path, &cargo); let collected = { drain_handles(&mut handles); diff --git a/src/tools/tidy/src/x_version.rs b/src/tools/tidy/src/x_version.rs index 6cadc18fd3e9c..070a751b05183 100644 --- a/src/tools/tidy/src/x_version.rs +++ b/src/tools/tidy/src/x_version.rs @@ -1,9 +1,9 @@ use semver::Version; -use serde_json::Value; use std::io::ErrorKind; +use std::path::Path; 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(); // 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. @@ -35,7 +35,7 @@ pub fn check(bad: &mut bool) { let version = String::from_utf8_lossy(&output.stdout); 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 { return tidy_error!( bad, @@ -54,27 +54,11 @@ pub fn check(bad: &mut bool) { } // 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()) +fn get_x_wrapper_version(root: &Path, cargo: &Path) -> Option { + let mut cmd = cargo_metadata::MetadataCommand::new(); + cmd.cargo_path(cargo) + .manifest_path(root.join("src/tools/x/Cargo.toml")) + .features(cargo_metadata::CargoOpt::AllFeatures); + let mut metadata = t!(cmd.exec()); + metadata.packages.pop().map(|x| x.version) } From 85f649fd27754cf54dff48131b87800a02edb948 Mon Sep 17 00:00:00 2001 From: J Haigh Date: Mon, 2 Jan 2023 20:49:18 -0700 Subject: [PATCH 16/16] no_deps Co-authored-by: Joshua Nelson --- src/tools/tidy/src/x_version.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/tidy/src/x_version.rs b/src/tools/tidy/src/x_version.rs index 070a751b05183..5dc6a0588c32b 100644 --- a/src/tools/tidy/src/x_version.rs +++ b/src/tools/tidy/src/x_version.rs @@ -58,6 +58,7 @@ fn get_x_wrapper_version(root: &Path, cargo: &Path) -> Option { let mut cmd = cargo_metadata::MetadataCommand::new(); cmd.cargo_path(cargo) .manifest_path(root.join("src/tools/x/Cargo.toml")) + .no_deps() .features(cargo_metadata::CargoOpt::AllFeatures); let mut metadata = t!(cmd.exec()); metadata.packages.pop().map(|x| x.version)