From 9ad8314f1a319d3b18c1e3b488b11e2a0ad5d263 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Fri, 19 Jan 2024 14:06:25 -0500 Subject: [PATCH] Fix #1021 --- dylint/src/metadata/cli/mod.rs | 37 ++++++++++++++++++++++++---------- internal/src/command.rs | 5 ++++- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/dylint/src/metadata/cli/mod.rs b/dylint/src/metadata/cli/mod.rs index 7b81df9ed..2357de4a7 100644 --- a/dylint/src/metadata/cli/mod.rs +++ b/dylint/src/metadata/cli/mod.rs @@ -25,6 +25,7 @@ use std::{ ffi::{OsStr, OsString}, fs::{create_dir_all, read_dir, remove_dir_all, write}, path::{Path, PathBuf}, + process::Output, }; use tempfile::{tempdir, Builder, TempDir}; use url::Url; @@ -148,18 +149,31 @@ fn git_dependency_root(url: &str, details: &DetailedTomlDependency) -> Result Ok(path), + (Err(err), true) => Err(err), + (Err(err), false) => Err(err).with_context(|| { + format!( + "fetching packages failed\nstdout: {:?}\nstderr: {:?}", + String::from_utf8(output.stdout).unwrap_or_default(), + String::from_utf8(output.stderr).unwrap_or_default() + ) + }), + }?; Ok(path.to_path_buf()) } @@ -239,19 +253,20 @@ fn inject_dummy_dependencies( Ok(injected_dependencies) } -fn cargo_fetch(path: &Path) -> Result<()> { +fn cargo_fetch(path: &Path) -> Result { // smoelius: `cargo fetch` could fail, e.g., if a new checkouts subdirectory had to be created. // But the command should still be executed. // smoelius: Since stdout and stderr are captured, there is no need to use `.quiet(true)`. - let _output = dylint_internal::cargo::fetch("dummy package") + // smoelius: We still want to hide the message, though. + dylint_internal::cargo::fetch("dummy package") + .quiet(dylint_internal::cargo::Quiet::MESSAGE) .stable(true) .build() .args([ "--manifest-path", &path.join("Cargo.toml").to_string_lossy(), ]) - .logged_output(false)?; - Ok(()) + .logged_output(false) } fn cargo_metadata(path: &Path) -> Result { diff --git a/internal/src/command.rs b/internal/src/command.rs index cd8cd98b1..a3b4f31fb 100644 --- a/internal/src/command.rs +++ b/internal/src/command.rs @@ -1,7 +1,7 @@ use anyhow::{ensure, Context, Result}; use std::{ path::Path, - process::{Command, Output}, + process::{Command, Output, Stdio}, }; #[allow(clippy::module_name_repetitions)] @@ -18,6 +18,9 @@ impl CommandExt for Command { log::debug!("{:?}", self.get_current_dir()); log::debug!("{:?}", self); + self.stdout(Stdio::piped()); + self.stderr(Stdio::piped()); + #[allow(clippy::disallowed_methods)] let output = self .output()