Skip to content

Commit

Permalink
feat: make PBXProject.compatibilityVersion optional and add `PBXPro…
Browse files Browse the repository at this point in the history
…ject.preferredProjectObjectVersion` to support Xcode 16 (#854)

* feat: Make compatibilityVersion optional

* feat: Introduce `preferredProjectObjectVersion`

* Increase the header-max-length of the PR title

* Change the value to an array

* Fix the syntax (again)

---------

Co-authored-by: Pedro <pedro@pepicrft.me>
  • Loading branch information
kimdv and pepicrft authored Sep 27, 2024
1 parent 4c9414f commit 2f925d2
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .github/.commitlint.rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
rules: {
'header-max-length': [2, 'always', 200],
}
}
1 change: 1 addition & 0 deletions .github/workflows/conventional-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ jobs:
- uses: CondeNast/conventional-pull-request-action@v0.2.0
with:
commitTitleMatch: false
commitlintRulesPath: ".github/.commitlint.rules.js"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21 changes: 17 additions & 4 deletions Sources/XcodeProj/Objects/Project/PBXProject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ public final class PBXProject: PBXObject {
}

/// A string representation of the XcodeCompatibilityVersion.
public var compatibilityVersion: String
public var compatibilityVersion: String?

/// An int representation of the PreferredProjectObjectVersion.
public var preferredProjectObjectVersion: Int?

