use std::path::PathBuf;
const RUSTC_WRAPPER_ENV_KEYS: [&str; 4] = [
"RUSTC_WRAPPER",
"CARGO_BUILD_RUSTC_WRAPPER",
"RUSTC_WORKSPACE_WRAPPER",
"CARGO_BUILD_RUSTC_WORKSPACE_WRAPPER",
];
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub enum ProcessStdin {
#[default]
Null,
Bytes(Vec<u8>),
}
#[derive(Clone, Debug, Default)]
pub struct ProcessCommandConfig {
pub cwd: Option<PathBuf>,
pub env: Vec<(String, String)>,
pub env_remove: Vec<String>,
pub stdin: ProcessStdin,
pub closed_env: bool,
}
pub fn apply_active_rustc_wrapper_policy(
env: &mut Vec<(String, String)>,
env_remove: &mut Vec<String>,
) {
if super::active_sandbox_policy().is_some() {
neutralize_rustc_wrapper(env, env_remove);
}
}
pub(super) fn neutralize_rustc_wrapper(
env: &mut Vec<(String, String)>,
env_remove: &mut Vec<String>,
) {
for key in RUSTC_WRAPPER_ENV_KEYS {
env.retain(|(existing, _)| !existing.eq_ignore_ascii_case(key));
env_remove.retain(|removed| !removed.eq_ignore_ascii_case(key));
env.push((key.to_string(), String::new()));
}
}