Skip to content

Commit 2238bb6

Browse files
committed
enh(xcodegen): types
1 parent 7307641 commit 2238bb6

File tree

10 files changed

+702
-40
lines changed

10 files changed

+702
-40
lines changed

src/types/project.rs

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,92 @@
1+
mod config;
2+
mod dependency;
3+
mod options;
4+
mod package;
5+
mod platform;
6+
mod target;
7+
mod target_type;
8+
19
use super::Root;
2-
#[cfg(feature = "daemon")]
3-
use anyhow::Result;
410
use serde::{Deserialize, Serialize};
511
use std::collections::HashMap;
6-
use std::path::PathBuf;
12+
pub use {
13+
config::PluginConfig, dependency::*, options::*, package::*, platform::*, target::*,
14+
target_type::*,
15+
};
16+
17+
#[cfg(feature = "daemon")]
18+
use anyhow::Result;
719

820
/// Represent XcodeGen Project
921
#[derive(Debug, Deserialize, Serialize)]
22+
#[serde(rename_all = "camelCase")]
1023
pub struct Project {
1124
/// Project Name or rather xproj generated file name.
1225
pub name: String,
26+
1327
/// The list of targets in the project mapped by name
14-
pub targets: HashMap<String, Target>,
15-
/// xbase local configuration
28+
pub targets: HashMap<String, ProjectTarget>,
29+
1630
#[serde(rename(deserialize = "xbase"), default)]
17-
pub xcode_base: LocalConfig,
18-
/// Root directory
31+
/// xbase local configuration
32+
pub xbase: PluginConfig,
33+
1934
#[serde(skip)]
35+
/// Root directory
2036
pub root: Root,
21-
/// Connected Clients
37+
2238
#[serde(default)]
39+
/// Connected Clients
2340
pub clients: Vec<i32>,
24-
/// Ignore Patterns
41+
2542
#[serde(default)]
43+
/// Ignore Patterns
2644
pub ignore_patterns: Vec<String>,
27-
}
2845

29-
/// Represent Xcode Target
30-
// TODO: serialize from string or vector
31-
#[derive(Debug, Deserialize, Serialize)]
32-
pub struct Target {
33-
pub r#type: String,
34-
pub platform: String,
35-
pub sources: Vec<PathBuf>,
36-
}
46+
#[serde(default)]
47+
/// Options to override default behaviour
48+
pub options: ProjectOptions,
3749

38-
#[derive(Debug, Default, Deserialize, Serialize)]
39-
pub struct LocalConfig {
40-
pub ignore: Vec<String>,
50+
#[serde(default)]
51+
/// Packages
52+
pub packages: HashMap<String, ProjectPackage>,
4153
}
4254

