Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/toolchain/src/lib.rs')
| -rw-r--r-- | crates/toolchain/src/lib.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/crates/toolchain/src/lib.rs b/crates/toolchain/src/lib.rs index a0603e35a0..33578e056e 100644 --- a/crates/toolchain/src/lib.rs +++ b/crates/toolchain/src/lib.rs @@ -1,6 +1,12 @@ //! Discovery of `cargo` & `rustc` executables. -use std::{env, iter, path::PathBuf}; +use std::{ + env, + ffi::OsStr, + iter, + path::{Path, PathBuf}, + process::Command, +}; use camino::{Utf8Path, Utf8PathBuf}; @@ -65,6 +71,14 @@ impl Tool { } } +pub fn command(cmd: impl AsRef<OsStr>, working_directory: impl AsRef<Path>) -> Command { + // we are `toolchain::command`` + #[allow(clippy::disallowed_methods)] + let mut cmd = Command::new(cmd); + cmd.current_dir(working_directory); + cmd +} + fn invoke(list: &[fn(&str) -> Option<Utf8PathBuf>], executable: &str) -> Utf8PathBuf { list.iter().find_map(|it| it(executable)).unwrap_or_else(|| executable.into()) } |