File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ use crate :: prelude:: * ;
2
+ use std:: { path:: Path , process:: Command } ;
3
+
4
+ pub fn run < P : AsRef < Path > > ( runner_go_path : P , run_args : & [ & str ] ) -> anyhow:: Result < ( ) > {
5
+ // Extract the directory containing runner.go to use as working directory
6
+ let runner_go_path = runner_go_path. as_ref ( ) ;
7
+ let file_dir = runner_go_path. parent ( ) . unwrap ( ) ;
8
+ let module_root = file_dir. parent ( ) . unwrap ( ) ;
9
+ let relative_path = runner_go_path. strip_prefix ( module_root) . unwrap ( ) ;
10
+ debug ! (
11
+ "Building codspeed runner: {:?} (root = {:?})" ,
12
+ module_root. join( relative_path) ,
13
+ module_root
14
+ ) ;
15
+
16
+ // Run go run -tags=codspeed <path> {args}
17
+ let output = Command :: new ( "go" )
18
+ . arg ( "run" )
19
+ . arg ( "-tags=codspeed" )
20
+ . arg ( relative_path)
21
+ . args ( run_args)
22
+ . current_dir ( module_root)
23
+ . stdout ( std:: process:: Stdio :: inherit ( ) )
24
+ . stderr ( std:: process:: Stdio :: inherit ( ) )
25
+ . output ( )
26
+ . context ( "Failed to execute go build command" ) ?;
27
+
28
+ if !output. status . success ( ) {
29
+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
30
+ let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
31
+
32
+ warn ! ( "Command output: {stdout}" ) ;
33
+ warn ! ( "Command error output: {stderr}" ) ;
34
+
35
+ bail ! ( "Failed to run benchmark. Exit status: {}" , output. status) ;
36
+ }
37
+
38
+ Ok ( ( ) )
39
+ }
You can’t perform that action at this time.
0 commit comments