File tree Expand file tree Collapse file tree 7 files changed +23
-33
lines changed Expand file tree Collapse file tree 7 files changed +23
-33
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ macro_rules! benchmark_group {
64
64
pub fn $group_name( bencher: & mut $crate:: Bencher ) {
65
65
bencher. push_group( stringify!( $group_name) ) ;
66
66
$(
67
- bencher. set_current_file( codspeed :: abs_file!( ) ) ;
67
+ bencher. set_current_file( $crate :: abs_file!( ) ) ;
68
68
bencher. set_current_bench_path( stringify!( $function) ) ;
69
69
$function( bencher) ;
70
70
) +
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ mod compat_bencher {
6
6
#[ cfg( codspeed) ]
7
7
#[ path = "." ]
8
8
mod compat_bencher {
9
+ pub use codspeed:: abs_file;
10
+
9
11
mod compat;
10
12
pub use compat:: * ;
11
13
}
Original file line number Diff line number Diff line change @@ -76,7 +76,17 @@ pub fn run_benches(
76
76
std:: process:: Command :: new ( bench)
77
77
. env ( "CODSPEED_CARGO_WORKSPACE_ROOT" , workspace_root. as_ref ( ) )
78
78
. status ( )
79
- . map_err ( |_| anyhow ! ( "failed to execute the benchmark process" ) ) ?;
79
+ . map_err ( |_| anyhow ! ( "failed to execute the benchmark process" ) )
80
+ . and_then ( |status| {
81
+ if status. success ( ) {
82
+ Ok ( ( ) )
83
+ } else {
84
+ Err ( anyhow ! (
85
+ "failed to execute the benchmark process, exit code: {}" ,
86
+ status. code( ) . unwrap_or( 1 )
87
+ ) )
88
+ }
89
+ } ) ?;
80
90
ws. config ( ) . shell ( ) . status_with_color (
81
91
"Done" ,
82
92
format ! ( "running {}" , bench_name) ,
Original file line number Diff line number Diff line change 1
1
#[ macro_export]
2
2
macro_rules! abs_file {
3
3
( ) => {
4
- std:: path:: PathBuf :: from( std:: env:: var( "CODSPEED_CARGO_WORKSPACE_ROOT" ) . unwrap( ) )
5
- . join( file!( ) )
6
- . to_string_lossy( )
4
+ std:: path:: PathBuf :: from(
5
+ std:: env:: var( "CODSPEED_CARGO_WORKSPACE_ROOT" )
6
+ . expect( "Could not find CODSPEED_CARGO_WORKSPACE_ROOT env variable, make sure you are using the latest version of cargo-codspeed" )
7
+ )
8
+ . join( file!( ) )
9
+ . to_string_lossy( )
7
10
} ;
8
11
}
9
12
Original file line number Diff line number Diff line change 1
1
use std:: io;
2
2
use std:: path:: { Path , PathBuf } ;
3
- use std:: process:: Command ;
4
3
5
4
fn get_parent_git_repo_path ( abs_path : & Path ) -> io:: Result < PathBuf > {
6
5
if abs_path. join ( ".git" ) . exists ( ) {
28
27
}
29
28
}
30
29
31
- /// Returns the path to the root of the cargo workspace.
32
- /// This is needed since file! returns the path relatively to the workspace root
33
- /// while CARGO_MANIFEST_DIR returns the path to the sub package
34
- pub fn get_cargo_workspace_root ( ) -> PathBuf {
35
- let output = Command :: new ( "cargo" )
36
- . args ( [
37
- "metadata" ,
38
- "--format-version" ,
39
- "1" ,
40
- "--no-deps" ,
41
- "--quiet" ,
42
- "--offline" ,
43
- ] )
44
- . current_dir ( env ! ( "CARGO_MANIFEST_DIR" ) )
45
- . output ( )
46
- . expect ( "Failed to execute `cargo metadata`" ) ;
47
-
48
- let metadata: serde_json:: Value =
49
- serde_json:: from_slice ( & output. stdout ) . expect ( "Failed to parse `cargo metadata` output" ) ;
50
-
51
- let workspace_root = metadata[ "workspace_root" ]
52
- . as_str ( )
53
- . expect ( "`workspace_root` field is missing or not a string" ) ;
54
- PathBuf :: from ( workspace_root)
55
- }
56
-
57
30
/// Fixes spaces around `::` created by stringify!($function).
58
31
pub fn get_formated_function_path ( function_path : impl Into < String > ) -> String {
59
32
let function_path = function_path. into ( ) ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ macro_rules! criterion_group {
4
4
pub fn $name( criterion: & mut $crate:: Criterion ) {
5
5
let mut criterion = & mut criterion. with_patched_measurement( $config) ;
6
6
$(
7
- criterion. set_current_file( codspeed :: abs_file!( ) ) ;
7
+ criterion. set_current_file( $crate :: abs_file!( ) ) ;
8
8
criterion. set_macro_group( format!( "{}::{}" , stringify!( $name) , stringify!( $target) ) ) ;
9
9
$target( criterion) ;
10
10
) +
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ mod compat_criterion {
8
8
#[ cfg( codspeed) ]
9
9
#[ path = "." ]
10
10
mod compat_criterion {
11
+ pub use codspeed:: abs_file;
12
+
11
13
mod compat;
12
14
pub use compat:: * ;
13
15
You can’t perform that action at this time.
0 commit comments