Skip to content

Commit 4005f0c

Browse files
committed
[PackageModel] Use PolymorphicCodable for Target
1 parent 9013e6e commit 4005f0c

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

Sources/PackageModel/Package.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public final class Package: Codable {
5555
}
5656

5757
/// The targets contained in the package.
58-
public let targets: [Target]
58+
@PolymorphicCodableArray
59+
public var targets: [Target]
5960

6061
/// The products produced by the package.
6162
public let products: [Product]
@@ -80,7 +81,7 @@ public final class Package: Codable {
8081
) {
8182
self.manifest = manifest
8283
self.path = path
83-
self.targets = targets
84+
self._targets = .init(wrappedValue: targets)
8485
self.products = products
8586
self.targetSearchPath = targetSearchPath
8687
self.testTargetSearchPath = testTargetSearchPath

Sources/PackageModel/Product.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
import TSCBasic
12+
import TSCUtility
1213

1314
/// The type of product.
1415
public enum ProductType: CustomStringConvertible, Equatable {
@@ -66,7 +67,8 @@ public class Product: Codable {
6667
///
6768
/// This is never empty, and is only the targets which are required to be in
6869
/// the product, but not necessarily their transitive dependencies.
69-
public let targets: [Target]
70+
@PolymorphicCodableArray
71+
public var targets: [Target]
7072

7173
/// The path to linux main file.
7274
public let linuxMain: AbsolutePath?
@@ -85,7 +87,7 @@ public class Product: Codable {
8587
}
8688
self.name = name
8789
self.type = type
88-
self.targets = targets
90+
self._targets = .init(wrappedValue: targets)
8991
self.linuxMain = linuxMain
9092
}
9193
}

Sources/PackageModel/Target.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@
99
*/
1010

1111
import TSCBasic
12+
import TSCUtility
13+
14+
public class Target: ObjectIdentifierProtocol, PolymorphicCodableProtocol {
15+
public static var implementations: [PolymorphicCodableProtocol.Type] = [
16+
SwiftTarget.self,
17+
ClangTarget.self,
18+
SystemLibraryTarget.self,
19+
BinaryTarget.self,
20+
]
1221

13-
public class Target: ObjectIdentifierProtocol, Codable {
1422
/// The target kind.
1523
public enum Kind: String, Codable {
1624
case executable

swift-tools-support-core/Sources/TSCUtility/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ add_library(TSCUtility
2525
OSLog.swift
2626
PkgConfig.swift
2727
Platform.swift
28+
PolymorphicCodable.swift
2829
ProgressAnimation.swift
2930
SimplePersistence.swift
3031
StringExtensions.swift

0 commit comments

Comments
 (0)