Skip to content

Commit

Permalink
feat(apple): allow provisioning updates for Target::build (#381)
Browse files Browse the repository at this point in the history
follow up for #371, turns out in CI we also need to provide the values for the target.build() usage
  • Loading branch information
lucasfernog authored Aug 31, 2024
1 parent 3d9e939 commit e289dd9
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changes/apple-build-options.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cargo-mobile2": minor
---

Added a `BuildConfig` argument to the `Target::build` iOS method to allow provisioning updates.
5 changes: 5 additions & 0 deletions .changes/move-auth-credentials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cargo-mobile2": minor
---

Move `AuthCredentials` to `cargo_mobile2::apple`.
20 changes: 17 additions & 3 deletions src/apple/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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)
},
)
Expand All @@ -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))
Expand Down
17 changes: 14 additions & 3 deletions src/apple/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand All @@ -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...");

Expand Down
9 changes: 9 additions & 0 deletions src/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@ pub mod target;
pub mod teams;
mod version_number;

use std::path::PathBuf;

use crate::util::{
self,
cli::{Report, TextWrapper},
};

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(
Expand Down
39 changes: 33 additions & 6 deletions src/apple/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::{
config::{Config, Metadata},
system_profile::{self, DeveloperTools},
version_number::VersionNumber,
AuthCredentials,
};
use crate::{
env::{Env, ExplicitEnv as _},
Expand All @@ -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;

Expand Down Expand Up @@ -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<AuthCredentials>,
}

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)]
Expand Down Expand Up @@ -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();
Expand All @@ -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(())
})
Expand Down

0 comments on commit e289dd9

Please sign in to comment.