From 09909212654f1a362bf6457477e57ddd7e0bbb0e Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sat, 20 Jan 2024 09:00:55 -0300 Subject: [PATCH] optimize build scripts [skip ci] --- core/tauri-build/src/lib.rs | 10 ++++++---- core/tauri-utils/src/acl/build.rs | 9 ++++++--- core/tauri/build.rs | 7 +++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index 227761d3c1c0..5aab858b5f4c 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -25,6 +25,7 @@ use tauri_utils::{ use std::{ env::var_os, + fs::read_to_string, path::{Path, PathBuf}, }; @@ -484,10 +485,11 @@ pub fn try_build(attributes: Attributes) -> Result<()> { acl::validate_capabilities(&plugin_manifests, &capabilities)?; - std::fs::write( - out_dir.join(CAPABILITIES_FILE_NAME), - serde_json::to_string(&capabilities)?, - )?; + let capabilities_path = out_dir.join(CAPABILITIES_FILE_NAME); + let capabilities_json = serde_json::to_string(&capabilities)?; + if capabilities_json != read_to_string(&capabilities_path).unwrap_or_default() { + std::fs::write(capabilities_path, capabilities_json)?; + } println!("cargo:rustc-env=TAURI_ENV_TARGET_TRIPLE={target_triple}"); diff --git a/core/tauri-utils/src/acl/build.rs b/core/tauri-utils/src/acl/build.rs index 5e4e854cd26a..9f001c29b34a 100644 --- a/core/tauri-utils/src/acl/build.rs +++ b/core/tauri-utils/src/acl/build.rs @@ -7,7 +7,7 @@ use std::{ collections::{BTreeMap, HashMap}, env::{current_dir, vars_os}, - fs::{create_dir_all, File}, + fs::{create_dir_all, read_to_string, File}, io::{BufWriter, Write}, path::{Path, PathBuf}, }; @@ -309,7 +309,10 @@ commands.deny = ["{command}"] schema_path = schema_path.display().to_string().replace('\\', "\\\\") ); - std::fs::write(path.join(format!("{command}.toml")), toml) - .unwrap_or_else(|_| panic!("unable to autogenerate ${command}.toml")); + let out_path = path.join(format!("{command}.toml")); + if toml != read_to_string(&out_path).unwrap_or_default() { + std::fs::write(out_path, toml) + .unwrap_or_else(|_| panic!("unable to autogenerate ${command}.toml")); + } } } diff --git a/core/tauri/build.rs b/core/tauri/build.rs index 5739c88f5d71..e944be71b76f 100644 --- a/core/tauri/build.rs +++ b/core/tauri/build.rs @@ -312,8 +312,11 @@ permissions = [{default_permissions}] "###, ); - std::fs::write(autogenerated.join("default.toml"), default_toml) - .unwrap_or_else(|_| panic!("unable to autogenerate default permissions")); + let out_path = autogenerated.join("default.toml"); + if default_toml != read_to_string(&out_path).unwrap_or_default() { + std::fs::write(out_path, default_toml) + .unwrap_or_else(|_| panic!("unable to autogenerate default permissions")); + } let permissions = tauri_utils::acl::build::define_permissions( &format!("./permissions/{plugin}/**/*.toml"),