From e289dd95a435ad069e8252519a2e1232f9376d98 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Sat, 31 Aug 2024 17:29:33 -0300 Subject: [PATCH] feat(apple): allow provisioning updates for Target::build (#381) follow up for #371, turns out in CI we also need to provide the values for the target.build() usage --- .changes/apple-build-options.md | 5 ++++ .changes/move-auth-credentials.md | 5 ++++ src/apple/cli.rs | 20 +++++++++++++--- src/apple/device/mod.rs | 17 +++++++++++--- src/apple/mod.rs | 9 +++++++ src/apple/target.rs | 39 ++++++++++++++++++++++++++----- 6 files changed, 83 insertions(+), 12 deletions(-) create mode 100644 .changes/apple-build-options.md create mode 100644 .changes/move-auth-credentials.md diff --git a/.changes/apple-build-options.md b/.changes/apple-build-options.md new file mode 100644 index 00000000..39db3d84 --- /dev/null +++ b/.changes/apple-build-options.md @@ -0,0 +1,5 @@ +--- +"cargo-mobile2": minor +--- + +Added a `BuildConfig` argument to the `Target::build` iOS method to allow provisioning updates. diff --git a/.changes/move-auth-credentials.md b/.changes/move-auth-credentials.md new file mode 100644 index 00000000..f0a3f478 --- /dev/null +++ b/.changes/move-auth-credentials.md @@ -0,0 +1,5 @@ +--- +"cargo-mobile2": minor +--- + +Move `AuthCredentials` to `cargo_mobile2::apple`. diff --git a/src/apple/cli.rs b/src/apple/cli.rs index 3c03bad5..b5df9b65 100644 --- a/src/apple/cli.rs +++ b/src/apple/cli.rs @@ -3,7 +3,9 @@ use crate::{ config::{Config, Metadata}, device::{self, Device, RunError}, rust_version_check, - target::{ArchiveError, BuildError, CheckError, CompileLibError, ExportError, Target}, + target::{ + ArchiveError, BuildConfig, BuildError, CheckError, CompileLibError, ExportError, Target, + }, NAME, }, config::{ @@ -314,7 +316,13 @@ impl Exec for Input { &env, |target: &Target| { target - .build(config, &env, noise_level, profile) + .build( + config, + &env, + noise_level, + profile, + BuildConfig::default().allow_provisioning_updates(), + ) .map_err(Error::BuildFailed) }, ) @@ -338,7 +346,13 @@ impl Exec for Input { } target - .build(config, &env, noise_level, profile) + .build( + config, + &env, + noise_level, + profile, + BuildConfig::new().allow_provisioning_updates(), + ) .map_err(Error::BuildFailed)?; target .archive(config, &env, noise_level, profile, Some(app_version)) diff --git a/src/apple/device/mod.rs b/src/apple/device/mod.rs index 6924e7ee..c5e502ca 100644 --- a/src/apple/device/mod.rs +++ b/src/apple/device/mod.rs @@ -4,7 +4,7 @@ use super::{ target::{ArchiveError, BuildError, ExportError, Target}, }; use crate::{ - apple::target::ExportConfig, + apple::target::{BuildConfig, ExportConfig}, env::{Env, ExplicitEnv as _}, opts, util::cli::{Report, Reportable}, @@ -128,7 +128,13 @@ impl<'a> Device<'a> { // TODO: These steps are run unconditionally, which is slooooooow println!("Building app..."); self.target - .build(config, env, noise_level, profile) + .build( + config, + env, + noise_level, + profile, + BuildConfig::new().allow_provisioning_updates(), + ) .map_err(RunError::BuildFailed)?; println!("Archiving app..."); self.target @@ -141,7 +147,12 @@ impl<'a> Device<'a> { DeviceKind::IosDeployDevice | DeviceKind::DeviceCtlDevice => { println!("Exporting app..."); self.target - .export(config, env, noise_level, ExportConfig::default()) + .export( + config, + env, + noise_level, + ExportConfig::default().allow_provisioning_updates(), + ) .map_err(RunError::ExportFailed)?; println!("Extracting IPA..."); diff --git a/src/apple/mod.rs b/src/apple/mod.rs index be854d6a..0c31e097 100644 --- a/src/apple/mod.rs +++ b/src/apple/mod.rs @@ -9,6 +9,8 @@ pub mod target; pub mod teams; mod version_number; +use std::path::PathBuf; + use crate::util::{ self, cli::{Report, TextWrapper}, @@ -16,6 +18,13 @@ use crate::util::{ pub static NAME: &str = "apple"; +#[derive(Clone)] +pub struct AuthCredentials { + pub key_path: PathBuf, + pub key_id: String, + pub key_issuer_id: String, +} + pub fn rust_version_check(wrapper: &TextWrapper) -> Result<(), util::RustVersionError> { util::RustVersion::check().map(|version| if !version.valid() { Report::action_request( diff --git a/src/apple/target.rs b/src/apple/target.rs index eaffb375..8cfb6ff4 100644 --- a/src/apple/target.rs +++ b/src/apple/target.rs @@ -2,6 +2,7 @@ use super::{ config::{Config, Metadata}, system_profile::{self, DeveloperTools}, version_number::VersionNumber, + AuthCredentials, }; use crate::{ env::{Env, ExplicitEnv as _}, @@ -18,7 +19,6 @@ use once_cell_regex::exports::once_cell::sync::OnceCell; use std::{ collections::{BTreeMap, HashMap}, ffi::{OsStr, OsString}, - path::PathBuf, }; use thiserror::Error; @@ -156,10 +156,26 @@ impl ExportConfig { } } -pub struct AuthCredentials { - pub key_path: PathBuf, - pub key_id: String, - pub key_issuer_id: String, +#[derive(Default)] +pub struct BuildConfig { + allow_provisioning_updates: bool, + authentication_credentials: Option, +} + +impl BuildConfig { + pub fn new() -> Self { + Self::default() + } + + pub fn allow_provisioning_updates(mut self) -> Self { + self.allow_provisioning_updates = true; + self + } + + pub fn authentication_credentials(mut self, credentials: AuthCredentials) -> Self { + self.authentication_credentials.replace(credentials); + self + } } #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] @@ -345,6 +361,7 @@ impl<'a> Target<'a> { env: &Env, noise_level: opts::NoiseLevel, profile: opts::Profile, + build_config: BuildConfig, ) -> Result<(), BuildError> { let configuration = profile.as_str(); let scheme = config.scheme(); @@ -366,12 +383,22 @@ impl<'a> Target<'a> { if let Some(a) = &arch { cmd.args(["-arch", a]); } + + if build_config.allow_provisioning_updates { + cmd.arg("-allowProvisioningUpdates"); + } + if let Some(credentials) = &build_config.authentication_credentials { + cmd.args(["-authenticationKeyID", &credentials.key_id]) + .arg("-authenticationKeyPath") + .arg(&credentials.key_path) + .args(["-authenticationKeyIssuerID", &credentials.key_issuer_id]); + } + cmd.args(["-scheme", &scheme]) .arg("-workspace") .arg(&workspace_path) .args(["-sdk", &sdk]) .args(["-configuration", configuration]) - .arg("-allowProvisioningUpdates") .arg("build"); Ok(()) })