From c49555821f9735239bf12281b9151eac3b4596d4 Mon Sep 17 00:00:00 2001 From: DebugSteven Date: Thu, 17 Nov 2022 13:21:36 -0700 Subject: [PATCH] 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 ce7e7ac5cd4..bfcf0907365 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 6714c63ee62..f01d4673368 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 00000000000..2cbbde8de82 --- /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 f07ff43efe9..db5d03710d7 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) => {