From e871e552136afea1207bb72786337c5904c74374 Mon Sep 17 00:00:00 2001 From: Flakebi Date: Fri, 16 Aug 2024 11:10:44 +0200 Subject: [PATCH] fix(android): avoid rebuilds if nothing changed Unconditionally overwriting files where the build reruns if they changed leads to rebuilds every time. Only overwrite a file if its content is different to not rebuild in such a case. --- core/tauri-build/src/mobile.rs | 37 ++++++++++++++++++++++++---------- core/tauri/build.rs | 8 +++++++- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/core/tauri-build/src/mobile.rs b/core/tauri-build/src/mobile.rs index 3c8e7c1cb797..4e60a9b335dd 100644 --- a/core/tauri-build/src/mobile.rs +++ b/core/tauri-build/src/mobile.rs @@ -80,20 +80,35 @@ dependencies {" } } - write(&gradle_settings_path, gradle_settings).context("failed to write tauri.settings.gradle")?; + // Overwrite only if changed to not trigger rebuilds + if std::fs::read_to_string(&gradle_settings_path) + .map(|o| o != gradle_settings) + .unwrap_or(true) + { + write(&gradle_settings_path, gradle_settings) + .context("failed to write tauri.settings.gradle")?; + } - write(&app_build_gradle_path, app_build_gradle) - .context("failed to write tauri.build.gradle.kts")?; + if std::fs::read_to_string(&app_build_gradle_path) + .map(|o| o != app_build_gradle) + .unwrap_or(true) + { + write(&app_build_gradle_path, app_build_gradle) + .context("failed to write tauri.build.gradle.kts")?; + } if !app_tauri_properties.is_empty() { - write( - &app_tauri_properties_path, - format!( - "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n{}", - app_tauri_properties.join("\n") - ), - ) - .context("failed to write tauri.properties")?; + let app_tauri_properties_content = format!( + "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.\n{}", + app_tauri_properties.join("\n") + ); + if std::fs::read_to_string(&app_tauri_properties_path) + .map(|o| o != app_tauri_properties_content) + .unwrap_or(true) + { + write(&app_tauri_properties_path, app_tauri_properties_content) + .context("failed to write tauri.properties")?; + } } println!("cargo:rerun-if-changed={}", gradle_settings_path.display()); diff --git a/core/tauri/build.rs b/core/tauri/build.rs index b1935105d15d..1f7bfeb3592a 100644 --- a/core/tauri/build.rs +++ b/core/tauri/build.rs @@ -289,7 +289,13 @@ fn main() { .replace("{{library}}", &library); let out_path = kotlin_out_dir.join(file.file_name()); - write(&out_path, content).expect("Failed to write kotlin file"); + // Overwrite only if changed to not trigger rebuilds + if std::fs::read_to_string(&out_path) + .map(|o| o != content) + .unwrap_or(true) + { + write(&out_path, content).expect("Failed to write kotlin file"); + } println!("cargo:rerun-if-changed={}", out_path.display()); } }