Skip to content

Commit

Permalink
warn when there's a newer version of the x tool available
Browse files Browse the repository at this point in the history
  • Loading branch information
DebugSteven committed Dec 31, 2022
1 parent 726bbfc commit c495558
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/tools/tidy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ pub mod ui_tests;
pub mod unit_tests;
pub mod unstable_book;
pub mod walk;
pub mod x;
20 changes: 19 additions & 1 deletion src/tools/tidy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -64,7 +79,8 @@ fn main() {
}
});
handles.push_back(handle);
}
};

}

check!(target_specific_tests, &src_path);
Expand Down Expand Up @@ -107,6 +123,8 @@ fn main() {
check!(alphabetical, &compiler_path);
check!(alphabetical, &library_path);

check!(x);

let collected = {
drain_handles(&mut handles);

Expand Down
19 changes: 19 additions & 0 deletions src/tools/tidy/src/x.rs
Original file line number Diff line number Diff line change
@@ -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`")
}
8 changes: 8 additions & 0 deletions src/tools/x/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ fn exec_or_status(command: &mut Command) -> io::Result<ExitStatus> {
}

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) => {
Expand Down

0 comments on commit c495558

Please sign in to comment.