From be5f9a291b75d3a28c58d3ef505c0095ee459d50 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Fri, 10 May 2024 01:21:33 +0000 Subject: [PATCH] Eliminate two uses of `subprocess` --- cargo-test-fuzz/src/lib.rs | 25 ++++++++++++------------- testing/Cargo.toml | 1 - testing/src/examples.rs | 16 +++++++++++----- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/cargo-test-fuzz/src/lib.rs b/cargo-test-fuzz/src/lib.rs index 37da5c06..ebbf7f55 100644 --- a/cargo-test-fuzz/src/lib.rs +++ b/cargo-test-fuzz/src/lib.rs @@ -25,9 +25,8 @@ use std::{ fmt::{Debug, Formatter}, fs::{create_dir_all, read, read_dir, remove_dir_all, File}, io::{BufRead, Read}, - iter, path::{Path, PathBuf}, - process::{exit, Command}, + process::{exit, Command, Stdio}, sync::OnceLock, time::Duration, }; @@ -263,19 +262,19 @@ fn build(opts: &TestFuzz, quiet: bool) -> Result> { // `AFL_QUIET=1` doesn't work here, so pipe standard error to /dev/null. // smoelius: Suppressing all of standard error is too extreme. For now, suppress only when // displaying/replaying. - let mut exec = Exec::cmd("cargo") - .args( - &args - .iter() - .chain(iter::once(&"--message-format=json")) - .collect::>(), - ) - .stdout(Redirection::Pipe); + let mut command = Command::new("cargo"); + command + .args(&args) + .arg("--message-format=json") + .stdout(Stdio::piped()); if quiet && !opts.verbose { - exec = exec.stderr(NullFile); + command.stderr(Stdio::null()); } - debug!("{:?}", exec); - let mut popen = exec.clone().popen()?; + debug!("{command:?}"); + let exec = format!("{command:?}"); + let mut popen = command + .spawn() + .with_context(|| format!("Could not spawn `{exec:?}`"))?; let artifacts = popen .stdout .take() diff --git a/testing/Cargo.toml b/testing/Cargo.toml index 77431952..71ccfd2b 100644 --- a/testing/Cargo.toml +++ b/testing/Cargo.toml @@ -14,7 +14,6 @@ if_chain = "1.0" log = "0.4" once_cell = "1.19" retry = "2.0" -subprocess = "0.2" internal = { path = "../internal", package = "test-fuzz-internal", version = "=5.1.0" } diff --git a/testing/src/examples.rs b/testing/src/examples.rs index 2ee76aa9..f62e58f0 100644 --- a/testing/src/examples.rs +++ b/testing/src/examples.rs @@ -5,8 +5,10 @@ use if_chain::if_chain; use internal::serde_format; use log::debug; use once_cell::sync::Lazy; -use std::path::Path; -use subprocess::{Exec, Redirection}; +use std::{ + path::Path, + process::{Command as StdCommand, Stdio}, +}; pub static MANIFEST_PATH: Lazy = Lazy::new(|| { #[cfg_attr(dylint_lib = "general", allow(abs_home_path))] @@ -35,9 +37,13 @@ pub fn test(krate: &str, test: &str) -> Result { ]; args.extend_from_slice(&["--no-run", "--message-format=json"]); - let exec = Exec::cmd("cargo").args(&args).stdout(Redirection::Pipe); - debug!("{:?}", exec); - let mut popen = exec.clone().popen()?; + let mut command = StdCommand::new("cargo"); + command.args(&args).stdout(Stdio::piped()); + debug!("{command:?}"); + let exec = format!("{command:?}"); + let mut popen = command + .spawn() + .with_context(|| format!("Could not spawn `{exec:?}`"))?; let messages = popen .stdout .take()