Skip to content

Commit

Permalink
Merge pull request #833 from tuist/waltflanagan/Initial9.0Work
Browse files Browse the repository at this point in the history
Update project to Swift 5.10 and start on `Sendable` updates
  • Loading branch information
waltflanagan authored Aug 7, 2024
2 parents a5120dc + e2b09d3 commit 9dd12c6
Show file tree
Hide file tree
Showing 36 changed files with 516 additions and 369 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.8
// swift-tools-version:5.10

import PackageDescription

Expand Down
11 changes: 11 additions & 0 deletions Sources/XcodeProj/Extensions/NSLocking+withLock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Foundation

// reimplemention of `withLock` from `NSLocking` extension that is exclusive to the macOS version of `Foundation`
extension NSLocking {
func withLock<T>(_ body: () throws -> T) rethrows -> T {
lock()
defer { unlock() }
return try body()
}
}

12 changes: 0 additions & 12 deletions Sources/XcodeProj/Extensions/NSRecursiveLock+Sync.swift

This file was deleted.

10 changes: 5 additions & 5 deletions Sources/XcodeProj/Objects/BuildPhase/PBXBuildFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public final class PBXBuildFile: PBXObject {
/// Returns the file the build file refers to.
public var file: PBXFileElement? {
get {
fileReference?.getObject()
fileReference?.object()
}
set {
fileReference = newValue?.reference
Expand All @@ -23,7 +23,7 @@ public final class PBXBuildFile: PBXObject {
/// Product.
public var product: XCSwiftPackageProductDependency? {
get {
productReference?.getObject()
productReference?.object()
}
set {
productReference = newValue?.reference
Expand Down Expand Up @@ -104,8 +104,8 @@ extension PBXBuildFile {
/// - Returns: file name.
/// - Throws: an error if the name cannot be obtained.
func fileName() throws -> String? {
if let fileElement: PBXFileElement = fileReference?.getObject(), let name = fileElement.fileName() { return name }
if let product: XCSwiftPackageProductDependency = productReference?.getObject() { return product.productName }
if let fileElement: PBXFileElement = fileReference?.object(), let name = fileElement.fileName() { return name }
if let product: XCSwiftPackageProductDependency = productReference?.object() { return product.productName }
return nil
}

Expand Down Expand Up @@ -171,7 +171,7 @@ final class PBXBuildPhaseFile: PlistSerializable, Equatable {
var dictionary: [CommentedString: PlistValue] = [:]
dictionary["isa"] = .string(CommentedString(PBXBuildFile.isa))
if let fileReference = buildFile.fileReference {
let fileElement: PBXFileElement? = fileReference.getObject()
let fileElement: PBXFileElement? = fileReference.object()
dictionary["fileRef"] = .string(CommentedString(fileReference.value, comment: fileElement?.fileName()))
}
if let product = buildFile.product {
Expand Down
2 changes: 1 addition & 1 deletion Sources/XcodeProj/Objects/BuildPhase/PBXBuildPhase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class PBXBuildPhase: PBXContainerItem {
dictionary["buildActionMask"] = .string(CommentedString("\(buildActionMask)"))
if let fileReferences = fileReferences {
let files: PlistValue = .array(fileReferences.map { fileReference in
let buildFile: PBXBuildFile? = fileReference.getObject()
let buildFile: PBXBuildFile? = fileReference.object()
let name = buildFile.flatMap { try? $0.fileName() } ?? nil
let fileName: String = name ?? "(null)"
let type = self.name()
Expand Down
51 changes: 50 additions & 1 deletion Sources/XcodeProj/Objects/Configuration/BuildSettings.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@
import Foundation

/// Build settings.
public typealias BuildSettings = [String: Any]
public typealias BuildSettings = [String: BuildSetting]

public enum BuildSetting: Sendable, Equatable {
case string(String)
case array([String])

var valueForWriting: String {
switch self {
case .string(let string):
return string
case .array(let array):
return array.joined(separator: " ")
}
}
}

extension BuildSetting: Codable {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
do {
let string = try container.decode(String.self)
self = .string(string)
} catch {
let array = try container.decode([String].self)
self = .array(array)
}
}

public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch self {
case .string(let string):
try container.encode(string)
case .array(let array):
try container.encode(array)
}
}
}

extension BuildSetting: ExpressibleByArrayLiteral {
public init(arrayLiteral elements: String...) {
self = .array(elements)
}
}

extension BuildSetting: ExpressibleByStringLiteral {
public init(stringLiteral value: StringLiteralType) {
self = .string(value)
}
}
52 changes: 26 additions & 26 deletions Sources/XcodeProj/Objects/Configuration/XCBuildConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public final class XCBuildConfiguration: PBXObject {
/// Base xcconfig file reference.
public var baseConfiguration: PBXFileReference? {
get {
baseConfigurationReference?.getObject()
baseConfigurationReference?.object()
}
set {
if let newValue = newValue {
Expand Down Expand Up @@ -43,26 +43,26 @@ public final class XCBuildConfiguration: PBXObject {
}

// MARK: - Decodable

fileprivate enum CodingKeys: String, CodingKey {
case baseConfigurationReference
case buildSettings
case name
}

public required init(from decoder: Decoder) throws {
let objects = decoder.context.objects
let objectReferenceRepository = decoder.context.objectReferenceRepository
let container = try decoder.container(keyedBy: CodingKeys.self)
if let baseConfigurationReference: String = try container.decodeIfPresent(.baseConfigurationReference) {
self.baseConfigurationReference = objectReferenceRepository.getOrCreate(reference: baseConfigurationReference, objects: objects)
} else {
baseConfigurationReference = nil
}
buildSettings = try container.decode([String: Any].self, forKey: .buildSettings)
name = try container.decode(.name)
try super.init(from: decoder)

fileprivate enum CodingKeys: String, CodingKey {
case baseConfigurationReference
case buildSettings
case name
}

public required init(from decoder: Decoder) throws {
let objects = decoder.context.objects
let objectReferenceRepository = decoder.context.objectReferenceRepository
let container = try decoder.container(keyedBy: CodingKeys.self)
if let baseConfigurationReference: String = try container.decodeIfPresent(.baseConfigurationReference) {
self.baseConfigurationReference = objectReferenceRepository.getOrCreate(reference: baseConfigurationReference, objects: objects)
} else {
baseConfigurationReference = nil
}
buildSettings = try container.decode(BuildSettings.self, forKey: .buildSettings)
name = try container.decode(.name)
try super.init(from: decoder)
}

// MARK: - Public

Expand All @@ -75,16 +75,16 @@ public final class XCBuildConfiguration: PBXObject {
public func append(setting name: String, value: String) {
guard !value.isEmpty else { return }

let existing: Any = buildSettings[name] ?? "$(inherited)"
let existing: BuildSetting = buildSettings[name] ?? "$(inherited)"

switch existing {
case let string as String where string != value:
case let .string(string) where string != value:
let newValue = [string, value].joined(separator: " ")
buildSettings[name] = newValue
case let array as [String]:
buildSettings[name] = .string(newValue)
case let .array(array):
var newValue = array
newValue.append(value)
buildSettings[name] = newValue.uniqued()
buildSettings[name] = .array(newValue.uniqued())
default:
break
}
Expand All @@ -105,7 +105,7 @@ extension XCBuildConfiguration: PlistSerializable {
dictionary["name"] = .string(CommentedString(name))
dictionary["buildSettings"] = buildSettings.plist()
if let baseConfigurationReference = baseConfigurationReference {
let fileElement: PBXFileElement? = baseConfigurationReference.getObject()
let fileElement: PBXFileElement? = baseConfigurationReference.object()
dictionary["baseConfigurationReference"] = .string(CommentedString(baseConfigurationReference.value, comment: fileElement?.fileName()))
}
return (key: CommentedString(reference, comment: name), value: .dictionary(dictionary))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ extension XCConfigurationList: PlistSerializable {
dictionary["isa"] = .string(CommentedString(XCConfigurationList.isa))
dictionary["buildConfigurations"] = .array(buildConfigurationReferences
.map { configReference in
let config: XCBuildConfiguration? = configReference.getObject()
let config: XCBuildConfiguration? = configReference.object()
return .string(CommentedString(configReference.value, comment: config?.name))
})
dictionary["defaultConfigurationIsVisible"] = .string(CommentedString("\(defaultConfigurationIsVisible.int)"))
Expand Down
4 changes: 2 additions & 2 deletions Sources/XcodeProj/Objects/Files/PBXContainerItemProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public final class PBXContainerItemProxy: PBXObject {
var id: RemoteGlobalID {
switch self {
case let .reference(reference):
if let object = reference.getObject() {
if let object = reference.object() {
return .object(object)
} else {
return .string(reference.value)
Expand Down Expand Up @@ -65,7 +65,7 @@ public final class PBXContainerItemProxy: PBXObject {
/// Use isContainerPortalFileReference to check if you can use the getter
public var containerPortal: ContainerPortal {
get {
ContainerPortal(object: containerPortalReference.getObject())
ContainerPortal(object: containerPortalReference.object())
}
set {
guard let reference = newValue.reference else {
Expand Down
6 changes: 3 additions & 3 deletions Sources/XcodeProj/Objects/Files/PBXFileElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ public extension PBXFileElement {
/// - Returns: path to the variant group base file.
/// - Throws: an error if the path cannot be obtained.
private func baseVariantGroupPath() throws -> String? {
guard let variantGroup: PBXVariantGroup = reference.getObject() else { return nil }
guard let baseReference = try variantGroup
guard let variantGroup: PBXVariantGroup = reference.object() else { return nil }
guard let baseReference = variantGroup
.childrenReferences
.compactMap({ try $0.getThrowingObject() as PBXFileElement })
.compactMap({ $0.object(as: PBXFileElement.self) })
.first(where: { $0.name == "Base" }) else { return nil }
return baseReference.path
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/XcodeProj/Objects/Files/PBXGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class PBXGroup: PBXFileElement {
var dictionary: [CommentedString: PlistValue] = try super.plistKeyAndValue(proj: proj, reference: reference).value.dictionary ?? [:]
dictionary["isa"] = .string(CommentedString(type(of: self).isa))
dictionary["children"] = .array(childrenReferences.map { (fileReference) -> PlistValue in
let fileElement: PBXFileElement? = fileReference.getObject()
let fileElement: PBXFileElement? = fileReference.object()
return .string(CommentedString(fileReference.value, comment: fileElement?.fileName()))
})

Expand Down
4 changes: 2 additions & 2 deletions Sources/XcodeProj/Objects/Files/XCVersionGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public final class XCVersionGroup: PBXGroup {
/// Returns the current version file reference.
public var currentVersion: PBXFileReference? {
get {
currentVersionReference?.getObject()
currentVersionReference?.object()
}
set {
currentVersionReference = newValue?.reference
Expand Down Expand Up @@ -91,7 +91,7 @@ public final class XCVersionGroup: PBXGroup {
dictionary["versionGroupType"] = .string(CommentedString(versionGroupType))
}
if let currentVersionReference = currentVersionReference {
let fileElement: PBXFileElement? = currentVersionReference.getObject()
let fileElement: PBXFileElement? = currentVersionReference.object()
dictionary["currentVersion"] = .string(CommentedString(currentVersionReference.value, comment: fileElement?.fileName()))
}
return (key: CommentedString(reference, comment: path?.split(separator: "/").last.map(String.init)),
Expand Down
Loading

0 comments on commit 9dd12c6

Please sign in to comment.