@@ -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
1213const 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+
126150fn 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