@@ -16,8 +16,8 @@ import TSCBasic
16
16
17
17
import struct TSCUtility. Version
18
18
19
- /// Errors related to cross-compilation destinations .
20
- public enum DestinationError : Swift . Error {
19
+ /// Errors related to Swift SDKs .
20
+ public enum SwiftSDKError : Swift . Error {
21
21
/// A passed argument is neither a valid file system path nor a URL.
22
22
case invalidPathOrURL( String )
23
23
@@ -30,67 +30,67 @@ public enum DestinationError: Swift.Error {
30
30
/// Name of the destination bundle is not valid.
31
31
case invalidBundleName( String )
32
32
33
- /// No valid destinations were decoded from a destination file.
34
- case noDestinationsDecoded ( AbsolutePath )
33
+ /// No valid Swift SDKs were decoded from a metadata file.
34
+ case noSwiftSDKDecoded ( AbsolutePath )
35
35
36
36
/// Path used for storing destination configuration data is not a directory.
37
37
case pathIsNotDirectory( AbsolutePath )
38
38
39
- /// A destination couldn't be serialized with the latest serialization schema, potentially because it
39
+ /// Swift SDK metadata couldn't be serialized with the latest serialization schema, potentially because it
40
40
/// was deserialized from an earlier incompatible schema version or initialized manually with properties
41
41
/// required for initialization missing.
42
- case unserializableDestination
42
+ case unserializableMetadata
43
43
44
- /// No configuration values are available for this destination and run-time triple.
45
- case destinationNotFound ( artifactID: String , builtTimeTriple : Triple , runTimeTriple : Triple )
44
+ /// No configuration values are available for this Swift SDK and target triple.
45
+ case swiftSDKNotFound ( artifactID: String , hostTriple : Triple , targetTriple : Triple )
46
46
47
- /// A destination bundle with this name is already installed, can't install a new bundle with the same name.
48
- case destinationBundleAlreadyInstalled ( bundleName: String )
47
+ /// A Swift SDK bundle with this name is already installed, can't install a new bundle with the same name.
48
+ case swiftSDKBundleAlreadyInstalled ( bundleName: String )
49
49
50
- /// A destination with this artifact ID is already installed. Can't install a new bundle with this artifact,
50
+ /// A Swift SDK with this artifact ID is already installed. Can't install a new bundle with this artifact,
51
51
/// installed artifact IDs are expected to be unique.
52
- case destinationArtifactAlreadyInstalled ( installedBundleName: String , newBundleName: String , artifactID: String )
52
+ case swiftSDKArtifactAlreadyInstalled ( installedBundleName: String , newBundleName: String , artifactID: String )
53
53
54
54
#if os(macOS)
55
55
/// Quarantine attribute should be removed by the `xattr` command from an installed bundle.
56
56
case quarantineAttributePresent( bundlePath: AbsolutePath )
57
57
#endif
58
58
}
59
59
60
- extension DestinationError : CustomStringConvertible {
60
+ extension SwiftSDKError : CustomStringConvertible {
61
61
public var description : String {
62
62
switch self {
63
63
case . invalidPathOrURL( let argument) :
64
64
return " ` \( argument) ` is neither a valid filesystem path nor a URL. "
65
65
case . invalidSchemaVersion:
66
- return " unsupported destination file schema version "
66
+ return " unsupported Swift SDK file schema version "
67
67
case . invalidInstallation( let problem) :
68
68
return problem
69
69
case . invalidBundleName( let name) :
70
70
return """
71
71
invalid bundle name ` \( name) `, unpacked Swift SDK bundles are expected to have `.artifactbundle` extension
72
72
"""
73
- case . noDestinationsDecoded ( let path) :
74
- return " no valid Swift SDKs were decoded from a destination file at path ` \( path) ` "
73
+ case . noSwiftSDKDecoded ( let path) :
74
+ return " no valid Swift SDKs were decoded from a metadata file at path ` \( path) ` "
75
75
case . pathIsNotDirectory( let path) :
76
76
return " path expected to be a directory is not a directory or doesn't exist: ` \( path) ` "
77
- case . unserializableDestination :
77
+ case . unserializableMetadata :
78
78
return """
79
79
Swift SDK configuration couldn't be serialized with the latest serialization schema, potentially because \
80
80
it was deserialized from an earlier incompatible schema version or initialized manually with missing \
81
81
properties required for initialization
82
82
"""
83
- case . destinationNotFound ( let artifactID, let buildTimeTriple , let runTimeTriple ) :
83
+ case . swiftSDKNotFound ( let artifactID, let hostTriple , let targetTriple ) :
84
84
return """
85
- Swift SDK with ID ` \( artifactID) `, build-time triple \( buildTimeTriple ) , and run-time triple \
86
- \( runTimeTriple ) is not currently installed.
85
+ Swift SDK with ID ` \( artifactID) `, host triple \( hostTriple ) , and target triple \( targetTriple ) is not \
86
+ currently installed.
87
87
"""
88
- case . destinationBundleAlreadyInstalled ( let bundleName) :
88
+ case . swiftSDKBundleAlreadyInstalled ( let bundleName) :
89
89
return """
90
90
Swift SDK bundle with name ` \( bundleName) ` is already installed. Can't install a new bundle \
91
91
with the same name.
92
92
"""
93
- case . destinationArtifactAlreadyInstalled ( let installedBundleName, let newBundleName, let artifactID) :
93
+ case . swiftSDKArtifactAlreadyInstalled ( let installedBundleName, let newBundleName, let artifactID) :
94
94
return """
95
95
A Swift SDK with artifact ID ` \( artifactID) ` is already included in an installed bundle with name \
96
96
` \( installedBundleName) `. Can't install a new bundle ` \( newBundleName) ` with this artifact, artifact IDs \
@@ -282,6 +282,52 @@ public struct Destination: Equatable {
282
282
}
283
283
}
284
284
285
+ /// Initialize paths configuration from values deserialized using v4 schema.
286
+ /// - Parameters:
287
+ /// - properties: properties of a Swift SDK for the given triple.
288
+ /// - swiftSDKDirectory: directory used for converting relative paths in `properties` to absolute paths.
289
+ fileprivate init ( _ properties: SwiftSDKMetadataV4 . TripleProperties , swiftSDKDirectory: AbsolutePath ? = nil ) throws {
290
+ if let swiftSDKDirectory {
291
+ self . init (
292
+ sdkRootPath: try AbsolutePath ( validating: properties. sdkRootPath, relativeTo: swiftSDKDirectory) ,
293
+ swiftResourcesPath: try properties. swiftResourcesPath. map {
294
+ try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
295
+ } ,
296
+ swiftStaticResourcesPath: try properties. swiftStaticResourcesPath. map {
297
+ try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
298
+ } ,
299
+ includeSearchPaths: try properties. includeSearchPaths? . map {
300
+ try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
301
+ } ,
302
+ librarySearchPaths: try properties. librarySearchPaths? . map {
303
+ try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
304
+ } ,
305
+ toolsetPaths: try properties. toolsetPaths? . map {
306
+ try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
307
+ }
308
+ )
309
+ } else {
310
+ self . init (
311
+ sdkRootPath: try AbsolutePath ( validating: properties. sdkRootPath) ,
312
+ swiftResourcesPath: try properties. swiftResourcesPath. map {
313
+ try AbsolutePath ( validating: $0)
314
+ } ,
315
+ swiftStaticResourcesPath: try properties. swiftStaticResourcesPath. map {
316
+ try AbsolutePath ( validating: $0)
317
+ } ,
318
+ includeSearchPaths: try properties. includeSearchPaths? . map {
319
+ try AbsolutePath ( validating: $0)
320
+ } ,
321
+ librarySearchPaths: try properties. librarySearchPaths? . map {
322
+ try AbsolutePath ( validating: $0)
323
+ } ,
324
+ toolsetPaths: try properties. toolsetPaths? . map {
325
+ try AbsolutePath ( validating: $0)
326
+ }
327
+ )
328
+ }
329
+ }
330
+
285
331
public mutating func merge( with newConfiguration: Self ) {
286
332
if let sdkRootPath = newConfiguration. sdkRootPath {
287
333
self . sdkRootPath = sdkRootPath
@@ -408,7 +454,7 @@ public struct Destination: Equatable {
408
454
environment: environment
409
455
) . spm_chomp ( )
410
456
guard !sdkPathStr. isEmpty else {
411
- throw DestinationError . invalidInstallation ( " default SDK not found " )
457
+ throw SwiftSDKError . invalidInstallation ( " default SDK not found " )
412
458
}
413
459
sdkPath = try AbsolutePath ( validating: sdkPathStr)
414
460
}
@@ -569,12 +615,56 @@ extension Destination {
569
615
destinationDirectory: destinationDirectory
570
616
)
571
617
}
618
+
619
+ case Version ( 4 , 0 , 0 ) :
620
+ let swiftSDKs = try decoder. decode ( path: path, fileSystem: fileSystem, as: SwiftSDKMetadataV4 . self)
621
+ let swiftSDKDirectory = path. parentDirectory
622
+
623
+ return try swiftSDKs. targetTriples. map { triple, properties in
624
+ let triple = try Triple ( triple)
625
+
626
+ let pathStrings = properties. toolsetPaths ?? [ ]
627
+ let toolset = try pathStrings. reduce ( into: Toolset ( knownTools: [ : ] , rootPaths: [ ] ) ) {
628
+ try $0. merge (
629
+ with: Toolset (
630
+ from: . init( validating: $1, relativeTo: swiftSDKDirectory) ,
631
+ at: fileSystem,
632
+ observabilityScope
633
+ )
634
+ )
635
+ }
636
+
637
+ return try Destination (
638
+ targetTriple: triple,
639
+ properties: properties,
640
+ toolset: toolset,
641
+ swiftSDKDirectory: swiftSDKDirectory
642
+ )
643
+ }
572
644
default :
573
- throw DestinationError . invalidSchemaVersion
645
+ throw SwiftSDKError . invalidSchemaVersion
574
646
}
575
647
}
576
648
577
-
649
+ /// Initialize new Swift SDK from values deserialized using v4 schema.
650
+ /// - Parameters:
651
+ /// - targetTriple: triple of the machine running code built with this Swift SDK.
652
+ /// - properties: properties of the Swift SDK for the given triple.
653
+ /// - toolset: combined toolset used by this Swift SDK.
654
+ /// - swiftSDKDirectory: directory used for converting relative paths in `properties` to absolute paths.
655
+ init (
656
+ targetTriple: Triple ,
657
+ properties: SwiftSDKMetadataV4 . TripleProperties ,
658
+ toolset: Toolset = . init( ) ,
659
+ swiftSDKDirectory: AbsolutePath ? = nil
660
+ ) throws {
661
+ self . init (
662
+ targetTriple: targetTriple,
663
+ toolset: toolset,
664
+ pathsConfiguration: try . init( properties, swiftSDKDirectory: swiftSDKDirectory)
665
+ )
666
+ }
667
+
578
668
/// Initialize new destination from values deserialized using v3 schema.
579
669
/// - Parameters:
580
670
/// - runTimeTriple: triple of the machine running code built with this destination.
@@ -641,7 +731,7 @@ extension Destination {
641
731
)
642
732
)
643
733
default :
644
- throw DestinationError . invalidSchemaVersion
734
+ throw SwiftSDKError . invalidSchemaVersion
645
735
}
646
736
}
647
737
@@ -651,12 +741,12 @@ extension Destination {
651
741
/// from different schema versions or constructed manually without providing valid values for such properties.
652
742
var serialized : ( Triple , SerializedDestinationV3 . TripleProperties ) {
653
743
get throws {
654
- guard let runTimeTriple = self . targetTriple, let sdkRootDir = self . pathsConfiguration. sdkRootPath else {
655
- throw DestinationError . unserializableDestination
744
+ guard let targetTriple = self . targetTriple, let sdkRootDir = self . pathsConfiguration. sdkRootPath else {
745
+ throw SwiftSDKError . unserializableMetadata
656
746
}
657
747
658
748
return (
659
- runTimeTriple ,
749
+ targetTriple ,
660
750
. init(
661
751
sdkRootPath: sdkRootDir. pathString,
662
752
swiftResourcesPath: self . pathsConfiguration. swiftResourcesPath? . pathString,
@@ -746,3 +836,29 @@ struct SerializedDestinationV3: Decodable {
746
836
/// Mapping of triple strings to corresponding properties of such run-time triple.
747
837
let runTimeTriples : [ String : TripleProperties ]
748
838
}
839
+
840
+ /// Represents v4 schema of `swift-sdk.json` (previously `destination.json`) files used for cross-compilation.
841
+ struct SwiftSDKMetadataV4 : Decodable {
842
+ struct TripleProperties : Codable {
843
+ /// Path relative to `swift-sdk.json` containing SDK root.
844
+ var sdkRootPath : String
845
+
846
+ /// Path relative to `swift-sdk.json` containing Swift resources for dynamic linking.
847
+ var swiftResourcesPath : String ?
848
+
849
+ /// Path relative to `swift-sdk.json` containing Swift resources for static linking.
850
+ var swiftStaticResourcesPath : String ?
851
+
852
+ /// Array of paths relative to `swift-sdk.json` containing headers.
853
+ var includeSearchPaths : [ String ] ?
854
+
855
+ /// Array of paths relative to `swift-sdk.json` containing libraries.
856
+ var librarySearchPaths : [ String ] ?
857
+
858
+ /// Array of paths relative to `swift-sdk.json` containing toolset files.
859
+ var toolsetPaths : [ String ] ?
860
+ }
861
+
862
+ /// Mapping of triple strings to corresponding properties of such target triple.
863
+ let targetTriples : [ String : TripleProperties ]
864
+ }
0 commit comments