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 {
6464 pub fn $group_name( bencher: & mut $crate:: Bencher ) {
6565 bencher. push_group( stringify!( $group_name) ) ;
6666 $(
67- bencher. set_current_file( codspeed :: abs_file!( ) ) ;
67+ bencher. set_current_file( $crate :: abs_file!( ) ) ;
6868 bencher. set_current_bench_path( stringify!( $function) ) ;
6969 $function( bencher) ;
7070 ) +
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ mod compat_bencher {
66#[ cfg( codspeed) ]
77#[ path = "." ]
88mod compat_bencher {
9+ pub use codspeed:: abs_file;
10+
911 mod compat;
1012 pub use compat:: * ;
1113}
Original file line number Diff line number Diff line change @@ -76,7 +76,17 @@ pub fn run_benches(
7676 std:: process:: Command :: new ( bench)
7777 . env ( "CODSPEED_CARGO_WORKSPACE_ROOT" , workspace_root. as_ref ( ) )
7878 . 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+ } ) ?;
8090 ws. config ( ) . shell ( ) . status_with_color (
8191 "Done" ,
8292 format ! ( "running {}" , bench_name) ,
Original file line number Diff line number Diff line change 11#[ macro_export]
22macro_rules! abs_file {
33 ( ) => {
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( )
710 } ;
811}
912
Original file line number Diff line number Diff line change 11use std:: io;
22use std:: path:: { Path , PathBuf } ;
3- use std:: process:: Command ;
43
54fn get_parent_git_repo_path ( abs_path : & Path ) -> io:: Result < PathBuf > {
65 if abs_path. join ( ".git" ) . exists ( ) {
2827 }
2928}
3029
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-
5730/// Fixes spaces around `::` created by stringify!($function).
5831pub fn get_formated_function_path ( function_path : impl Into < String > ) -> String {
5932 let function_path = function_path. into ( ) ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ macro_rules! criterion_group {
44 pub fn $name( criterion: & mut $crate:: Criterion ) {
55 let mut criterion = & mut criterion. with_patched_measurement( $config) ;
66 $(
7- criterion. set_current_file( codspeed :: abs_file!( ) ) ;
7+ criterion. set_current_file( $crate :: abs_file!( ) ) ;
88 criterion. set_macro_group( format!( "{}::{}" , stringify!( $name) , stringify!( $target) ) ) ;
99 $target( criterion) ;
1010 ) +
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ mod compat_criterion {
88#[ cfg( codspeed) ]
99#[ path = "." ]
1010mod compat_criterion {
11+ pub use codspeed:: abs_file;
12+
1113 mod compat;
1214 pub use compat:: * ;
1315
You can’t perform that action at this time.
0 commit comments