Skip to content

Commit

Permalink
Fix zng_tp_licenses::collect_cargo_about call in Powershell (#552)
Browse files Browse the repository at this point in the history
cargo about now prints an error for stdio redirect in powershell
  • Loading branch information
SamRodri authored Nov 20, 2024
1 parent 39be6fc commit d7d0821
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

* Fix `zng_tp_licenses::collect_cargo_about` call in Powershell.

# 0.12.9

Expand Down
3 changes: 3 additions & 0 deletions crates/zng-tp-licenses/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ serde_json = { version = "1.0", optional = true }
deflate = { version = "1.0", optional = true }
inflate = { version = "0.4", optional = true }
bincode = { version = "1.3", optional = true }

[target.'cfg(windows)'.dependencies]
tempfile = "3.10"
11 changes: 11 additions & 0 deletions crates/zng-tp-licenses/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ pub fn collect_cargo_about(about_cfg_path: &str) -> Vec<LicenseUsed> {
.arg("json")
.arg("--all-features");

// cargo about returns an error on stdout redirect in PowerShell
#[cfg(windows)]
let temp_file = tempfile::NamedTempFile::new().expect("cannot crate temp file for windows output");
#[cfg(windows)]
{
cargo_about.arg("--output-file").arg(temp_file.path());
}

if !about_cfg_path.is_empty() {
cargo_about.arg("-c").arg(about_cfg_path);
}
Expand All @@ -154,6 +162,9 @@ pub fn collect_cargo_about(about_cfg_path: &str) -> Vec<LicenseUsed> {
output.status
);

#[cfg(windows)]
let json = std::fs::read_to_string(temp_file.path()).expect("cannot read temp file with windows output");
#[cfg(not(windows))]
let json = String::from_utf8(output.stdout).unwrap();

parse_cargo_about(&json).expect("error parsing `cargo about` output")
Expand Down

0 comments on commit d7d0821

Please sign in to comment.