Skip to content

Commit

Permalink
Let user specify ios app version (BrainiumLLC#60)
Browse files Browse the repository at this point in the history
* Add back missing closing delimiter to `app_dependencies_platform`

* Let user specify ios app version

* Add separate bundle_version and bundle_version_short fields

* make bundle_version_short the source of truth

* Update src/apple/config/mod.rs

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

* Update src/apple/config/mod.rs

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

* Fix stupid mistake

* Add TODO for bundle_version

Co-authored-by: Francesca Lovebloom <[email protected]>
  • Loading branch information
ArthurKValladares and francesca64 committed Jan 13, 2022
1 parent 0806d35 commit ecb8869
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 2 deletions.
28 changes: 27 additions & 1 deletion src/apple/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ pub use self::raw::*;

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

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

Expand Down Expand Up @@ -137,6 +140,7 @@ pub enum Error {
DevelopmentTeamMissing,
DevelopmentTeamEmpty,
ProjectDirInvalid(ProjectDirInvalid),
BundleVersionInvalid(VersionTripleError),
IosVersionInvalid(VersionDoubleError),
MacOsVersionInvalid(VersionDoubleError),
}
Expand All @@ -155,6 +159,10 @@ impl Error {
msg,
format!("`{}.project-dir` invalid: {}", super::NAME, err),
),
Self::BundleVersionInvalid(err) => Report::error(
msg,
format!("`{}.app-version` invalid: {}", super::NAME, err),
),
Self::IosVersionInvalid(err) => Report::error(
msg,
format!("`{}.ios-version` invalid: {}", super::NAME, err),
Expand All @@ -174,6 +182,9 @@ pub struct Config {
app: App,
development_team: String,
project_dir: String,
// TODO: Allow support for [3, inf) integers
bundle_version: VersionTriple,
bundle_version_short: VersionTriple,
ios_version: VersionDouble,
macos_version: VersionDouble,
use_legacy_build_system: bool,
Expand Down Expand Up @@ -213,10 +224,25 @@ impl Config {
);
Ok(DEFAULT_PROJECT_DIR.to_owned())
})?;

let bundle_version_short = raw
.bundle_version_short
.map(|str| VersionTriple::from_str(&str))
.transpose()
.map_err(Error::BundleVersionInvalid)?
.unwrap_or(DEFAULT_BUNDLE_VERSION);

Ok(Self {
app,
development_team: raw.development_team,
project_dir,
bundle_version: raw
.bundle_version
.map(|str| VersionTriple::from_str(&str))
.transpose()
.map_err(Error::BundleVersionInvalid)?
.unwrap_or(bundle_version_short),
bundle_version_short,
ios_version: raw
.ios_version
.map(|str| VersionDouble::from_str(&str))
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 bundle_version: Option<String>,
pub bundle_version_short: Option<String>,
pub ios_version: Option<String>,
pub macos_version: Option<String>,
pub use_legacy_build_system: Option<bool>,
Expand All @@ -70,6 +72,8 @@ impl Raw {
ios_features: None,
macos_no_default_features: None,
macos_features: None,
bundle_version: None,
bundle_version_short: None,
ios_version: None,
macos_version: None,
use_legacy_build_system: None,
Expand Down Expand Up @@ -148,6 +152,8 @@ impl Raw {
ios_features: None,
macos_no_default_features: None,
macos_features: None,
bundle_version: None,
bundle_version_short: None,
ios_version: None,
macos_version: None,
use_legacy_build_system: None,
Expand Down
74 changes: 73 additions & 1 deletion src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ pub enum VersionTripleError {
version: String,
source: std::num::ParseIntError,
},
#[error(
"Failed to parse version string {version:?}: string must be in format <major>[.minor][.patch]"
)]
VersionStringInvalid { version: String },
}

macro_rules! parse {
Expand All @@ -106,7 +110,7 @@ macro_rules! parse {
}

// Generic version triple
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
pub struct VersionTriple {
pub major: u32,
pub minor: u32,
Expand All @@ -119,6 +123,15 @@ impl Display for VersionTriple {
}
}

impl Serialize for VersionTriple {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.collect_str(self)
}
}

impl VersionTriple {
pub const fn new(major: u32, minor: u32, patch: u32) -> Self {
Self {
Expand Down Expand Up @@ -148,6 +161,65 @@ impl VersionTriple {
version_str,
))
}

pub fn from_str(v: &str) -> Result<Self, VersionTripleError> {
match v.split(".").count() {
1 => Ok(VersionTriple {
major: v
.parse()
.map_err(|source| VersionTripleError::MajorInvalid {
version: v.to_owned(),
source,
})?,
minor: 0,
patch: 0,
}),
2 => {
let mut s = v.split(".");
Ok(VersionTriple {
major: s.next().unwrap().parse().map_err(|source| {
VersionTripleError::MajorInvalid {
version: v.to_owned(),
source,
}
})?,
minor: s.next().unwrap().parse().map_err(|source| {
VersionTripleError::MinorInvalid {
version: v.to_owned(),
source,
}
})?,
patch: 0,
})
}
3 => {
let mut s = v.split(".");
Ok(VersionTriple {
major: s.next().unwrap().parse().map_err(|source| {
VersionTripleError::MajorInvalid {
version: v.to_owned(),
source,
}
})?,
minor: s.next().unwrap().parse().map_err(|source| {
VersionTripleError::MinorInvalid {
version: v.to_owned(),
source,
}
})?,
patch: s.next().unwrap().parse().map_err(|source| {
VersionTripleError::PatchInvalid {
version: v.to_owned(),
source,
}
})?,
})
}
_ => Err(VersionTripleError::VersionStringInvalid {
version: v.to_owned(),
}),
}
}
}

#[derive(Debug, Error)]
Expand Down
2 changes: 2 additions & 0 deletions templates/platforms/xcode/project.yml.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ targets:
- UIInterfaceOrientationPortraitUpsideDown
- UIInterfaceOrientationLandscapeLeft
- UIInterfaceOrientationLandscapeRight
CFBundleShortVersionString: {{apple.bundle-version-short}}
CFBundleVersion: {{apple.bundle-version}}
scheme:
environmentVariables:
RUST_BACKTRACE: full
Expand Down

0 comments on commit ecb8869

Please sign in to comment.