Skip to content

Commit

Permalink
Fix #1021
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Jan 19, 2024
1 parent a34dd16 commit 9ad8314
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
37 changes: 26 additions & 11 deletions dylint/src/metadata/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -148,18 +149,31 @@ fn git_dependency_root(url: &str, details: &DetailedTomlDependency) -> Result<Pa
BTreeMap::new()
};

cargo_fetch(package.path())?;
let output = cargo_fetch(package.path())?;

// smoelius: `cargo metadata` will fail if `cargo fetch` had to create a new checkouts
// subdirectory.
let metadata = cargo_metadata(package.path()).ok();

let path = find_accessed_subdir(
&dep_name,
&checkout_path,
&injected_dependencies,
metadata.as_ref(),
)?;
let path = match (
find_accessed_subdir(
&dep_name,
&checkout_path,
&injected_dependencies,
metadata.as_ref(),
),
output.status.success(),
) {
(Ok(path), _) => 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())
}
Expand Down Expand Up @@ -239,19 +253,20 @@ fn inject_dummy_dependencies(
Ok(injected_dependencies)
}

fn cargo_fetch(path: &Path) -> Result<()> {
fn cargo_fetch(path: &Path) -> Result<Output> {
// 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<Metadata> {
Expand Down
5 changes: 4 additions & 1 deletion internal/src/command.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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()
Expand Down

0 comments on commit 9ad8314

Please sign in to comment.