Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1248: Inherit stderr when running `cargo metadata` r=messense a=messense Use an extension trait to achieve the same functionality so we don't need to wait for upstream. Fixes #1243 Co-authored-by: messense <messense@icloud.com>
- Loading branch information
Showing
5 changed files
with
32 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use cargo_metadata::{Metadata, MetadataCommand}; | ||
use std::process::Stdio; | ||
|
||
pub trait MetadataCommandExt { | ||
/// Runs configured `cargo metadata` and returns parsed `Metadata`. | ||
/// Inherits stderr from parent process. | ||
fn exec_inherit_stderr(&self) -> Result<Metadata, cargo_metadata::Error>; | ||
} | ||
|
||
impl MetadataCommandExt for MetadataCommand { | ||
fn exec_inherit_stderr(&self) -> Result<Metadata, cargo_metadata::Error> { | ||
let mut command = self.cargo_command(); | ||
command.stderr(Stdio::inherit()); | ||
let output = command.output()?; | ||
if !output.status.success() { | ||
return Err(cargo_metadata::Error::CargoMetadata { | ||
stderr: String::from_utf8(output.stderr)?, | ||
}); | ||
} | ||
let stdout = std::str::from_utf8(&output.stdout)? | ||
.lines() | ||
.find(|line| line.starts_with('{')) | ||
.ok_or(cargo_metadata::Error::NoJson)?; | ||
Self::parse(stdout) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters