Skip to content

fix: #7614 - rebuild every time on macos because of Info.plist changes - #9878

Merged
lucasfernog merged 7 commits into
tauri-apps:devfrom
Sanctum-AI:fix/macos-rebuild-every-rerun
Jun 26, 2024
Merged

lucasfernog merged 7 commits into
tauri-apps:devfrom
Sanctum-AI:fix/macos-rebuild-every-rerun

Conversation

@olexiyb

@olexiyb olexiyb commented May 25, 2024 •

Copy link
Copy Markdown
Contributor

According to macos documentation

This key is a machine-readable string composed of one to three period-separated integers, such as 10.14.1. The string can only contain numeric characters (0-9) and periods.

Each integer provides information about the build version in the format [Major].[Minor].[Patch]:

Major: A major revision number.

Minor: A minor revision number.

Patch: A maintenance release number.

You can include more integers but the system ignores them.

Current logic of the build prepare Info.plist with added timestamp at the end, this cause rebuild each restart even if not needed. Because You can include more integers but the system ignores them it does not make any sense to add timestamp

I also have to check Info.plist content from previous build with new build. If no changes just skip the write

This should solve #7614

@olexiyb
olexiyb requested a review from a team as a code owner May 25, 2024 09:32

@lucasfernog lucasfernog left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch, can you clean this up so it only serializes the plist once?

diff --git a/core/tauri-codegen/src/context.rs b/core/tauri-codegen/src/context.rs
index 59e9a78ef..ace1e345a 100644
--- a/core/tauri-codegen/src/context.rs
+++ b/core/tauri-codegen/src/context.rs
@@ -4,6 +4,7 @@
 
 use std::collections::BTreeMap;
 use std::convert::identity;
+use std::io::BufWriter;
 use std::path::{Path, PathBuf};
 use std::{ffi::OsStr, str::FromStr};
 
@@ -328,18 +329,20 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
         plist.insert("CFBundleVersion".into(), version.clone().into());
       }
     }
-    
+
     let plist_file = out_dir.join("Info.plist");
-    let old = if plist_file.exists() {
-      plist::Value::from_file(&plist_file).expect("failed to read old Info.plist")
-    } else {
-      plist::Value::Dictionary(Default::default())
-    };
-    let old = serde_json::to_string(&old).unwrap();
-    let n = serde_json::to_string(&info_plist).unwrap();
-    if old.ne(&n) {
-      info_plist.to_file_xml(plist_file).expect("failed to write Info.plist");
+
+    let mut plist_contents = BufWriter::new(Vec::new());
+    info_plist
+      .to_writer_xml(&mut plist_contents)
+      .expect("failed to serialize plist");
+    let plist_contents =
+      String::from_utf8_lossy(&plist_contents.into_inner().unwrap()).into_owned();
+
+    if plist_contents != std::fs::read_to_string(&plist_file).unwrap_or_default() {
+      std::fs::write(&plist_file, &plist_contents).expect("failed to write Info.plist");
     }
+
     quote!({
       tauri::embed_plist::embed_info_plist!(concat!(std::env!("OUT_DIR"), "/Info.plist"));
     })

@lucasfernog lucasfernog left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must fix clippy and also add a change file in the .changes folder:

.changes/fix-build-script-rerun-macos.md

---
"tauri-codegen": patch:bug
---

Fixes Info.plist rewriting always triggering build to rerun.

Comment thread core/tauri-codegen/src/context.rs Outdated
Comment thread core/tauri-codegen/src/context.rs Outdated
olexiyb and others added 4 commits May 29, 2024 12:00
Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>
Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>
@olexiyb
olexiyb requested a review from lucasfernog June 17, 2024 14:45
@lucasfernog
lucasfernog merged commit 1f6e478 into tauri-apps:dev Jun 26, 2024
@olexiyb
olexiyb deleted the fix/macos-rebuild-every-rerun branch July 1, 2024 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants