mirror of
https://github.com/horizon-rust/horizon.git
synced 2026-11-07 11:06:11 -10:00
horizon-client, horizon-world and horizon-protocol each had an example named `probe`. Cargo copies every crate's examples into one <profile>/examples/ directory, so parallel parity harnesses sharing a target dir could run another crate's probe (CI parity run 40055656303: command_parse ran the horizon-world dispatcher). The examples are now client_probe, world_probe and protocol_probe ([[example]] in each Cargo.toml; the files stay where they are), and every harness builds and runs its own crate's name. tools/parity.py recognises the new names when it counts the probes a harness ran, and renames the old `probe` in recorded artifacts to the crate's target (from the record's -p, else its probe sources), so the prebuild still builds them instead of dropping them as unknown. Co-Authored-By: Claude Opus 5.5 <[email protected]>
50 lines
1.6 KiB
Rust
50 lines
1.6 KiB
Rust
//! 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: client_probe <name> [arguments...]\nprobes: {}",
|
|
names.join(" ")
|
|
);
|
|
ExitCode::from(2)
|
|
})
|
|
}
|