feat(build): add API to update the iOS entitlements file (#7448)

This commit is contained in:
Lucas Fernandes Nogueira
2023-07-18 06:20:55 -07:00
committed by GitHub
parent aa94f7197e
commit aba04fa823
3 changed files with 40 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"tauri-build": patch:feat
---
Added the `mobile::update_entitlements` function for iOS.

View File

@@ -32,6 +32,7 @@ semver = "1"
[target."cfg(target_os = \"macos\")".dependencies]
swift-rs = { version = "1.0.5", features = [ "build" ] }
plist = "1"
[features]
codegen = [ "tauri-codegen", "quote" ]

View File

@@ -146,6 +146,40 @@ fn copy_folder(source: &Path, target: &Path, ignore_paths: &[&str]) -> Result<()
Ok(())
}
#[cfg(target_os = "macos")]
fn update_plist_file<P: AsRef<Path>, F: FnOnce(&mut plist::Dictionary)>(
path: P,
f: F,
) -> Result<()> {
let path = path.as_ref();
if path.exists() {
let mut plist = plist::Value::from_file(path)?;
if let Some(dict) = plist.as_dictionary_mut() {
f(dict);
plist::to_file_xml(path, &plist)?;
}
}
Ok(())
}
#[cfg(target_os = "macos")]
pub fn update_entitlements<F: FnOnce(&mut plist::Dictionary)>(f: F) -> Result<()> {
if let (Some(project_path), Ok(app_name)) = (
var_os("TAURI_IOS_PROJECT_PATH").map(PathBuf::from),
var("TAURI_IOS_APP_NAME"),
) {
update_plist_file(
project_path
.join(format!("{app_name}_iOS"))
.join(format!("{app_name}_iOS.entitlements")),
f,
)?;
}
Ok(())
}
pub(crate) fn generate_gradle_files(project_dir: PathBuf) -> Result<()> {
let gradle_settings_path = project_dir.join("tauri.settings.gradle");
let app_build_gradle_path = project_dir.join("app").join("tauri.build.gradle.kts");