Skip to content

Commit

Permalink
fix(macos-sign): missing stdout/stderr in Node.js context (#10654)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored Aug 16, 2024
1 parent 10fb027 commit 1b0c447
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-missing-codesign-error-macos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-macos-sign": patch:bug
---

Fixes output not visible when running on Node.js via NAPI.
1 change: 1 addition & 0 deletions tooling/bundler/src/bundle/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ pub trait CommandExt {

impl CommandExt for Command {
fn piped(&mut self) -> std::io::Result<ExitStatus> {
self.stdin(os_pipe::dup_stdin()?);
self.stdout(os_pipe::dup_stdout()?);
self.stderr(os_pipe::dup_stderr()?);
let program = self.get_program().to_string_lossy().into_owned();
Expand Down
1 change: 1 addition & 0 deletions tooling/cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tooling/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ pub trait CommandExt {

impl CommandExt for Command {
fn piped(&mut self) -> std::io::Result<ExitStatus> {
self.stdin(os_pipe::dup_stdin()?);
self.stdout(os_pipe::dup_stdout()?);
self.stderr(os_pipe::dup_stderr()?);
let program = self.get_program().to_string_lossy().into_owned();
Expand Down
1 change: 1 addition & 0 deletions tooling/macos-sign/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ os_pipe = "1"
plist = "1"
rand = "0.8"
dirs-next = "2"
log = "0.4"
18 changes: 9 additions & 9 deletions tooling/macos-sign/src/keychain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
process::Command,
};

use crate::assert_command;
use crate::{assert_command, CommandExt};
use anyhow::Result;
use rand::distributions::{Alphanumeric, DistString};

Expand All @@ -33,7 +33,7 @@ impl Drop for Keychain {
let _ = Command::new("security")
.arg("delete-keychain")
.arg(path)
.status();
.piped();
}
}
}
Expand Down Expand Up @@ -77,15 +77,15 @@ impl Keychain {
Command::new("security")
.args(["create-keychain", "-p", &keychain_password])
.arg(&keychain_path)
.status(),
.piped(),
"failed to create keychain",
)?;

assert_command(
Command::new("security")
.args(["unlock-keychain", "-p", &keychain_password])
.arg(&keychain_path)
.status(),
.piped(),
"failed to set unlock keychain",
)?;

Expand All @@ -105,15 +105,15 @@ impl Keychain {
])
.arg("-k")
.arg(&keychain_path)
.status(),
.piped(),
"failed to import keychain certificate",
)?;

assert_command(
Command::new("security")
.args(["set-keychain-settings", "-t", "3600", "-u"])
.arg(&keychain_path)
.status(),
.piped(),
"failed to set keychain settings",
)?;

Expand All @@ -128,7 +128,7 @@ impl Keychain {
&keychain_password,
])
.arg(&keychain_path)
.status(),
.piped(),
"failed to set keychain settings",
)?;

Expand All @@ -147,7 +147,7 @@ impl Keychain {
.args(["list-keychain", "-d", "user", "-s"])
.args(current_keychains)
.arg(&keychain_path)
.status(),
.piped(),
"failed to list keychain",
)?;

Expand Down Expand Up @@ -209,7 +209,7 @@ impl Keychain {

codesign.arg(path);

assert_command(codesign.status(), "failed to sign app")?;
assert_command(codesign.piped(), "failed to sign app")?;

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions tooling/macos-sign/src/keychain/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fn get_pem_list(keychain_path: &Path, name_substr: &str) -> std::io::Result<std:
.arg("-c")
.arg(name_substr)
.arg(keychain_path)
.stdin(os_pipe::dup_stdin().unwrap())
.stderr(os_pipe::dup_stderr().unwrap())
.output()
}
Expand Down
24 changes: 21 additions & 3 deletions tooling/macos-sign/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::{
ffi::{OsStr, OsString},
path::{Path, PathBuf},
process::Command,
process::{Command, ExitStatus},
};

use anyhow::{Context, Result};
Expand All @@ -17,6 +17,24 @@ mod provisioning_profile;
pub use keychain::{Keychain, Team};
pub use provisioning_profile::ProvisioningProfile;

trait CommandExt {
// The `pipe` function sets the stdout and stderr to properly
// show the command output in the Node.js wrapper.
fn piped(&mut self) -> std::io::Result<ExitStatus>;
}

impl CommandExt for Command {
fn piped(&mut self) -> std::io::Result<ExitStatus> {
self.stdin(os_pipe::dup_stdin()?);
self.stdout(os_pipe::dup_stdout()?);
self.stderr(os_pipe::dup_stderr()?);
let program = self.get_program().to_string_lossy().into_owned();
log::debug!(action = "Running"; "Command `{} {}`", program, self.get_args().map(|arg| arg.to_string_lossy()).fold(String::new(), |acc, arg| format!("{acc} {arg}")));

self.status().map_err(Into::into)
}
}

pub enum ApiKey {
Path(PathBuf),
Raw(Vec<u8>),
Expand Down Expand Up @@ -71,7 +89,7 @@ pub fn notarize(
// use ditto to create a PKZip almost identical to Finder
// this remove almost 99% of false alarm in notarization
assert_command(
Command::new("ditto").args(zip_args).status(),
Command::new("ditto").args(zip_args).piped(),
"failed to zip app with ditto",
)?;

Expand Down Expand Up @@ -230,7 +248,7 @@ fn decode_base64(base64: &OsStr, out_path: &Path) -> Result<()> {
.arg(&src_path)
.arg("-o")
.arg(out_path)
.status(),
.piped(),
"failed to decode certificate",
)?;

Expand Down

0 comments on commit 1b0c447

Please sign in to comment.