Skip to content

Commit 1c8520e

Browse files
committed
Add check for debug = true
1 parent 8b92a1f commit 1c8520e

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ addr2line = "0.25"
1212
anyhow = "1.0"
1313
byteorder = "1.5"
1414
cargo_metadata = "0.23"
15+
toml = "0.9"
1516

1617
# smoelius: Dependencies needed for `__anchor_cli`.
1718
anchor-client = { version = "0.32", optional = true }
@@ -31,7 +32,6 @@ serde_json = { version = "1.0", optional = true }
3132
shellexpand = { version = "3.1", optional = true }
3233
solana-cli-config = { version = "3.0", optional = true }
3334
solana-sdk = { version = "2.3", optional = true }
34-
toml = { version = "0.9", optional = true }
3535
walkdir = { version = "2.5", optional = true }
3636

3737
[build-dependencies]
@@ -62,7 +62,6 @@ __anchor_cli = [
6262
"shellexpand",
6363
"solana-cli-config",
6464
"solana-sdk",
65-
"toml",
6665
"walkdir",
6766
]
6867

src/bin/anchor-coverage.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ use std::{
44
env::{args, current_dir, join_paths, split_paths, var_os},
55
ffi::OsString,
66
fmt::Write,
7-
fs::{canonicalize, create_dir_all, read, remove_dir_all},
7+
fs::{canonicalize, create_dir_all, read, read_to_string, remove_dir_all},
88
path::{Path, PathBuf},
99
process::Command,
1010
};
11+
use toml::{Table, Value};
1112

1213
const SBF_TRACE_DIR: &str = "SBF_TRACE_DIR";
1314

@@ -48,6 +49,13 @@ Usage: {0} [ANCHOR_TEST_ARGS]...
4849
_guard = VarGuard::set("PATH", Some(prepended_paths));
4950
}
5051

52+
if !profile_release_has_debug()? {
53+
eprintln!(
54+
"Warning: Could not find `debug = true` under `[profile.release]`; `anchor-coverage` \
55+
may not work correctly"
56+
);
57+
}
58+
5159
let sbf_trace_dir = current_dir.join("sbf_trace_dir");
5260

5361
if sbf_trace_dir.try_exists()? {
@@ -123,6 +131,22 @@ fn prepend_paths(path: PathBuf) -> Result<OsString> {
123131
Ok(paths_joined)
124132
}
125133

134+
fn profile_release_has_debug() -> Result<bool> {
135+
// smoelius: If Cargo.toml cannot be found, proceed as if everything is okay.
136+
let Ok(contents) = read_to_string("Cargo.toml") else {
137+
return Ok(true);
138+
};
139+
let table = contents.parse::<Table>()?;
140+
Ok(table
141+
.get("profile")
142+
.and_then(Value::as_table)
143+
.and_then(|table| table.get("release"))
144+
.and_then(Value::as_table)
145+
.and_then(|table| table.get("debug"))
146+
.and_then(Value::as_bool)
147+
.unwrap_or(false))
148+
}
149+
126150
fn anchor_test_with_debug(args: &[String], sbf_trace_dir: &Path) -> Result<()> {
127151
#[cfg(feature = "__anchor_cli")]
128152
anchor_coverage::__build_with_debug(

0 commit comments

Comments
 (0)