fix: #7614 - rebuild every time on macos because of Info.plist changes (#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>
This commit is contained in:
olexiyb 2024-06-26 14:08:14 +03:00 committed by GitHub
parent 7d85f7cf82
commit 1f6e478c84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 7 deletions

View File

@ -0,0 +1,5 @@
---
"tauri-codegen": patch:bug
---
Fixes Info.plist rewriting always triggering build to rerun.

View File

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