Split the client probe list from its dispatch the same way
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
//! How the probe binary runs a probe. main.rs lists the probes and nothing else (tools/parity.py leaves it out of
|
||||
//! the harnesses' dependencies); code every probe relies on goes here.
|
||||
use std::process::ExitCode;
|
||||
|
||||
/// `probes! { a, b, }` declares the binary's `main`, which runs the probe module named by its first argument.
|
||||
macro_rules! probes {
|
||||
($($name:ident,)*) => {
|
||||
fn run(name: &str) -> Option<std::process::ExitCode> {
|
||||
use std::process::Termination;
|
||||
Some(match name {
|
||||
$(stringify!($name) => $name::main().report(),)*
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
fn main() -> std::process::ExitCode {
|
||||
dispatch::main(&[$(stringify!($name)),*], run)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// The probe's command line as its own example saw it: the program, then the arguments after the probe's name.
|
||||
pub fn args() -> std::vec::IntoIter<String> {
|
||||
let mut args: Vec<String> = std::env::args().collect();
|
||||
if args.len() > 1 {
|
||||
args.remove(1);
|
||||
}
|
||||
args.into_iter()
|
||||
}
|
||||
|
||||
/// args(), as OsStrings.
|
||||
pub fn args_os() -> std::vec::IntoIter<std::ffi::OsString> {
|
||||
let mut args: Vec<_> = std::env::args_os().collect();
|
||||
if args.len() > 1 {
|
||||
args.remove(1);
|
||||
}
|
||||
args.into_iter()
|
||||
}
|
||||
|
||||
pub fn main(names: &[&str], run: fn(&str) -> Option<ExitCode>) -> ExitCode {
|
||||
let name = std::env::args().nth(1).unwrap_or_default();
|
||||
run(&name).unwrap_or_else(|| {
|
||||
eprintln!(
|
||||
"usage: probe <name> [arguments...]\nprobes: {}",
|
||||
names.join(" ")
|
||||
);
|
||||
ExitCode::from(2)
|
||||
})
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
//! Every horizon-client parity probe in one binary: `probe <name> [arguments]` runs `<name>.rs` as its own
|
||||
//! example did (tools/test_*_parity.py, tools/oracle_harness.py, tools/audio_harness.py). Linking ~80 examples,
|
||||
//! each with the whole client in it, was most of the parity job's probe build; one binary builds it once.
|
||||
use std::process::{ExitCode, Termination};
|
||||
//!
|
||||
//! This file only lists the probes, so that adding one reruns no harness: tools/parity.py leaves it out of
|
||||
//! their dependencies. How a probe runs is in dispatch.rs.
|
||||
#[macro_use]
|
||||
mod dispatch;
|
||||
|
||||
use dispatch::{args, args_os};
|
||||
|
||||
mod ambient_fixture;
|
||||
mod arrow_probe;
|
||||
@@ -87,20 +93,6 @@ mod weather_fixture;
|
||||
mod world_border_render_fixture;
|
||||
mod world_options_fixture;
|
||||
|
||||
/// `run(name)` runs the probe module `name`; NAMES lists them.
|
||||
macro_rules! probes {
|
||||
($($name:ident,)*) => {
|
||||
const NAMES: &[&str] = &[$(stringify!($name)),*];
|
||||
|
||||
fn run(name: &str) -> Option<ExitCode> {
|
||||
Some(match name {
|
||||
$(stringify!($name) => $name::main().report(),)*
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
probes! {
|
||||
ambient_fixture,
|
||||
arrow_probe,
|
||||
@@ -184,32 +176,3 @@ probes! {
|
||||
world_border_render_fixture,
|
||||
world_options_fixture,
|
||||
}
|
||||
|
||||
/// The probe's command line as its own example saw it: the program, then the arguments after the probe's name.
|
||||
fn args() -> std::vec::IntoIter<String> {
|
||||
let mut args: Vec<String> = std::env::args().collect();
|
||||
if args.len() > 1 {
|
||||
args.remove(1);
|
||||
}
|
||||
args.into_iter()
|
||||
}
|
||||
|
||||
/// args(), as OsStrings.
|
||||
fn args_os() -> std::vec::IntoIter<std::ffi::OsString> {
|
||||
let mut args: Vec<_> = std::env::args_os().collect();
|
||||
if args.len() > 1 {
|
||||
args.remove(1);
|
||||
}
|
||||
args.into_iter()
|
||||
}
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let name = std::env::args().nth(1).unwrap_or_default();
|
||||
run(&name).unwrap_or_else(|| {
|
||||
eprintln!(
|
||||
"usage: probe <name> [arguments...]\nprobes: {}",
|
||||
NAMES.join(" ")
|
||||
);
|
||||
ExitCode::from(2)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user