Skip to content

Commit decc743

Browse files
anivarosyonaskolb
andauthored
Added ProjectFormat enum with specific for each version fields (#1566)
* Added ProjectFormat enum with specific for each version fields * Added ability to specify project format version via `projectFormat` option --------- Co-authored-by: Yonas Kolb <yonaskolb@users.noreply.github.com>
1 parent 167d119 commit decc743

10 files changed

Lines changed: 62 additions & 10 deletions

File tree

Docs/ProjectSpec.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ Note that target names can also be changed by adding a `name` property to a targ
133133
- [ ] **indentWidth**: **Int** - If this is specified, the Xcode project will override the user's setting for indent width in number of spaces.
134134
- [ ] **tabWidth**: **Int** - If this is specified, the Xcode project will override the user's setting for indent width in number of spaces.
135135
- [ ] **xcodeVersion**: **String** - The version of Xcode. This defaults to the latest version periodically. You can specify it in the format `0910` or `9.1`
136+
- [ ] **projectFormat**: **String** - The version of Xcode project. By default this is set to `xcode16_0`
137+
- `xcode16_3`: Xcode 16.3
138+
- `xcode16_0`: Xcode 16.0
139+
- `xcode15_3`: Xcode 15.3
140+
- `xcode15_0`: Xcode 15.0
141+
- `xcode14_0`: Xcode 14.0
142+
136143
- [ ] **deploymentTarget**: **[[Platform](#platform): String]** - A project wide deployment target can be specified for each platform otherwise the default SDK version in Xcode will be used. This will be overridden by any custom build settings that set the deployment target eg `IPHONEOS_DEPLOYMENT_TARGET`. Target specific deployment targets can also be set with [Target](#target).deploymentTarget.
137144
- [ ] **disabledValidations**: **[String]** - A list of validations that can be disabled if they're too strict for your use case. By default this is set to an empty array. Currently these are the available options:
138145
- `missingConfigs`: Disable errors for configurations in yaml files that don't exist in the project itself. This can be useful if you include the same yaml file in different projects
@@ -156,7 +163,7 @@ Note that target names can also be changed by adding a `name` property to a targ
156163
- [ ] **defaultSourceDirectoryType**: **String** - When a [Target source](#target-source) doesn't specify a type and is a directory, this is the type that will be used. If nothing is specified for either then `group` will be used.
157164
- `group` (default)
158165
- `folder`
159-
- `syncedFolder`
166+
- `syncedFolder`: Can be used starting from **projectFormat** `xcode16_0`
160167

161168
```yaml
162169
options:

Sources/ProjectSpec/SpecOptions.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public struct SpecOptions: Equatable {
2424
public var tabWidth: UInt?
2525
public var indentWidth: UInt?
2626
public var xcodeVersion: String?
27+
public var projectFormat: String?
2728
public var deploymentTarget: DeploymentTarget
2829
public var defaultConfig: String?
2930
public var transitivelyLinkDependencies: Bool
@@ -88,6 +89,7 @@ public struct SpecOptions: Equatable {
8889
tabWidth: UInt? = nil,
8990
usesTabs: Bool? = nil,
9091
xcodeVersion: String? = nil,
92+
projectFormat: String? = nil,
9193
deploymentTarget: DeploymentTarget = .init(),
9294
disabledValidations: [ValidationType] = [],
9395
defaultConfig: String? = nil,
@@ -115,6 +117,7 @@ public struct SpecOptions: Equatable {
115117
self.indentWidth = indentWidth
116118
self.usesTabs = usesTabs
117119
self.xcodeVersion = xcodeVersion
120+
self.projectFormat = projectFormat
118121
self.deploymentTarget = deploymentTarget
119122
self.disabledValidations = disabledValidations
120123
self.defaultConfig = defaultConfig
@@ -148,6 +151,7 @@ extension SpecOptions: JSONObjectConvertible {
148151
developmentLanguage = jsonDictionary.json(atKeyPath: "developmentLanguage")
149152
usesTabs = jsonDictionary.json(atKeyPath: "usesTabs")
150153
xcodeVersion = jsonDictionary.json(atKeyPath: "xcodeVersion")
154+
projectFormat = jsonDictionary.json(atKeyPath: "projectFormat")
151155
indentWidth = (jsonDictionary.json(atKeyPath: "indentWidth") as Int?).flatMap(UInt.init)
152156
tabWidth = (jsonDictionary.json(atKeyPath: "tabWidth") as Int?).flatMap(UInt.init)
153157
deploymentTarget = jsonDictionary.json(atKeyPath: "deploymentTarget") ?? DeploymentTarget()
@@ -186,6 +190,7 @@ extension SpecOptions: JSONEncodable {
186190
"developmentLanguage": developmentLanguage,
187191
"usesTabs": usesTabs,
188192
"xcodeVersion": xcodeVersion,
193+
"projectFormat": projectFormat,
189194
"indentWidth": indentWidth.flatMap { Int($0) },
190195
"tabWidth": tabWidth.flatMap { Int($0) },
191196
"defaultConfig": defaultConfig,

Sources/XcodeGenKit/PBXProjGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public class PBXProjGenerator {
102102
name: project.name,
103103
buildConfigurationList: buildConfigList,
104104
compatibilityVersion: project.compatibilityVersion,
105-
preferredProjectObjectVersion: Int(project.objectVersion),
105+
preferredProjectObjectVersion: project.preferredProjectObjectVersion.map { Int($0) },
106106
minimizedProjectReferenceProxies: project.minimizedProjectReferenceProxies,
107107
mainGroup: mainGroup,
108108
developmentRegion: developmentRegion
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
public extension ProjectFormat {
2+
static let `default`: ProjectFormat = .xcode16_0
3+
}
4+
5+
public enum ProjectFormat: String {
6+
case xcode16_3
7+
case xcode16_0
8+
case xcode15_3
9+
case xcode15_0
10+
case xcode14_0
11+
12+
public var objectVersion: UInt {
13+
switch self {
14+
case .xcode16_3: 90
15+
case .xcode16_0: 77
16+
case .xcode15_3: 63
17+
case .xcode15_0: 60
18+
case .xcode14_0: 56
19+
}
20+
}
21+
22+
public var preferredProjectObjectVersion: UInt? {
23+
switch self {
24+
case .xcode16_3, .xcode16_0: objectVersion
25+
case .xcode15_3, .xcode15_0, .xcode14_0: nil
26+
}
27+
}
28+
29+
public var compatibilityVersion: String? {
30+
switch self {
31+
case .xcode16_3, .xcode16_0: nil
32+
case .xcode15_3: "Xcode 15.3"
33+
case .xcode15_0: "Xcode 15.0"
34+
case .xcode14_0: "Xcode 14.0"
35+
}
36+
}
37+
}

Sources/XcodeGenKit/Version.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,24 @@ extension Project {
77
XCodeVersion.parse(options.xcodeVersion ?? "14.3")
88
}
99

10+
public var projectFormat: ProjectFormat {
11+
options.projectFormat.flatMap(ProjectFormat.init) ?? .default
12+
}
13+
1014
var schemeVersion: String {
1115
"1.7"
1216
}
1317

14-
var compatibilityVersion: String {
15-
"Xcode 14.0"
18+
var compatibilityVersion: String? {
19+
projectFormat.compatibilityVersion
1620
}
1721

1822
var objectVersion: UInt {
19-
77
23+
projectFormat.objectVersion
24+
}
25+
26+
var preferredProjectObjectVersion: UInt? {
27+
projectFormat.preferredProjectObjectVersion
2028
}
2129

2230
var minimizedProjectReferenceProxies: Int {

Tests/Fixtures/CarthageProject/Project.xcodeproj/project.pbxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@
326326
};
327327
};
328328
buildConfigurationList = D91E14E36EC0B415578456F2 /* Build configuration list for PBXProject "Project" */;
329-
compatibilityVersion = "Xcode 14.0";
330329
developmentRegion = en;
331330
hasScannedForEncodings = 0;
332331
knownRegions = (

Tests/Fixtures/SPM/SPM.xcodeproj/project.pbxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@
246246
};
247247
};
248248
buildConfigurationList = 425866ADA259DB93FC4AF1E3 /* Build configuration list for PBXProject "SPM" */;
249-
compatibilityVersion = "Xcode 14.0";
250249
developmentRegion = en;
251250
hasScannedForEncodings = 0;
252251
knownRegions = (

Tests/Fixtures/TestProject/AnotherProject/AnotherProject.xcodeproj/project.pbxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124
};
125125
};
126126
buildConfigurationList = 3DFC1105373EDB6483D4BC5D /* Build configuration list for PBXProject "AnotherProject" */;
127-
compatibilityVersion = "Xcode 14.0";
128127
developmentRegion = en;
129128
hasScannedForEncodings = 0;
130129
knownRegions = (

Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2484,7 +2484,6 @@
24842484
);
24852485
};
24862486
buildConfigurationList = D91E14E36EC0B415578456F2 /* Build configuration list for PBXProject "Project" */;
2487-
compatibilityVersion = "Xcode 14.0";
24882487
developmentRegion = en;
24892488
hasScannedForEncodings = 0;
24902489
knownRegions = (

Tests/Fixtures/scheme_test/TestProject.xcodeproj/project.pbxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
};
7777
};
7878
buildConfigurationList = E903F6E8184E2A86CEC31778 /* Build configuration list for PBXProject "TestProject" */;
79-
compatibilityVersion = "Xcode 14.0";
8079
developmentRegion = en;
8180
hasScannedForEncodings = 0;
8281
knownRegions = (

0 commit comments

Comments
 (0)