Skip to content

Commit

Permalink
fix: #7614 - rebuild every time on macos because of Info.plist changes (
Browse files Browse the repository at this point in the history
#9878)

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

* apply proposed patch from lucasfernog

* Update core/tauri-codegen/src/context.rs

Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>

* Update core/tauri-codegen/src/context.rs

Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>

* added changes file

---------

Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>
  • Loading branch information
olexiyb and lucasfernog committed Jun 26, 2024
1 parent 7d85f7c commit 1f6e478
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-build-script-rerun-macos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri-codegen": patch:bug
---

Fixes Info.plist rewriting always triggering build to rerun.
20 changes: 13 additions & 7 deletions core/tauri-codegen/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,23 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult<TokenStream> {
}
if let Some(version) = &config.version {
plist.insert("CFBundleShortVersionString".into(), version.clone().into());
}
let format =
time::format_description::parse("[year][month][day].[hour][minute][second]").unwrap();
if let Ok(build_number) = time::OffsetDateTime::now_utc().format(&format) {
plist.insert("CFBundleVersion".into(), build_number.into());
plist.insert("CFBundleVersion".into(), version.clone().into());
}
}

let plist_file = out_dir.join("Info.plist");

let mut plist_contents = std::io::BufWriter::new(Vec::new());
info_plist
.to_file_xml(out_dir.join("Info.plist"))
.expect("failed to write 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"));
})
Expand Down

0 comments on commit 1f6e478

Please sign in to comment.