repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

build: enforce pinned tool versions

0786575ac5bae9dda4fc00747ee957da5d63ef89

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (1)

+33 / −20 text lines

Diff layout

xtask/src/main.rs

Modified

+33 / −20 text lines

2929const PUP_VERSION: &str = "0.1.8";
3131/// Version of `cargo-nextest` used by the test gate.
32const NEXTEST_VERSION: &str = "0.9.144";
32const NEXTEST_VERSION: &str = "0.9.146";
3434/// Version of `cargo-binstall` used to install `cargo-nextest`.
3535const BINSTALL_VERSION: &str = "1.23.0";
36const MACHETE_VERSION: &str = "0.9.2";
3637const DENY_VERSION: &str = "0.20.2";
3738const AUDIT_VERSION: &str = "0.22.2";
3839const CRATES: &[&str] = &[
162163fn cargo_machete() -> ExitCode {
163 let installed = tool_present_bin("cargo-machete", "--version", || {
164 cargo(&["install", "--locked", "cargo-machete"])
164 let installed = tool_present_bin("cargo-machete", MACHETE_VERSION, || {
165 cargo(&[
166 "install",
167 "--locked",
168 "--version",
169 MACHETE_VERSION,
170 "cargo-machete",
171 ])
165172 });
166173 if installed != ExitCode::SUCCESS {
167174 return installed;
214221fn install_machete() -> ExitCode {
215 tool_present_bin("cargo-machete", "--version", || {
216 cargo(&["install", "--locked", "cargo-machete"])
222 tool_present_bin("cargo-machete", MACHETE_VERSION, || {
223 cargo(&[
224 "install",
225 "--locked",
226 "--version",
227 MACHETE_VERSION,
228 "cargo-machete",
229 ])
217230 })
220233fn install_deny() -> ExitCode {
221 tool_present_bin("cargo-deny", "--version", || {
234 tool_present_bin("cargo-deny", DENY_VERSION, || {
222235 cargo(&[
223236 "binstall",
224237 "--no-confirm",
230243fn install_audit() -> ExitCode {
231 tool_present_bin("cargo-audit", "--version", || {
244 tool_present_bin("cargo-audit", AUDIT_VERSION, || {
232245 cargo(&[
233246 "binstall",
234247 "--no-confirm",
240253fn install_binstall() -> ExitCode {
241 tool_present(&["binstall", "--help"], || {
254 tool_present_bin("cargo-binstall", BINSTALL_VERSION, || {
242255 cargo(&[
243256 "install",
244257 "cargo-binstall",
254267fn install_nextest() -> ExitCode {
255 tool_present(&["nextest", "--version"], || {
268 tool_present_bin("cargo-nextest", NEXTEST_VERSION, || {
256269 cargo(&[
257270 "binstall",
258271 &format!("cargo-nextest@{NEXTEST_VERSION}"),
311324 }
314/// Probes an external binary directly; cargo subcommand dispatch can mangle
315/// arguments, so build tools are probed and run as plain binaries.
316fn tool_present_bin(program: &str, flag: &str, install: impl FnOnce() -> ExitCode) -> ExitCode {
317 match Command::new(program)
318 .arg(flag)
319 .stdout(std::process::Stdio::null())
327/// Probes an external binary directly and enforces the pinned version;
328/// mismatch or absence runs the installer, so drift self-heals to the pin.
329fn tool_present_bin(program: &str, version: &str, install: impl FnOnce() -> ExitCode) -> ExitCode {
330 let probe = Command::new(program)
331 .arg("--version")
332 .stdout(std::process::Stdio::piped())
320333 .stderr(std::process::Stdio::null())
321 .status()
322 {
323 Ok(status) if status.success() => ExitCode::SUCCESS,
324 _ => install(),
325 }
334 .output();
335 let pinned = probe.is_ok_and(|output| {
336 output.status.success() && String::from_utf8_lossy(&output.stdout).contains(version)
337 });
338 if pinned { ExitCode::SUCCESS } else { install() }
328341fn cargo_doc() -> ExitCode {