Skip to content

Commit 029f1c4

Browse files
authored
Merge pull request #11 from g-Off/xcode-11
adding support for xcode 11 and swift package dependencies
2 parents c6e2329 + 8bcc30a commit 029f1c4

34 files changed

+434
-93
lines changed

Package.resolved

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ let package = Package(
1313
targets: ["XcodeProject"]),
1414
],
1515
dependencies: [
16+
.package(url: "https://github.com/g-Off/ObjectCoder.git", .exact("0.1.0"))
1617
],
1718
targets: [
1819
.target(
1920
name: "XcodeProject",
20-
dependencies: []),
21+
dependencies: ["ObjectCoder"]),
2122
.testTarget(
2223
name: "XcodeProjectTests",
2324
dependencies: ["XcodeProject"]),

Sources/XcodeProject/Archiving/Encoder/AnyCodingKey.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ struct AnyCodingKey: CodingKey, Equatable, Hashable {
2121
self.intValue = intValue
2222
}
2323

24+
init(index: Int) {
25+
self.init(intValue: index)!
26+
}
27+
2428
init<Key>(_ base: Key) where Key: CodingKey {
2529
if let intValue = base.intValue {
2630
self.init(intValue: intValue)!

Sources/XcodeProject/Archiving/Encoder/PBXEncoder.swift

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,38 @@
66
//
77

88
import Foundation
9+
import ObjectCoder
910

1011
class PBXObjectEncoder {
1112
static let objectVersionKey = CodingUserInfoKey(rawValue: "objectVersion")!
1213
var objectVersion: ObjectVersion = .xcode93
1314

15+
private static func quotedKey(_ codingKeys: [CodingKey]) -> CodingKey {
16+
let codingKey = codingKeys.last!
17+
if codingKey.intValue != nil { return codingKey }
18+
return AnyCodingKey(stringValue: codingKey.stringValue.quotedString)!
19+
}
20+
1421
func encode(_ object: PBXObject) throws -> [String: AnyObject] {
15-
let encoder = _PBXObjectEncoder()
16-
encoder.userInfo = [PBXObjectEncoder.objectVersionKey: objectVersion]
22+
let options = ObjectEncoder<NSObject>.Options(
23+
keyEncodingStrategy: .custom(PBXObjectEncoder.quotedKey),
24+
userInfo: [PBXObjectEncoder.objectVersionKey: objectVersion]
25+
)
26+
let boxer = ObjectEncoder<NSObject>.Boxer()
27+
boxer.addWrapper { (object: PBXObject) -> NSObject in
28+
return NSString(string: object.plistID.description)
29+
}
30+
boxer.encodedString = { (value, _) in
31+
return NSString(string: value.quotedString)
32+
}
33+
let encoder = ObjectEncoder(options: options, boxer: boxer)
1734
try object.encode(to: encoder)
18-
return encoder.storage.popContainer() as? [String: AnyObject] ?? [:]
35+
return encoder.encoded as? [String: AnyObject] ?? [:]
36+
37+
// let encoder = _PBXObjectEncoder()
38+
// encoder.userInfo = [PBXObjectEncoder.objectVersionKey: objectVersion]
39+
// try object.encode(to: encoder)
40+
// return encoder.storage.popContainer() as? [String: AnyObject] ?? [:]
1941
}
2042
}
2143

Sources/XcodeProject/Archiving/Encoder/_PBXObjectEncoder+KeyedContainer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ extension _PBXObjectEncoder.KeyedContainer: KeyedEncodingContainerProtocol {
2828
}
2929

3030
func encodeNil(forKey key: Key) throws {
31-
container[key.stringValue] = NSNull()
31+
container[key.stringValue.quotedString] = NSNull()
3232
}
3333

3434
func encode(_ value: String, forKey key: Key) throws {
35-
container[key.stringValue] = NSString(string: value.quotedString)
35+
container[key.stringValue.quotedString] = NSString(string: value.quotedString)
3636
}
3737

3838
func encode<T>(_ value: T, forKey key: Key) throws where T: Encodable {
3939
encoder.codingPath.append(key)
4040
defer { encoder.codingPath.removeLast() }
41-
container[key.stringValue] = try encoder.box(value)
41+
container[key.stringValue.quotedString] = try encoder.box(value)
4242
}
4343

4444
func nestedContainer<NestedKey>(keyedBy keyType: NestedKey.Type, forKey key: Key) -> KeyedEncodingContainer<NestedKey> where NestedKey: CodingKey {

Sources/XcodeProject/Archiving/PropertyList.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ struct PropertyList {
2121
return PropertyList(value)
2222
}
2323

24+
subscript(key: CodingKey) -> PropertyList? {
25+
guard let dictionary = self.dictionary else { return nil }
26+
return PropertyList(dictionary[key.stringValue])
27+
}
28+
2429
private func getTypedObject<T>() -> T? {
2530
return object as? T
2631
}

Sources/XcodeProject/Objects/Build Phases/PBXBuildPhase.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright © 2017 Geoffrey Foster. All rights reserved.
77
//
88

9-
public class PBXBuildPhase: PBXObject {
9+
public class PBXBuildPhase: PBXProjectItem {
1010
private enum CodingKeys: String, CodingKey {
1111
case name
1212
case files
@@ -61,18 +61,18 @@ public class PBXBuildPhase: PBXObject {
6161
override func update(with plist: PropertyList, objectCache: ObjectCache) {
6262
super.update(with: plist, objectCache: objectCache)
6363

64-
guard let files = plist["files"]?.array else {
64+
guard let files = plist[CodingKeys.files]?.array else {
6565
fatalError()
6666
}
67-
self._name = plist["name"]?.string
67+
self._name = plist[CodingKeys.name]?.string
6868
self.files = files.compactMap {
6969
let file: PBXBuildFile? = objectCache.object(for: PBXGlobalID(rawValue: $0))
7070
return file
7171
}
7272

73-
self.runOnlyForDeploymentPostprocessing = plist["runOnlyForDeploymentPostprocessing"]?.bool
73+
self.runOnlyForDeploymentPostprocessing = plist[CodingKeys.runOnlyForDeploymentPostprocessing]?.bool
7474

75-
if let v = plist["buildActionMask"]?.string, let buildActionMask = Int32(v) {
75+
if let v = plist[CodingKeys.buildActionMask]?.string, let buildActionMask = Int32(v) {
7676
self.buildActionMask = buildActionMask
7777
}
7878
}

Sources/XcodeProject/Objects/Build Phases/PBXCopyFilesBuildPhase.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public final class PBXCopyFilesBuildPhase: PBXBuildPhase {
3939

4040
override func update(with plist: PropertyList, objectCache: ObjectCache) {
4141
super.update(with: plist, objectCache: objectCache)
42-
guard let dstPath = plist["dstPath"]?.string else { fatalError() }
42+
guard let dstPath = plist[CodingKeys.dstPath]?.string else { fatalError() }
4343
self.dstPath = dstPath
44-
guard let dstSubfolderSpec = Destination(string: plist["dstSubfolderSpec"]?.string) else { fatalError() }
44+
guard let dstSubfolderSpec = Destination(string: plist[CodingKeys.dstSubfolderSpec]?.string) else { fatalError() }
4545
self.dstSubfolderSpec = dstSubfolderSpec
4646
}
4747

Sources/XcodeProject/Objects/Build Phases/PBXShellScriptBuildPhase.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ public final class PBXShellScriptBuildPhase: PBXBuildPhase {
2727

2828
override func update(with plist: PropertyList, objectCache: ObjectCache) {
2929
super.update(with: plist, objectCache: objectCache)
30-
self.inputPaths = plist["inputPaths"]?.array ?? []
31-
self.outputPaths = plist["outputPaths"]?.array ?? []
32-
self.inputFileListPaths = plist["inputFileListPaths"]?.array ?? []
33-
self.outputFileListPaths = plist["outputFileListPaths"]?.array ?? []
34-
self.shellPath = plist["shellPath"]?.string
35-
self.shellScript = plist["shellScript"]?.string
36-
self.showEnvVarsInLog = plist["showEnvVarsInLog"]?.bool
30+
self.inputPaths = plist[CodingKeys.inputPaths]?.array ?? []
31+
self.outputPaths = plist[CodingKeys.outputPaths]?.array ?? []
32+
self.inputFileListPaths = plist[CodingKeys.inputFileListPaths]?.array ?? []
33+
self.outputFileListPaths = plist[CodingKeys.outputFileListPaths]?.array ?? []
34+
self.shellPath = plist[CodingKeys.shellPath]?.string
35+
self.shellScript = plist[CodingKeys.shellScript]?.string
36+
self.showEnvVarsInLog = plist[CodingKeys.showEnvVarsInLog]?.bool
3737
}
3838

3939
public override func encode(to encoder: Encoder) throws {

Sources/XcodeProject/Objects/PBXBuildFile.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
// Copyright © 2017 Geoffrey Foster. All rights reserved.
77
//
88

9-
public final class PBXBuildFile: PBXObject {
9+
public final class PBXBuildFile: PBXProjectItem {
1010
private enum CodingKeys: String, CodingKey {
1111
case fileRef
1212
case settings
13+
case productRef
1314
}
1415
public enum Attribute: String, Comparable, Encodable {
1516
public static func < (lhs: PBXBuildFile.Attribute, rhs: PBXBuildFile.Attribute) -> Bool {
@@ -18,6 +19,7 @@ public final class PBXBuildFile: PBXObject {
1819

1920
case `public` = "Public"
2021
case `private` = "Private"
22+
case required = "Required"
2123
case `weak` = "Weak"
2224
case client = "Client"
2325
case server = "Server"
@@ -61,6 +63,8 @@ public final class PBXBuildFile: PBXObject {
6163
}
6264
var settings: Settings?
6365

66+
private(set) var productReference: PBXProductDependency?
67+
6468
public convenience init(globalID: PBXGlobalID, fileReference: PBXReference) {
6569
self.init(globalID: globalID)
6670
fileRef = fileReference
@@ -71,24 +75,27 @@ public final class PBXBuildFile: PBXObject {
7175
var container = encoder.container(keyedBy: CodingKeys.self)
7276
try container.encodeIfPresent(fileRef, forKey: .fileRef)
7377
try container.encodeIfPresent(settings, forKey: .settings)
78+
try container.encodeIfPresent(productReference, forKey: .productRef)
7479
}
7580

7681
override func update(with plist: PropertyList, objectCache: ObjectCache) {
7782
super.update(with: plist, objectCache: objectCache)
78-
self.fileRef = objectCache.object(for: PBXGlobalID(rawValue: plist["fileRef"]?.string))
83+
self.fileRef = objectCache.object(for: PBXGlobalID(rawValue: plist[CodingKeys.fileRef]?.string))
84+
self.productReference = objectCache.object(for: PBXGlobalID(rawValue: plist[CodingKeys.productRef]?.string))
7985
self.settings = Settings(plist["settings"]?.dictionary)
8086
}
8187

8288
override var archiveComment: String {
83-
guard let fileRef = fileRef, let parent = parent else {
89+
guard let parent = parent, let refComment = fileRef?.archiveComment ?? productReference?.archiveComment else {
8490
return super.archiveComment
8591
}
86-
return "\(fileRef.archiveComment) in \(parent.archiveComment)"
92+
return "\(refComment) in \(parent.archiveComment)"
8793
}
8894

8995
override func visit(_ visitor: ObjectVisitor) {
9096
super.visit(visitor)
9197
visitor.visit(object: fileRef)
98+
visitor.visit(object: productReference)
9299
}
93100

94101
override var archiveInPlistOnSingleLine: Bool {

0 commit comments

Comments
 (0)