mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-09 01:28:49 +00:00
feat: async process based on tokio::process::Command
This commit is contained in:
parent
04d9ffc21c
commit
e10be0f5e8
4 changed files with 54 additions and 19 deletions
39
Cargo.lock
generated
39
Cargo.lock
generated
|
@ -334,6 +334,7 @@ dependencies = [
|
|||
"serde",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"tokio",
|
||||
"tracker",
|
||||
"uuid",
|
||||
"vte4",
|
||||
|
@ -879,9 +880,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.3.3"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
|
||||
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
|
||||
|
||||
[[package]]
|
||||
name = "home"
|
||||
|
@ -1296,13 +1297,14 @@ checksum = "e53debba6bda7a793e5f99b8dacf19e626084f525f7829104ba9898f367d85ff"
|
|||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.8.11"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c"
|
||||
checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"wasi",
|
||||
"windows-sys 0.48.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1360,16 +1362,6 @@ dependencies = [
|
|||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "objc"
|
||||
version = "0.2.7"
|
||||
|
@ -1964,6 +1956,15 @@ version = "1.2.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380"
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.9"
|
||||
|
@ -2117,18 +2118,18 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
|||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.38.0"
|
||||
version = "1.39.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a"
|
||||
checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5"
|
||||
dependencies = [
|
||||
"backtrace",
|
||||
"bytes",
|
||||
"libc",
|
||||
"mio",
|
||||
"num_cpus",
|
||||
"pin-project-lite",
|
||||
"signal-hook-registry",
|
||||
"socket2",
|
||||
"windows-sys 0.48.0",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -29,3 +29,4 @@ openxr = { git = "https://github.com/galister/openxrs", rev = "af4a55d", feature
|
|||
] }
|
||||
ash = "0.38.0"
|
||||
sha2 = "0.10.8"
|
||||
tokio = { version = "1.39.3", features = ["process"] }
|
||||
|
|
32
src/async_process.rs
Normal file
32
src/async_process.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
use std::process::Stdio;
|
||||
use std::{collections::HashMap, os::unix::process::ExitStatusExt};
|
||||
use tokio::process::Command;
|
||||
|
||||
pub struct AsyncProcessOut {
|
||||
pub exit_code: i32,
|
||||
pub stdout: String,
|
||||
pub stderr: String,
|
||||
}
|
||||
|
||||
pub async fn async_process(
|
||||
cmd: &str,
|
||||
args: Option<&[&str]>,
|
||||
env: Option<HashMap<String, String>>,
|
||||
) -> anyhow::Result<AsyncProcessOut> {
|
||||
let cmd = Command::new(cmd)
|
||||
.args(args.unwrap_or_default())
|
||||
.envs(env.unwrap_or_default())
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()?;
|
||||
let out = cmd.wait_with_output().await?;
|
||||
Ok(AsyncProcessOut {
|
||||
exit_code: out
|
||||
.status
|
||||
.code()
|
||||
.unwrap_or_else(|| out.status.signal().unwrap_or(-1337)),
|
||||
stdout: String::from_utf8(out.stdout)?,
|
||||
stderr: String::from_utf8(out.stderr)?,
|
||||
})
|
||||
}
|
|
@ -17,6 +17,7 @@ use ui::{
|
|||
cmdline_opts::CmdLineOpts,
|
||||
};
|
||||
|
||||
pub mod async_process;
|
||||
pub mod build_tools;
|
||||
pub mod builders;
|
||||
pub mod cmd_runner;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue