Skip to content

Commit

Permalink
Podfile support (BrainiumLLC#38)
Browse files Browse the repository at this point in the history
* Support podfiles

* Better way to change dir.

* Small wording change

* Install cocoapods, some tweaks

* Better handling of cocoapods with brew and gem

* adapt workspace path when using pods

* no longer use dynamic frameworks

* Update mod.rs

* 'static is implied for static bindings

* Handle updating cocoapods

* Add `cargo apple pod-update` command

* change pod-update command to `pod`, pipe in extra arguments

* Revert updating cocoapods

* Second pass at updating gem dependencies

* Cleanup implementation

* Simplify logic for updating packages.

* remove gem_needs_update collection

* Add an optional cache for installed_with_gem, as checking every time can be slow.

* Make gems cache into a struct

* Update src/apple/deps/mod.rs

Co-authored-by: Francesca Lovebloom <[email protected]>

* Update src/apple/deps/mod.rs

Co-authored-by: Francesca Lovebloom <[email protected]>

* Update src/apple/deps/update.rs

Co-authored-by: Francesca Lovebloom <[email protected]>

* Update src/apple/deps/mod.rs

Co-authored-by: Francesca Lovebloom <[email protected]>

* Update src/apple/deps/update.rs

Co-authored-by: Francesca Lovebloom <[email protected]>

* Update src/apple/deps/mod.rs

Co-authored-by: Francesca Lovebloom <[email protected]>

* Update src/apple/deps/update.rs

Co-authored-by: Francesca Lovebloom <[email protected]>

* Fix build

* Update src/apple/deps/mod.rs

Co-authored-by: Francesca Lovebloom <[email protected]>

* Revert "Update src/apple/deps/mod.rs"

This reverts commit b5b1c45.

* Don't specify types in collect when we don't need to

* cleanup according to PR

* Make install a member of PackageDeps

* Move get_string_for_group into util

* address feedback

* Cleanup code according to PR

* address some PR feedback

* update outdated_gem_deps

* style tweaks

* rename command_string to command

* Update src/apple/deps/mod.rs

Co-authored-by: Francesca Lovebloom <[email protected]>

* Add support for specifying ios and macos deployment targets

* Use a VersionDouble struct to handle min ios and macos version

* use VersionDouble::dafault()

* Cleanup VersionDouble use declarations

* Better error handling for VersionDouble

* Update src/util/mod.rs

Co-authored-by: Francesca Lovebloom <[email protected]>

* Rename VersionDouble NdkVersion

* Use VersionDouble::new to construct VersionDouble

* no long apped `_double` to name of VersionDouble variables

* Remove default VersionDouble impl. Doesn't make sense in all platforms.

* No longer implement custom deserialize function for VersionDouble

* update to use VersionDouble::new for MIN_NDK_VERSION

* improve version number handling.

* refactor getting ios/macos versions from raw

* Refactor getting version number from string.

* re-gen cargo.lock, fix bundletool install call

* Fix formatting

* fix another formatting issue

Co-authored-by: Francesca Lovebloom <[email protected]>
  • Loading branch information
ArthurKValladares and francesca64 committed Nov 30, 2021
1 parent 3e36823 commit 059e222
Show file tree
Hide file tree
Showing 13 changed files with 465 additions and 64 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/android/bundletool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ pub fn install(reinstall_deps: opts::ReinstallDeps) -> Result<(), InstallError>
}
#[cfg(target_os = "macos")]
{
crate::apple::deps::install("bundletool", reinstall_deps).map_err(InstallError)?;
use crate::apple::deps::{GemCache, PackageSpec};
PackageSpec::brew("bundletool")
.install(reinstall_deps, &mut GemCache::new())
.map_err(InstallError)?;
}
Ok(())
}
39 changes: 18 additions & 21 deletions src/android/ndk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use super::{
source_props::{self, SourceProps},
target::Target,
};
use crate::util::cli::{Report, Reportable};
use crate::util::{
cli::{Report, Reportable},
VersionDouble,
};
use once_cell_regex::regex_multi_line;
use std::{
collections::HashSet,
Expand All @@ -11,10 +14,7 @@ use std::{
};
use thiserror::Error;

const MIN_NDK_VERSION: ShortVersion = ShortVersion {
major: 19,
minor: 0,
};
const MIN_NDK_VERSION: NdkVersion = NdkVersion(VersionDouble::new(19, 0));

#[cfg(target_os = "macos")]
pub fn host_tag() -> &'static str {
Expand Down Expand Up @@ -99,34 +99,31 @@ impl MissingToolError {
}

#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct ShortVersion {
major: u32,
minor: u32,
}
pub struct NdkVersion(VersionDouble);

impl Display for ShortVersion {
impl Display for NdkVersion {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "r{}", self.major)?;
if self.minor != 0 {
write!(f, "r{}", self.0.major)?;
if self.0.minor != 0 {
write!(
f,
"{}",
(b'a'..=b'z')
.map(char::from)
.nth(self.minor as _)
.nth(self.0.minor as _)
.expect("NDK minor version exceeded the number of letters in the alphabet")
)?;
}
Ok(())
}
}

impl From<source_props::Revision> for ShortVersion {
impl From<source_props::Revision> for NdkVersion {
fn from(revision: source_props::Revision) -> Self {
Self {
major: revision.triple.major,
minor: revision.triple.minor,
}
Self(VersionDouble::new(
revision.triple.major,
revision.triple.minor,
))
}
}

Expand All @@ -141,8 +138,8 @@ pub enum Error {
VersionLookupFailed(#[from] source_props::Error),
#[error("At least NDK {you_need} is required (you currently have NDK {you_have})")]
VersionTooLow {
you_have: ShortVersion,
you_need: ShortVersion,
you_have: NdkVersion,
you_need: NdkVersion,
},
}

Expand Down Expand Up @@ -188,7 +185,7 @@ impl Env {
let env = Self { ndk_home };
let version = env
.version()
.map(ShortVersion::from)
.map(NdkVersion::from)
.map_err(Error::VersionLookupFailed)?;
if version >= MIN_NDK_VERSION {
Ok(env)
Expand Down
23 changes: 23 additions & 0 deletions src/apple/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ pub enum Command {
},
#[structopt(name = "list", about = "Lists connected devices")]
List,
#[structopt(name = "pod", about = "Runs `pod <args>`")]
Pod {
#[structopt(
name = "arguments",
help = "arguments passed down to the `pod <args>` command",
index = 1,
required = true
)]
arguments: Vec<String>,
},
#[structopt(
name = "xcode-script",
about = "Compiles static lib (should only be called by Xcode!)",
Expand Down Expand Up @@ -149,6 +159,7 @@ pub enum Error {
MacosSdkRootInvalid { macos_sdk_root: PathBuf },
ArchInvalid { arch: String },
CompileLibFailed(CompileLibError),
PodCommandFailed(bossy::Error),
}

impl Reportable for Error {
Expand Down Expand Up @@ -191,6 +202,7 @@ impl Reportable for Error {
format!("{:?} isn't a known arch", arch),
),
Self::CompileLibFailed(err) => err.report(),
Self::PodCommandFailed(err) => Report::error("pod command failed", err),
}
}
}
Expand Down Expand Up @@ -327,6 +339,17 @@ impl Exec for Input {
.map(|device_list| {
prompt::list_display_only(device_list.iter(), device_list.len());
}),
Command::Pod { arguments } => with_config(non_interactive, wrapper, |config, _| {
bossy::Command::impure_parse("pod")
.with_args(arguments)
.with_arg(format!(
"--project-directory={}",
config.project_dir().display()
))
.run_and_wait()
.map_err(Error::PodCommandFailed)?;
Ok(())
}),
Command::XcodeScript {
macos,
sdk_root,
Expand Down
48 changes: 43 additions & 5 deletions src/apple/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub use self::raw::*;

use crate::{
config::app::App,
util::{self, cli::Report},
util::{self, cli::Report, VersionDouble, VersionDoubleError},
};
use serde::{Deserialize, Serialize};
use std::{
Expand All @@ -13,6 +13,8 @@ use std::{
};

static DEFAULT_PROJECT_DIR: &str = "gen/apple";
const DEFAULT_IOS_VERSION: VersionDouble = VersionDouble::new(9, 0);
const DEFAULT_MACOS_VERSION: VersionDouble = VersionDouble::new(11, 0);

#[derive(Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case")]
Expand All @@ -22,6 +24,7 @@ pub struct Platform {
vendor_frameworks: Option<Vec<String>>,
vendor_sdks: Option<Vec<String>>,
asset_catalogs: Option<Vec<PathBuf>>,
pods: Option<Vec<PathBuf>>,
additional_targets: Option<Vec<PathBuf>>,
}

Expand Down Expand Up @@ -50,6 +53,10 @@ impl Platform {
self.asset_catalogs.as_deref()
}

pub fn pods(&self) -> Option<&[PathBuf]> {
self.pods.as_deref()
}

pub fn additional_targets(&self) -> Option<&[PathBuf]> {
self.additional_targets.as_deref()
}
Expand Down Expand Up @@ -130,6 +137,8 @@ pub enum Error {
DevelopmentTeamMissing,
DevelopmentTeamEmpty,
ProjectDirInvalid(ProjectDirInvalid),
IosVersionInvalid(VersionDoubleError),
MacOsVersionInvalid(VersionDoubleError),
}

impl Error {
Expand All @@ -146,6 +155,14 @@ impl Error {
msg,
format!("`{}.project-dir` invalid: {}", super::NAME, err),
),
Self::IosVersionInvalid(err) => Report::error(
msg,
format!("`{}.ios-version` invalid: {}", super::NAME, err),
),
Self::MacOsVersionInvalid(err) => Report::error(
msg,
format!("`{}.macos-version` invalid: {}", super::NAME, err),
),
}
}
}
Expand All @@ -157,6 +174,8 @@ pub struct Config {
app: App,
development_team: String,
project_dir: String,
ios_version: VersionDouble,
macos_version: VersionDouble,
use_legacy_build_system: bool,
}

Expand Down Expand Up @@ -198,6 +217,18 @@ impl Config {
app,
development_team: raw.development_team,
project_dir,
ios_version: raw
.ios_version
.map(|str| VersionDouble::from_str(&str))
.transpose()
.map_err(Error::IosVersionInvalid)?
.unwrap_or(DEFAULT_IOS_VERSION),
macos_version: raw
.macos_version
.map(|str| VersionDouble::from_str(&str))
.transpose()
.map_err(Error::IosVersionInvalid)?
.unwrap_or(DEFAULT_MACOS_VERSION),
use_legacy_build_system: raw.use_legacy_build_system.unwrap_or(true),
})
}
Expand All @@ -215,10 +246,17 @@ impl Config {
}

pub fn workspace_path(&self) -> PathBuf {
self.project_dir().join(format!(
"{}.xcodeproj/project.xcworkspace/",
self.app.name()
))
let root_workspace = self
.project_dir()
.join(format!("{}.xcworkspace/", self.app.name()));
if root_workspace.exists() {
root_workspace
} else {
self.project_dir().join(format!(
"{}.xcodeproj/project.xcworkspace/",
self.app.name()
))
}
}

pub fn archive_dir(&self) -> PathBuf {
Expand Down
6 changes: 6 additions & 0 deletions src/apple/config/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ pub struct Raw {
pub ios_features: Option<Vec<String>>,
pub macos_no_default_features: Option<bool>,
pub macos_features: Option<Vec<String>>,
pub ios_version: Option<String>,
pub macos_version: Option<String>,
pub use_legacy_build_system: Option<bool>,
}

Expand All @@ -68,6 +70,8 @@ impl Raw {
ios_features: None,
macos_no_default_features: None,
macos_features: None,
ios_version: None,
macos_version: None,
use_legacy_build_system: None,
})
}
Expand Down Expand Up @@ -144,6 +148,8 @@ impl Raw {
ios_features: None,
macos_no_default_features: None,
macos_features: None,
ios_version: None,
macos_version: None,
use_legacy_build_system: None,
})
}
Expand Down
Loading

0 comments on commit 059e222

Please sign in to comment.