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