4355
#[cfg(feature = "daemon")]
4456
impl Project {
45-
pub async fn new(root: &PathBuf) -> Result<Self> {
57+
pub async fn new(root: &std::path::PathBuf) -> Result<Self> {
4658
let path = root.join("project.yml");
4759
if !path.exists() {
4860
anyhow::bail!("project.yaml doesn't exist in '{:?}'", root)
4961
}
5062

51-
let project = tokio::fs::read_to_string(path).await?;
52-
let mut project = serde_yaml::from_str::<Project>(&project)?;
53-
54-
let ignore_patterns: Vec<String> = vec![
55-
"**/.git/**".into(),
56-
"**/*.xcodeproj/**".into(),
57-
"**/.*".into(),
58-
"**/build/**".into(),
59-
"**/buildServer.json".into(),
60-
];
63+
let content = tokio::fs::read_to_string(path).await?;
64+
let mut project = serde_yaml::from_str::<Project>(&content)?;
6165

6266
// Note: Add extra ignore patterns to `ignore` local config requires restarting daemon.
67+
project.ignore_patterns.extend(project.xbase.ignore.clone());
6368
project
6469
.ignore_patterns
65-
.extend(project.xcode_base.ignore.clone());
66-
67-
project.ignore_patterns.extend(ignore_patterns);
70+
.extend(DEFAULT_IGNORE_PATTERN.clone().into_iter());
6871

6972
Ok(project)
7073
}
7174

7275
pub async fn update(&mut self) -> Result<()> {
73-
let new_project = Self::new(&self.root).await?;
74-
self.name = new_project.name;
75-
self.targets = new_project.targets;
76-
self.xcode_base = new_project.xcode_base;
77-
76+
let ignore_patterns = self.ignore_patterns.clone();
77+
*self = Self::new(&self.root).await?;
78+
self.ignore_patterns = ignore_patterns;
7879
Ok(())
7980
}
8081
}
82+
83+
#[cfg(feature = "daemon")]
84+
lazy_static::lazy_static! {
85+
static ref DEFAULT_IGNORE_PATTERN: Vec<String> = vec![
86+
"**/.git/**".into(),
87+
"**/*.xcodeproj/**".into(),
88+
"**/.*".into(),
89+
"**/build/**".into(),
90+
"**/buildServer.json".into(),
91+
];
92+
}

src/types/project/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use super::*;
2+
3+
#[derive(Debug, Default, Deserialize, Serialize)]
4+
pub struct PluginConfig {
5+
pub ignore: Vec<String>,
6+
}

src/types/project/dependency.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#[derive(Debug)]
2+
pub enum ProjectDependency {
3+
/// Links to another target. If you are using project references you can specify a target
4+
/// within another project by using ProjectName/TargetName for the name
5+
Target(String),
6+
/// Links to a framework or XCFramework
7+
Framework(String),
8+
/// Helper for linking to a Carthage framework (not XCFramework)
9+
Carthage(String),
10+
/// Links to a dependency with the SDK. This can either be a relative path within the sdk root
11+
/// or a single filename that references a framework (.framework) or lib (.tbd)
12+
Sdk(String),
13+
/// Links to a Swift Package. The name must match the name of a package defined in the top
14+
/// level packages
15+
Package(String),
16+
/// Adds the pre-built bundle for the supplied name to the copy resources build phase. This is
17+
/// useful when a dependency exists on a static library target that has an associated bundle
18+
/// target, both existing in a separate project. Only usable in target types which can copy
19+
/// resources.
20+
Bundle(String),
21+
None,
22+
}

src/types/project/options.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use super::*;
2+
3+
#[derive(Debug, Default, Deserialize, Serialize)]
4+
#[serde(rename_all = "camelCase")]
5+
pub struct ProjectOptions {
6+
/// If this is specified then any target that doesn't have an PRODUCT_BUNDLE_IDENTIFIER (via
7+
/// all levels of build settings) will get an autogenerated one by combining bundleIdPrefix and
8+
/// the target name: bundleIdPrefix.name. The target name will be stripped of all characters
9+
/// that aren't alphanumerics, hyphens, or periods. Underscores will be replaced with hyphens.
10+
///
11+
/// Note: This is used to launch apps
12+
bundle_id_prefix: String,
13+
14+
/// The path to the carthage build directory. Defaults to Carthage/Build. This is used when
15+
/// specifying target carthage dependencies
16+
///
17+
#[serde(default = "carthage_build_path_default")]
18+
carthage_build_path: String,
19+
20+
/// The path to the carthage executable. Defaults to carthage.
21+
carthage_executable_path: Option<String>,
22+
23+
/// When this is set to true, all the invididual frameworks for Carthage framework dependencies
24+
/// will automatically be found. This property can be overriden individually for each carthage
25+
/// dependency - for more details see See findFrameworks in the Dependency section. Defaults to
26+
/// false.
27+
#[serde(default)]
28+
find_carthage_frameworks: bool,
29+
30+
/// This controls the settings that are automatically applied to the project and its targets.
31+
/// These are the same build settings that Xcode would add when creating a new project. Project
32+
/// settings are applied by config type. Target settings are applied by the product type and
33+
/// platform. By default this is set to all
34+
///
35+
/// - all: project and target settings
36+
/// - project: only project settings
37+
/// - targets: only target settings
38+
/// - none: no settings are automatically applied
39+
#[serde(default = "setting_presets_default")]
40+
setting_presets: String,
41+
42+
/// A project wide deployment target can be specified for each platform otherwise the default
43+
/// SDK version in Xcode will be used. This will be overridden by any custom build settings
44+
/// that set the deployment target eg IPHONEOS_DEPLOYMENT_TARGET. Target specific deployment
45+
/// targets can also be set with Target.deploymentTarget.
46+
#[serde(default)]
47+
deployment_target: HashMap<Platform, String>,
48+
49+
/// The default configuration for command line builds from Xcode. If the configuration provided
50+
/// here doesn't match one in your configs key, XcodeGen will fail. If you don't set this, the
51+
/// first configuration alphabetically will be chosen.
52+
default_config: Option<String>,
53+
54+
/// If this is false and your project does not include resources located in a Base.lproj
55+
/// directory then Base will not be included in the projects 'known regions'. The default value
56+
/// is true.
57+
#[serde(default = "use_base_internationalization_default")]
58+
use_base_internationalization: bool,
59+
}
60+
61+
const fn use_base_internationalization_default() -> bool {
62+
true
63+
}
64+
65+
fn carthage_build_path_default() -> String {
66+
String::from("Carthage/Build")
67+
}
68+
69+
fn setting_presets_default() -> String {
70+
String::from("all")
71+
}

src/types/project/package.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use super::*;
2+
3+
#[derive(Debug, Default, Deserialize, Serialize)]
4+
#[serde(rename_all = "camelCase")]
5+
pub struct ProjectPackage {
6+
#[serde(skip_serializing_if = "Option::is_none")]
7+
url: Option<String>,
8+
#[serde(skip_serializing_if = "Option::is_none")]
9+
from: Option<String>,
10+
#[serde(skip_serializing_if = "Option::is_none")]
11+
branch: Option<String>,
12+
#[serde(skip_serializing_if = "Option::is_none")]
13+
exact_version: Option<String>,
14+
#[serde(skip_serializing_if = "Option::is_none")]
15+
major_version: Option<String>,
16+
#[serde(skip_serializing_if = "Option::is_none")]
17+
minor_version: Option<String>,
18+
#[serde(skip_serializing_if = "Option::is_none")]
19+
min_version: Option<String>,
20+
#[serde(skip_serializing_if = "Option::is_none")]
21+
max_version: Option<String>,
22+
#[serde(skip_serializing_if = "Option::is_none")]
23+
revision: Option<String>,
24+
#[serde(skip_serializing_if = "Option::is_none")]
25+
github: Option<String>,
26+
#[serde(skip_serializing_if = "Option::is_none")]
27+
path: Option<String>,
28+
#[serde(skip_serializing_if = "Option::is_none")]
29+
group: Option<String>,
30+
}

src/types/project/platform.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use super::*;
2+
#[derive(Debug, Default, Deserialize, Serialize, Hash, PartialEq, Eq)]
3+
pub enum Platform {
4+
#[serde(rename = "iOS")]
5+
IOS,
6+
#[serde(rename = "watchOS")]
7+
WatchOS,
8+
#[serde(rename = "tvOS")]
9+
TvOS,
10+
#[serde(rename = "macOS")]
11+
MacOS,
12+
#[default]
13+
None,
14+
}
15+
16+
impl Platform {
17+
/// Returns `true` if the platfrom is [`IOS`].
18+
///
19+
/// [`IOS`]: Platfrom::IOS
20+
#[must_use]
21+
pub fn is_ios(&self) -> bool {
22+
matches!(self, Self::IOS)
23+
}
24+
25+
/// Returns `true` if the platfrom is [`WatchOS`].
26+
///
27+
/// [`WatchOS`]: Platfrom::WatchOS
28+
#[must_use]
29+
pub fn is_watch_os(&self) -> bool {
30+
matches!(self, Self::WatchOS)
31+
}
32+
33+
/// Returns `true` if the platfrom is [`TvOS`].
34+
///
35+
/// [`TvOS`]: Platfrom::TvOS
36+
#[must_use]
37+
pub fn is_tv_os(&self) -> bool {
38+
matches!(self, Self::TvOS)
39+
}
40+
41+
/// Returns `true` if the platfrom is [`MacOS`].
42+
///
43+
/// [`MacOS`]: Platfrom::MacOS
44+
#[must_use]
45+
pub fn is_mac_os(&self) -> bool {
46+
matches!(self, Self::MacOS)
47+
}
48+
}

0 commit comments

Comments
 (0)