Skip to content

Commit 2ca29eb

Browse files
committed
feat: run codspeed_runner.go with tags
1 parent 3111c2a commit 2ca29eb

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

go-runner/src/runner.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
}

0 commit comments

Comments
 (0)