/// The region of development.
public var developmentRegion: String?
Expand Down Expand Up @@ -286,6 +289,7 @@ public final class PBXProject: PBXObject {
/// - name: xcodeproj's name.
/// - buildConfigurationList: project build configuration list.
/// - compatibilityVersion: project compatibility version.
/// - preferredProjectObjectVersion: preferred project object version
/// - mainGroup: project main group.
/// - developmentRegion: project has development region.
/// - hasScannedForEncodings: project has scanned for encodings.
Expand All @@ -300,7 +304,8 @@ public final class PBXProject: PBXObject {
/// - targetAttributes: project target's attributes.
public init(name: String,
buildConfigurationList: XCConfigurationList,
compatibilityVersion: String,
compatibilityVersion: String?,
preferredProjectObjectVersion: Int?,
mainGroup: PBXGroup,
developmentRegion: String? = nil,
hasScannedForEncodings: Int = 0,
Expand All @@ -316,6 +321,7 @@ public final class PBXProject: PBXObject {
self.name = name
buildConfigurationListReference = buildConfigurationList.reference
self.compatibilityVersion = compatibilityVersion
self.preferredProjectObjectVersion = preferredProjectObjectVersion
mainGroupReference = mainGroup.reference
self.developmentRegion = developmentRegion
self.hasScannedForEncodings = hasScannedForEncodings
Expand All @@ -338,6 +344,7 @@ public final class PBXProject: PBXObject {
case name
case buildConfigurationList
case compatibilityVersion
case preferredProjectObjectVersion
case developmentRegion
case hasScannedForEncodings
case knownRegions
Expand All @@ -359,7 +366,8 @@ public final class PBXProject: PBXObject {
name = try (container.decodeIfPresent(.name)) ?? ""
let buildConfigurationListReference: String = try container.decode(.buildConfigurationList)
self.buildConfigurationListReference = referenceRepository.getOrCreate(reference: buildConfigurationListReference, objects: objects)
compatibilityVersion = try container.decode(.compatibilityVersion)
compatibilityVersion = try container.decodeIfPresent(.compatibilityVersion)
preferredProjectObjectVersion = try container.decodeIfPresent(.preferredProjectObjectVersion)
developmentRegion = try container.decodeIfPresent(.developmentRegion)
let hasScannedForEncodingsString: String? = try container.decodeIfPresent(.hasScannedForEncodings)
hasScannedForEncodings = hasScannedForEncodingsString.flatMap { Int($0) } ?? 0
Expand Down Expand Up @@ -482,7 +490,9 @@ extension PBXProject: PlistSerializable {
let buildConfigurationListCommentedString = CommentedString(buildConfigurationListReference.value,
comment: buildConfigurationListComment)
dictionary["buildConfigurationList"] = .string(buildConfigurationListCommentedString)
dictionary["compatibilityVersion"] = .string(CommentedString(compatibilityVersion))
if let compatibilityVersion {
dictionary["compatibilityVersion"] = .string(CommentedString(compatibilityVersion))
}
if let developmentRegion {
dictionary["developmentRegion"] = .string(CommentedString(developmentRegion))
}
Expand All @@ -494,6 +504,9 @@ extension PBXProject: PlistSerializable {
}
let mainGroupObject: PBXGroup? = mainGroupReference.getObject()
dictionary["mainGroup"] = .string(CommentedString(mainGroupReference.value, comment: mainGroupObject?.fileName()))
if let preferredProjectObjectVersion {
dictionary["preferredProjectObjectVersion"] = .string(CommentedString(preferredProjectObjectVersion.description))
}
if let productsGroupReference {
let productRefGroupObject: PBXGroup? = productsGroupReference.getObject()
dictionary["productRefGroup"] = .string(CommentedString(productsGroupReference.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class PBXContainerItemProxyTests: XCTestCase {

func test_maintains_remoteID() {
let target = PBXNativeTarget(name: "")
let project = PBXProject(name: "", buildConfigurationList: XCConfigurationList(), compatibilityVersion: "", mainGroup: PBXGroup())
let project = PBXProject(name: "", buildConfigurationList: XCConfigurationList(), compatibilityVersion: "", preferredProjectObjectVersion: nil, mainGroup: PBXGroup())
let containerProxy = PBXContainerItemProxy(containerPortal: .project(project), remoteGlobalID: .object(target))

XCTAssertEqual(target.uuid, containerProxy.remoteGlobalID?.uuid)
Expand Down
2 changes: 2 additions & 0 deletions Tests/XcodeProjTests/Objects/Files/PBXFileElementTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ final class PBXFileElementTests: XCTestCase {
let project = PBXProject(name: "ProjectName",
buildConfigurationList: XCConfigurationList(),
compatibilityVersion: "0",
preferredProjectObjectVersion: nil,
mainGroup: mainGroup)

let objects = PBXObjects(objects: [project, mainGroup, fileref, group])
Expand Down Expand Up @@ -109,6 +110,7 @@ final class PBXFileElementTests: XCTestCase {
let project = PBXProject(name: "ProjectName",
buildConfigurationList: XCConfigurationList(),
compatibilityVersion: "0",
preferredProjectObjectVersion: nil,
mainGroup: rootGroup)

let objects = PBXObjects(objects: [fileref, nestedGroup, rootGroup, project])
Expand Down
4 changes: 4 additions & 0 deletions Tests/XcodeProjTests/Objects/Files/PBXGroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ final class PBXGroupTests: XCTestCase {
let pbxProject = PBXProject(name: "ProjectName",
buildConfigurationList: XCConfigurationList(),
compatibilityVersion: "0",
preferredProjectObjectVersion: nil,
mainGroup: group)
project.add(object: pbxProject)

Expand Down Expand Up @@ -139,6 +140,7 @@ final class PBXGroupTests: XCTestCase {
let pbxProject = PBXProject(name: "ProjectName",
buildConfigurationList: XCConfigurationList(),
compatibilityVersion: "0",
preferredProjectObjectVersion: nil,
mainGroup: group)
project.add(object: pbxProject)

Expand All @@ -163,6 +165,7 @@ final class PBXGroupTests: XCTestCase {
let pbxProject = PBXProject(name: "ProjectName",
buildConfigurationList: XCConfigurationList(),
compatibilityVersion: "0",
preferredProjectObjectVersion: nil,
mainGroup: group)
project.add(object: pbxProject)

Expand All @@ -186,6 +189,7 @@ final class PBXGroupTests: XCTestCase {
let pbxProject = PBXProject(name: "ProjectName",
buildConfigurationList: XCConfigurationList(),
compatibilityVersion: "0",
preferredProjectObjectVersion: nil,
mainGroup: group)
project.add(object: pbxProject)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extension PBXProject {
PBXProject(name: name,
buildConfigurationList: buildConfigurationList,
compatibilityVersion: compatibilityVersion,
preferredProjectObjectVersion: nil,
mainGroup: mainGroup)
}
}
7 changes: 7 additions & 0 deletions Tests/XcodeProjTests/Objects/Project/PBXProjectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ final class PBXProjectTests: XCTestCase {
let project = PBXProject(name: "",
buildConfigurationList: XCConfigurationList(),
compatibilityVersion: "",
preferredProjectObjectVersion: nil,
mainGroup: PBXGroup(),
attributes: ["LastUpgradeCheck": "0940"],
targetAttributes: [target: ["TestTargetID": "123"]])
Expand Down Expand Up @@ -54,6 +55,7 @@ final class PBXProjectTests: XCTestCase {
let project = PBXProject(name: "Project",
buildConfigurationList: configurationList,
compatibilityVersion: "0",
preferredProjectObjectVersion: nil,
mainGroup: mainGroup,
targets: [target])

Expand Down Expand Up @@ -89,6 +91,7 @@ final class PBXProjectTests: XCTestCase {
let project = PBXProject(name: "Project",
buildConfigurationList: configurationList,
compatibilityVersion: "0",
preferredProjectObjectVersion: nil,
mainGroup: mainGroup,
targets: [target])

Expand Down Expand Up @@ -125,6 +128,7 @@ final class PBXProjectTests: XCTestCase {
let project = PBXProject(name: "Project",
buildConfigurationList: configurationList,
compatibilityVersion: "0",
preferredProjectObjectVersion: nil,
mainGroup: mainGroup,
targets: [target])

Expand Down Expand Up @@ -165,6 +169,7 @@ final class PBXProjectTests: XCTestCase {
let project = PBXProject(name: "Project",
buildConfigurationList: configurationList,
compatibilityVersion: "0",
preferredProjectObjectVersion: nil,
mainGroup: mainGroup,
targets: [target])

Expand Down Expand Up @@ -218,6 +223,7 @@ final class PBXProjectTests: XCTestCase {
let project = PBXProject(name: "Project",
buildConfigurationList: configurationList,
compatibilityVersion: "0",
preferredProjectObjectVersion: nil,
mainGroup: mainGroup,
targets: [target, secondTarget])

Expand Down Expand Up @@ -292,6 +298,7 @@ final class PBXProjectTests: XCTestCase {
let project = PBXProject(name: "Project",
buildConfigurationList: configurationList,
compatibilityVersion: "0",
preferredProjectObjectVersion: nil,
mainGroup: mainGroup,
targets: [target, secondTarget])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ final class PBXAggregateTargetTests: XCTestCase {
let project = PBXProject(name: "Project",
buildConfigurationList: configurationList,
compatibilityVersion: "0",
preferredProjectObjectVersion: nil,
mainGroup: mainGroup)

objects.add(object: project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ final class PBXNativeTargetTests: XCTestCase {
let project = PBXProject(name: "Project",
buildConfigurationList: configurationList,
compatibilityVersion: "0",
preferredProjectObjectVersion: nil,
mainGroup: mainGroup)

objects.add(object: project)
Expand Down
1 change: 1 addition & 0 deletions Tests/XcodeProjTests/Utils/ReferenceGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ private extension PBXProj {
let project = PBXProject(name: "test",
buildConfigurationList: XCConfigurationList.fixture(),
compatibilityVersion: Xcode.Default.compatibilityVersion,
preferredProjectObjectVersion: nil,
mainGroup: mainGroup)

add(object: mainGroup)
Expand Down

0 comments on commit 2f925d2

Please sign in to comment.