Keep the probe list out of the harnesses' dependencies

main.rs now only lists the probes; dispatch.rs runs them. The runner leaves
main.rs out of a probe-binary harness's dependencies and keeps dispatch.rs,
so adding a probe no longer reruns (or flake-checks) every harness of its
crate. It also follows crate::<probe> references between probes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-23 14:47:03 +02:00
parent ab4c246cda
commit ed847d43dc
4 changed files with 58 additions and 43 deletions
@@ -0,0 +1,40 @@
//! 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()
}
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)
})
}
+7 -35
View File
@@ -1,7 +1,13 @@
//! Every horizon-world parity probe in one binary: `probe <name> [arguments]` runs `<name>.rs` as its own
//! example did (tools/test_*_parity.py). Linking ~170 examples, each instantiating the crate's generics again,
//! was most of the parity job's probe build; one binary builds them 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;
/// Code shared by several probes.
mod support {
@@ -180,20 +186,6 @@ mod world_fixture;
mod world_ray_fixture;
mod worldgen_random_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! {
active_effect_tick_fixture,
active_effects_fixture,
@@ -364,23 +356,3 @@ probes! {
world_ray_fixture,
worldgen_random_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()
}
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)
})
}
+5 -3
View File
@@ -57,12 +57,14 @@ class ParityRunnerTests(unittest.TestCase):
(probe / "support").mkdir(parents=True)
(probe / "a_fixture.rs").write_text('mod integration { include!("d_fixture.rs"); }')
(probe / "d_fixture.rs").write_text("use crate::support::shared as s;")
for name in ("b_fixture.rs", "c_fixture.rs", "main.rs", "support/shared.rs", "support/other.rs"):
(probe / "b_fixture.rs").write_text("use crate::e_fixture;")
for name in ("c_fixture.rs", "dispatch.rs", "e_fixture.rs", "main.rs", "support/shared.rs", "support/other.rs"):
(probe / name).write_text("")
paths = [f"crates/w/examples/probe/{name}" for name in ("a_fixture.rs", "b_fixture.rs", "c_fixture.rs",
"d_fixture.rs", "main.rs", "support/other.rs", "support/shared.rs")]
"d_fixture.rs", "dispatch.rs", "e_fixture.rs", "main.rs",
"support/other.rs", "support/shared.rs")]
self.assertEqual(parity.only_probes_run(["crates/w/src/lib.rs", *paths], {"a_fixture", "b_fixture"}),
["crates/w/src/lib.rs", *paths[:2], *paths[3:5], paths[6]])
["crates/w/src/lib.rs", *paths[:2], *paths[3:6], paths[8]])
self.assertEqual(parity.only_probes_run(paths, set()), paths)
def test_java_sources_include_classes_pulled_from_the_sourcepath(self):
+6 -5
View File
@@ -482,16 +482,17 @@ def probes_run(commands):
def only_probes_run(paths, names):
"""A probe binary's dep-info lists every probe in it. Keep those the harness ran, the probes they include!
and the shared support modules they name (support::<module>), so that editing one probe reruns only its own
harnesses."""
"""A probe binary's dep-info lists every probe in it. Keep those the harness ran, the probes they include! or
name (crate::<probe>) and the shared support modules they name (support::<module>), so that editing one probe
reruns only its own harnesses. Files in a probe's own subdirectory and dispatch.rs, which runs them, are always
kept; main.rs, which only lists them, is left out, so adding a probe reruns nothing."""
if not names:
return paths
names, used = {*names, "main"}, ""
names, used = {*names, "dispatch"}, ""
while True:
ran = [path for path in paths if (match := PROBE_SOURCE.search(path)) and not match.group(1) and match.group(2) in names]
used = "".join((ROOT / path).read_text(encoding="utf-8", errors="replace") for path in ran)
included = set(re.findall(r'include!\("(\w+)\.rs"\)', used)) - names
included = {*re.findall(r'include!\("(\w+)\.rs"\)', used), *re.findall(r"\bcrate::(\w+)", used)} - names
if not included:
break
names |= included