From 2ca06577e10454446285df270c1c394c29c8de64 Mon Sep 17 00:00:00 2001 From: Jai A Date: Mon, 9 Sep 2024 21:10:41 -0700 Subject: [PATCH] Fix MacOS code signing, RPM + DEB, MSI/NSIS --- crates/tauri-bundler/src/bundle/common.rs | 54 +++++++++---------- .../tauri-bundler/src/bundle/linux/debian.rs | 10 ++-- crates/tauri-bundler/src/bundle/linux/rpm.rs | 14 +++-- crates/tauri-bundler/src/bundle/macos/app.rs | 12 +++-- .../src/bundle/windows/msi/wix.rs | 2 +- .../tauri-bundler/src/bundle/windows/nsis.rs | 4 +- 6 files changed, 48 insertions(+), 48 deletions(-) diff --git a/crates/tauri-bundler/src/bundle/common.rs b/crates/tauri-bundler/src/bundle/common.rs index d644da69a677..78d6dc41e1c8 100644 --- a/crates/tauri-bundler/src/bundle/common.rs +++ b/crates/tauri-bundler/src/bundle/common.rs @@ -135,44 +135,44 @@ pub(crate) fn use_v1_bin_name() -> bool { env_var.as_deref() == Ok("true") || env_var.as_deref() == Ok("1") } -pub(crate) fn get_bin_name(settings: &Settings) -> &str { +pub(crate) fn get_bin_name(settings: &Settings) -> String { if use_v1_bin_name() { - settings.product_name() + let target_os = settings + .target() + .split('-') + .nth(2) + .unwrap_or(std::env::consts::OS) + .replace("darwin", "macos"); + + if target_os == "linux" { + settings.product_name().to_kebab_case() + } else { + settings.product_name().to_string() + } } else { - settings.main_binary_name() + settings.main_binary_name().to_string() } } -pub(crate) fn rename_app( - target: &str, - bin_path: &Path, - product_name: &str, -) -> crate::Result { - let target_os = target - .split('-') - .nth(2) - .unwrap_or(std::env::consts::OS) - .replace("darwin", "macos"); - - let product_name = if target_os == "linux" { - product_name.to_kebab_case() - } else { - product_name.into() - }; +pub(crate) fn rename_app(settings: &Settings, bin_path: &Path) -> crate::Result { + let bin_name = get_bin_name(settings); let product_path = bin_path .parent() .unwrap() - .join(product_name) + .join(bin_name) .with_extension(bin_path.extension().unwrap_or_default()); - fs::rename(bin_path, &product_path).with_context(|| { - format!( - "failed to rename `{}` to `{}`", - display_path(bin_path), - display_path(&product_path), - ) - })?; + if !product_path.exists() { + fs::rename(bin_path, &product_path).with_context(|| { + format!( + "failed to rename `{}` to `{}`", + display_path(bin_path), + display_path(&product_path), + ) + })?; + } + Ok(product_path) } diff --git a/crates/tauri-bundler/src/bundle/linux/debian.rs b/crates/tauri-bundler/src/bundle/linux/debian.rs index e83633ef1fc4..b5c3f09e1701 100644 --- a/crates/tauri-bundler/src/bundle/linux/debian.rs +++ b/crates/tauri-bundler/src/bundle/linux/debian.rs @@ -109,13 +109,13 @@ pub fn generate_data( for bin in settings.binaries() { let bin_path = settings.binary_path(bin); - let dest_path = bin_dir.join(bin.name()); + let dest_path = if use_v1_bin_name() && bin.name() == settings.main_binary_name() { + bin_dir.join(get_bin_name(settings)) + } else { + bin_dir.join(bin.name()) + }; common::copy_file(&bin_path, &dest_path) .with_context(|| format!("Failed to copy binary from {bin_path:?}"))?; - - if use_v1_bin_name() && bin.name() == settings.main_binary_name() { - rename_app(settings.target(), &dest_path, settings.product_name())?; - } } copy_resource_files(settings, &data_dir).with_context(|| "Failed to copy resource files")?; diff --git a/crates/tauri-bundler/src/bundle/linux/rpm.rs b/crates/tauri-bundler/src/bundle/linux/rpm.rs index 0cf49091735d..2a7194d842de 100644 --- a/crates/tauri-bundler/src/bundle/linux/rpm.rs +++ b/crates/tauri-bundler/src/bundle/linux/rpm.rs @@ -100,17 +100,15 @@ pub fn bundle_project(settings: &Settings) -> crate::Result> { // Add binaries for bin in settings.binaries() { - let src = if use_v1_bin_name() && bin.name() == settings.main_binary_name() { - rename_app( - settings.target(), - &settings.binary_path(bin), - settings.product_name(), - )? + let src = settings.binary_path(bin); + + let dest_name = if bin.name() == settings.main_binary_name() { + get_bin_name(settings) } else { - settings.binary_path(bin) + bin.name().to_string() }; - let dest = Path::new("/usr/bin").join(bin.name()); + let dest = Path::new("/usr/bin").join(dest_name); builder = builder.with_file(src, FileOptions::new(dest.to_string_lossy()))?; } diff --git a/crates/tauri-bundler/src/bundle/macos/app.rs b/crates/tauri-bundler/src/bundle/macos/app.rs index 1651671026ab..c34b2a260977 100644 --- a/crates/tauri-bundler/src/bundle/macos/app.rs +++ b/crates/tauri-bundler/src/bundle/macos/app.rs @@ -31,7 +31,7 @@ use crate::Settings; use anyhow::Context; -use crate::bundle::common::{get_bin_name, rename_app, use_v1_bin_name}; +use crate::bundle::common::get_bin_name; use std::{ ffi::OsStr, fs, @@ -157,12 +157,14 @@ fn copy_binaries_to_bundle( let dest_dir = bundle_directory.join("MacOS"); for bin in settings.binaries() { let bin_path = settings.binary_path(bin); - let dest_path = dest_dir.join(bin.name()); + let dest_path = if bin.name() == settings.main_binary_name() { + dest_dir.join(get_bin_name(settings)) + } else { + dest_dir.join(bin.name()) + }; + common::copy_file(&bin_path, &dest_path) .with_context(|| format!("Failed to copy binary from {:?}", bin_path))?; - if use_v1_bin_name() && bin.name() == settings.main_binary_name() { - rename_app(settings.target(), &dest_path, settings.product_name())?; - } paths.push(dest_path); } Ok(paths) diff --git a/crates/tauri-bundler/src/bundle/windows/msi/wix.rs b/crates/tauri-bundler/src/bundle/windows/msi/wix.rs index 3e2da76d3b04..dd2eb153e60d 100644 --- a/crates/tauri-bundler/src/bundle/windows/msi/wix.rs +++ b/crates/tauri-bundler/src/bundle/windows/msi/wix.rs @@ -404,7 +404,7 @@ pub fn build_wix_app_installer( .ok_or_else(|| anyhow::anyhow!("Failed to get main binary"))?; let old_binary_path = settings.binary_path(main_binary); let app_exe_source = if use_v1_bin_name() { - rename_app(settings.target(), &old_binary_path, settings.product_name())? + rename_app(settings, &old_binary_path)? } else { old_binary_path }; diff --git a/crates/tauri-bundler/src/bundle/windows/nsis.rs b/crates/tauri-bundler/src/bundle/windows/nsis.rs index 2a343b23e920..f577871ad87e 100644 --- a/crates/tauri-bundler/src/bundle/windows/nsis.rs +++ b/crates/tauri-bundler/src/bundle/windows/nsis.rs @@ -345,7 +345,7 @@ fn build_nsis_app_installer( let old_binary_path = settings.binary_path(main_binary).with_extension("exe"); let main_binary_path = if use_v1_bin_name() { - rename_app(settings.target(), &old_binary_path, settings.product_name())? + rename_app(settings, &old_binary_path)? } else { old_binary_path }; @@ -356,7 +356,7 @@ fn build_nsis_app_installer( main_binary_path .file_stem() .and_then(|file_name| file_name.to_str()) - .unwrap_or_else(|| get_bin_name(settings)), + .unwrap_or(get_bin_name(settings).as_str()), ), ); data.insert("main_binary_path", to_json(&main_binary_path));