Skip to content

Commit

Permalink
optimize build scripts [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jan 20, 2024
1 parent 1b29ff7 commit 0990921
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
10 changes: 6 additions & 4 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use tauri_utils::{

use std::{
env::var_os,
fs::read_to_string,
path::{Path, PathBuf},
};

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

Expand Down
9 changes: 6 additions & 3 deletions core/tauri-utils/src/acl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -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"));
}
}
}
7 changes: 5 additions & 2 deletions core/tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 0990921

Please sign in to comment.