Skip to content

Commit

Permalink
fix(android): avoid rebuilds if nothing changed
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Flakebi committed Aug 16, 2024
1 parent 255d64e commit e871e55
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
37 changes: 26 additions & 11 deletions core/tauri-build/src/mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
8 changes: 7 additions & 1 deletion core/tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down

0 comments on commit e871e55

Please sign in to comment.