Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from
Jun 26, 2024

Conversation

olexiyb
Copy link
Contributor

@olexiyb olexiyb commented May 25, 2024

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
Copy link
Member

@lucasfernog lucasfernog left a comment

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"));
     })

Copy link
Member

@lucasfernog lucasfernog left a comment

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.

core/tauri-codegen/src/context.rs Outdated Show resolved Hide resolved
core/tauri-codegen/src/context.rs Outdated Show resolved Hide resolved
@olexiyb olexiyb requested a review from lucasfernog June 17, 2024 14:45
@lucasfernog lucasfernog merged commit 1f6e478 into tauri-apps:dev Jun 26, 2024
16 of 19 checks passed
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.

None yet

2 participants