Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions src/bin/anchor-coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use anchor_coverage::util::StripCurrentDir;
use anyhow::{bail, ensure, Result};
use std::{
env::{args, current_dir},
fs::{canonicalize, create_dir_all, remove_dir_all},
path::{Path, PathBuf},
fs::{create_dir_all, remove_dir_all},
path::Path,
process::Command,
};

Expand Down Expand Up @@ -127,18 +127,9 @@ fn anchor_test_skip_build(args: &[String], sbf_trace_dir: &Path) -> Result<()> {
}

fn grep_command() -> Result<String> {
let path = which("solana-test-validator")?;
let path = anchor_coverage::util::which("solana-test-validator")?;
Ok(format!(
"grep SBF_TRACE_DIR {} || echo 'solana-test-validator is not patched'",
path.display()
))
}

fn which(filename: &str) -> Result<PathBuf> {
let mut command = Command::new("which");
let output = command.arg(filename).output()?;
ensure!(output.status.success(), "command failed: {command:?}");
let stdout = std::str::from_utf8(&output.stdout)?;
let path = canonicalize(stdout.trim_end())?;
Ok(path)
}
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::util::which;
use addr2line::Loader;
use anyhow::{anyhow, Result};
use byteorder::{LittleEndian, ReadBytesExt};
Expand Down Expand Up @@ -138,6 +139,17 @@ If you are done generating lcov files, try running:
sbf_trace_dir.as_ref().strip_current_dir().display()
);

if which("genhtml").is_err() {
eprintln!("However, it seems that `genhtml` is not installed on your system");
if cfg!(target_os = "macos") {
eprintln!("You can install it using Homebrew:");
eprintln!(" brew install lcov");
} else if cfg!(target_os = "linux") {
eprintln!("You can install it using apt:");
eprintln!(" apt install lcov");
}
}

Ok(())
}

Expand Down
13 changes: 12 additions & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use anyhow::Result;
use anyhow::{ensure, Result};
use std::fs::canonicalize;
use std::process::Command;
use std::{
env::current_dir,
ffi::OsStr,
Expand Down Expand Up @@ -30,3 +32,12 @@ impl StripCurrentDir for Path {
self.strip_prefix(current_dir).unwrap_or(self)
}
}

pub fn which(filename: &str) -> Result<PathBuf> {
let mut command = Command::new("which");
let output = command.arg(filename).output()?;
ensure!(output.status.success(), "command failed: {command:?}");
let stdout = std::str::from_utf8(&output.stdout)?;
let path = canonicalize(stdout.trim_end())?;
Ok(path)
}
Loading