From f4e75dc0459d4c4bc2603ea456afd26bcde9c074 Mon Sep 17 00:00:00 2001 From: Christoph Gehrke Date: Wed, 1 Apr 2026 15:44:58 +0200 Subject: [PATCH] fix(cover): check for grcov's dependencies Doing this before profiling the corpus can save some frustration when llvm-tools are missing. --- Cargo.toml | 5 ++--- src/bin/cargo-ziggy/coverage.rs | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c0f36ad..aed564c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ cli = [ "signal-hook", "strip-ansi-escapes", "target-triple", + "tempfile", "time-humanize", "twox-hash", ] @@ -48,11 +49,9 @@ semver = { version = "1.0.27", optional = true } signal-hook = { version = "0.4.3", optional = true } strip-ansi-escapes = { version = "0.2.1", optional = true } target-triple = { version = "1.0.0", optional = true } +tempfile = { version = "3.27.0", optional = true } time-humanize = { version = "0.1.3", optional = true } twox-hash = { version = "2.1.2", optional = true } -[dev-dependencies] -tempfile = "3" - [lints.clippy] needless_doctest_main = "allow" diff --git a/src/bin/cargo-ziggy/coverage.rs b/src/bin/cargo-ziggy/coverage.rs index c00f8c0..e88f1d1 100644 --- a/src/bin/cargo-ziggy/coverage.rs +++ b/src/bin/cargo-ziggy/coverage.rs @@ -1,5 +1,5 @@ use crate::{Cover, find_target}; -use anyhow::{Context, Result, bail}; +use anyhow::{Context, Result, anyhow, bail}; use cargo_metadata::camino::Utf8PathBuf; use glob::glob; use indicatif::{ProgressBar, ProgressStyle}; @@ -22,6 +22,22 @@ impl Cover { .output() .context("grcov not found - please install by running `cargo install grcov`")?; + if let Ok(dir) = tempfile::tempdir() { + const TAG: &str = "[ERROR] "; + let _ = std::fs::File::create(dir.path().join("a.profraw")); + if let Some(out) = process::Command::new("grcov") + .args(["-b=.", "-o=.", "."]) + .current_dir(dir.path()) + .output() + .ok() + .and_then(|o| String::from_utf8(o.stderr).ok()) + && let Some(idx) = out.find(TAG) + { + return Err(anyhow!("{}", &out[idx + TAG.len()..])) + .context("grcov missing dependencies"); + } + } + eprintln!("Generating coverage"); self.target =