artifactize_tools/
launch.rs1use std::{
6 collections::BTreeMap, ffi::OsString, future::Future, path::PathBuf, pin::Pin, time::Duration,
7};
8
9use tokio_util::sync::CancellationToken;
10
11use crate::platform;
12pub use crate::platform::outcome::{ProcessEnd, ProcessOutcome};
13
14#[derive(Debug, Clone)]
16pub struct Launch {
17 pub program: PathBuf,
18 pub args: Vec<OsString>,
19 pub cwd: PathBuf,
20 pub timeout: Duration,
22 pub output_limit: usize,
24}
25
26#[derive(Debug)]
28pub struct Finished {
29 pub status: ProcessOutcome,
30 pub stdout: Vec<u8>,
31 pub stderr: Vec<u8>,
32 pub truncated: bool,
34}
35
36#[derive(Debug, thiserror::Error)]
38pub enum LaunchError {
39 #[error("timed out")]
40 TimedOut,
41 #[error("Tool call was cancelled.")]
42 Cancelled,
43 #[error("{0}")]
44 Failed(String),
45}
46
47pub type Running<'a> = Pin<Box<dyn Future<Output = Result<Finished, LaunchError>> + Send + 'a>>;
49
50pub trait Launcher: Sync {
52 fn run<'a>(&'a self, launch: Launch, cancellation: &'a CancellationToken) -> Running<'a>;
53}
54
55pub struct Standalone;
59
60impl Launcher for Standalone {
61 fn run<'a>(&'a self, launch: Launch, cancellation: &'a CancellationToken) -> Running<'a> {
62 Box::pin(platform::process::run(launch, cancellation))
63 }
64}
65
66pub fn passed_environment() -> BTreeMap<OsString, OsString> {
69 platform::process::passed_environment()
70}