Enforce a current directory being set for spawned commands

This commit is contained in:
Lukas Wirth 2024-12-29 12:51:13 +01:00
parent 0f95e60da3
commit 5ce14b0439
22 changed files with 99 additions and 75 deletions

View file

@ -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())
}