forge_engine/exec/
container.rs1use std::path::Path;
2
3use async_trait::async_trait;
4use check_runner::ExecutionBackend as RunnerExecutionBackend;
5
6use crate::config::ForgeConfig;
7use crate::error::ForgeResult;
8use crate::exec::backend::*;
9
10pub use check_runner::ContainerRuntime;
11
12pub struct ContainerBackend {
14 inner: check_runner::ContainerBackend,
15}
16
17impl ContainerBackend {
18 pub fn new(config: &ForgeConfig) -> ForgeResult<Self> {
20 Ok(Self {
21 inner: check_runner::ContainerBackend::new(&crate::exec::backend::runner_config(
22 config,
23 ))?,
24 })
25 }
26
27 pub fn runtime(&self) -> ContainerRuntime {
29 self.inner.runtime()
30 }
31}
32
33#[async_trait]
34impl ExecutionBackend for ContainerBackend {
35 fn kind(&self) -> ExecutionBackendKind {
36 self.inner.kind()
37 }
38
39 async fn prepare_workspace(&self, fixture: &Path) -> ForgeResult<Workspace> {
40 Ok(self.inner.prepare_workspace(fixture).await?)
41 }
42
43 async fn run_command(
44 &self,
45 workspace: &Path,
46 program: &str,
47 args: &[&str],
48 env: &[(&str, &str)],
49 timeout_secs: u64,
50 ) -> ForgeResult<CommandOutput> {
51 Ok(self
52 .inner
53 .run_command(workspace, program, args, env, timeout_secs)
54 .await?)
55 }
56
57 async fn collect_logs(
58 &self,
59 fmt: &CommandOutput,
60 clippy: &CommandOutput,
61 test: &CommandOutput,
62 ) -> ForgeResult<LogBundle> {
63 Ok(self.inner.collect_logs(fmt, clippy, test).await?)
64 }
65}
66
67pub fn detect_runtime(preference: &str) -> ForgeResult<ContainerRuntime> {
69 Ok(check_runner::detect_runtime(preference)?)
70}