@@ -266,14 +266,14 @@ public struct SwiftSDK: Equatable {
266
266
/// deserialization.
267
267
public private( set) var toolset : Toolset
268
268
269
- public struct PathsConfiguration : Equatable {
269
+ public struct PathsConfiguration < Path : Equatable > : Equatable {
270
270
public init (
271
- sdkRootPath: Basics . AbsolutePath ? ,
272
- swiftResourcesPath: Basics . AbsolutePath ? = nil ,
273
- swiftStaticResourcesPath: Basics . AbsolutePath ? = nil ,
274
- includeSearchPaths: [ Basics . AbsolutePath ] ? = nil ,
275
- librarySearchPaths: [ Basics . AbsolutePath ] ? = nil ,
276
- toolsetPaths: [ Basics . AbsolutePath ] ? = nil
271
+ sdkRootPath: Path ? = nil ,
272
+ swiftResourcesPath: Path ? = nil ,
273
+ swiftStaticResourcesPath: Path ? = nil ,
274
+ includeSearchPaths: [ Path ] ? = nil ,
275
+ librarySearchPaths: [ Path ] ? = nil ,
276
+ toolsetPaths: [ Path ] ? = nil
277
277
) {
278
278
self . sdkRootPath = sdkRootPath
279
279
self . swiftResourcesPath = swiftResourcesPath
@@ -284,22 +284,22 @@ public struct SwiftSDK: Equatable {
284
284
}
285
285
286
286
/// Root directory path of the SDK used to compile for the target triple.
287
- public var sdkRootPath : Basics . AbsolutePath ?
287
+ public var sdkRootPath : Path ?
288
288
289
289
/// Path containing Swift resources for dynamic linking.
290
- public var swiftResourcesPath : Basics . AbsolutePath ?
290
+ public var swiftResourcesPath : Path ?
291
291
292
292
/// Path containing Swift resources for static linking.
293
- public var swiftStaticResourcesPath : Basics . AbsolutePath ?
293
+ public var swiftStaticResourcesPath : Path ?
294
294
295
295
/// Array of paths containing headers.
296
- public var includeSearchPaths : [ Basics . AbsolutePath ] ?
296
+ public var includeSearchPaths : [ Path ] ?
297
297
298
298
/// Array of paths containing libraries.
299
- public var librarySearchPaths : [ Basics . AbsolutePath ] ?
299
+ public var librarySearchPaths : [ Path ] ?
300
300
301
301
/// Array of paths containing toolset files.
302
- public var toolsetPaths : [ Basics . AbsolutePath ] ?
302
+ public var toolsetPaths : [ Path ] ?
303
303
304
304
/// Initialize paths configuration from values deserialized using v3 schema.
305
305
/// - Parameters:
@@ -308,92 +308,50 @@ public struct SwiftSDK: Equatable {
308
308
fileprivate init (
309
309
_ properties: SerializedDestinationV3 . TripleProperties ,
310
310
swiftSDKDirectory: Basics . AbsolutePath ? = nil
311
- ) throws {
312
- if let swiftSDKDirectory {
313
- self . init (
314
- sdkRootPath: try AbsolutePath ( validating: properties. sdkRootPath, relativeTo: swiftSDKDirectory) ,
315
- swiftResourcesPath: try properties. swiftResourcesPath. map {
316
- try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
317
- } ,
318
- swiftStaticResourcesPath: try properties. swiftStaticResourcesPath. map {
319
- try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
320
- } ,
321
- includeSearchPaths: try properties. includeSearchPaths? . map {
322
- try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
323
- } ,
324
- librarySearchPaths: try properties. librarySearchPaths? . map {
325
- try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
326
- } ,
327
- toolsetPaths: try properties. toolsetPaths? . map {
328
- try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
329
- }
330
- )
331
- } else {
332
- self . init (
333
- sdkRootPath: try AbsolutePath ( validating: properties. sdkRootPath) ,
334
- swiftResourcesPath: try properties. swiftResourcesPath. map {
335
- try AbsolutePath ( validating: $0)
336
- } ,
337
- swiftStaticResourcesPath: try properties. swiftStaticResourcesPath. map {
338
- try AbsolutePath ( validating: $0)
339
- } ,
340
- includeSearchPaths: try properties. includeSearchPaths? . map {
341
- try AbsolutePath ( validating: $0)
342
- } ,
343
- librarySearchPaths: try properties. librarySearchPaths? . map {
344
- try AbsolutePath ( validating: $0)
345
- } ,
346
- toolsetPaths: try properties. toolsetPaths? . map {
347
- try AbsolutePath ( validating: $0)
348
- }
349
- )
350
- }
311
+ ) throws where Path == Basics . AbsolutePath {
312
+ self . init (
313
+ sdkRootPath: try AbsolutePath ( validating: properties. sdkRootPath, relativeTo: swiftSDKDirectory) ,
314
+ swiftResourcesPath: try properties. swiftResourcesPath. map {
315
+ try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
316
+ } ,
317
+ swiftStaticResourcesPath: try properties. swiftStaticResourcesPath. map {
318
+ try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
319
+ } ,
320
+ includeSearchPaths: try properties. includeSearchPaths? . map {
321
+ try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
322
+ } ,
323
+ librarySearchPaths: try properties. librarySearchPaths? . map {
324
+ try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
325
+ } ,
326
+ toolsetPaths: try properties. toolsetPaths? . map {
327
+ try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
328
+ }
329
+ )
351
330
}
352
331
353
332
/// Initialize paths configuration from values deserialized using v4 schema.
354
333
/// - Parameters:
355
334
/// - properties: properties of a Swift SDK for the given triple.
356
335
/// - swiftSDKDirectory: directory used for converting relative paths in `properties` to absolute paths.
357
- fileprivate init ( _ properties: SwiftSDKMetadataV4 . TripleProperties , swiftSDKDirectory: Basics . AbsolutePath ? = nil ) throws {
358
- if let swiftSDKDirectory {
359
- self . init (
360
- sdkRootPath: try AbsolutePath ( validating: properties. sdkRootPath, relativeTo: swiftSDKDirectory) ,
361
- swiftResourcesPath: try properties. swiftResourcesPath. map {
362
- try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
363
- } ,
364
- swiftStaticResourcesPath: try properties. swiftStaticResourcesPath. map {
365
- try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
366
- } ,
367
- includeSearchPaths: try properties. includeSearchPaths? . map {
368
- try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
369
- } ,
370
- librarySearchPaths: try properties. librarySearchPaths? . map {
371
- try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
372
- } ,
373
- toolsetPaths: try properties. toolsetPaths? . map {
374
- try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
375
- }
376
- )
377
- } else {
378
- self . init (
379
- sdkRootPath: try AbsolutePath ( validating: properties. sdkRootPath) ,
380
- swiftResourcesPath: try properties. swiftResourcesPath. map {
381
- try AbsolutePath ( validating: $0)
382
- } ,
383
- swiftStaticResourcesPath: try properties. swiftStaticResourcesPath. map {
384
- try AbsolutePath ( validating: $0)
385
- } ,
386
- includeSearchPaths: try properties. includeSearchPaths? . map {
387
- try AbsolutePath ( validating: $0)
388
- } ,
389
- librarySearchPaths: try properties. librarySearchPaths? . map {
390
- try AbsolutePath ( validating: $0)
391
- } ,
392
- toolsetPaths: try properties. toolsetPaths? . map {
393
- try AbsolutePath ( validating: $0)
394
- }
395
- )
396
- }
336
+ fileprivate init ( _ properties: SwiftSDKMetadataV4 . TripleProperties , swiftSDKDirectory: Basics . AbsolutePath ? = nil ) throws where Path == Basics . AbsolutePath {
337
+ self . init (
338
+ sdkRootPath: try AbsolutePath ( validating: properties. sdkRootPath, relativeTo: swiftSDKDirectory) ,
339
+ swiftResourcesPath: try properties. swiftResourcesPath. map {
340
+ try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
341
+ } ,
342
+ swiftStaticResourcesPath: try properties. swiftStaticResourcesPath. map {
343
+ try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
344
+ } ,
345
+ includeSearchPaths: try properties. includeSearchPaths? . map {
346
+ try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
347
+ } ,
348
+ librarySearchPaths: try properties. librarySearchPaths? . map {
349
+ try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
350
+ } ,
351
+ toolsetPaths: try properties. toolsetPaths? . map {
352
+ try AbsolutePath ( validating: $0, relativeTo: swiftSDKDirectory)
353
+ }
354
+ )
397
355
}
398
356
399
357
public mutating func merge( with newConfiguration: Self ) {
@@ -421,10 +379,45 @@ public struct SwiftSDK: Equatable {
421
379
self . toolsetPaths = toolsetPaths
422
380
}
423
381
}
382
+
383
+ public mutating func merge( with newConfiguration: PathsConfiguration < String > , relativeTo basePath: Path ? ) throws -> [ String ] where Path == Basics . AbsolutePath {
384
+ var updatedProperties : [ String ] = [ ]
385
+ if let sdkRootPath = newConfiguration. sdkRootPath {
386
+ self . sdkRootPath = try AbsolutePath ( validating: sdkRootPath, relativeTo: basePath)
387
+ updatedProperties. append ( " sdkRootPath " )
388
+ }
389
+
390
+ if let swiftResourcesPath = newConfiguration. swiftResourcesPath {
391
+ self . swiftResourcesPath = try AbsolutePath ( validating: swiftResourcesPath, relativeTo: basePath)
392
+ updatedProperties. append ( " swiftResourcesPath " )
393
+ }
394
+
395
+ if let swiftStaticResourcesPath = newConfiguration. swiftStaticResourcesPath {
396
+ self . swiftResourcesPath = try AbsolutePath ( validating: swiftStaticResourcesPath, relativeTo: basePath)
397
+ updatedProperties. append ( " swiftStaticResourcesPath " )
398
+ }
399
+
400
+ if let includeSearchPaths = newConfiguration. includeSearchPaths, !includeSearchPaths. isEmpty {
401
+ self . includeSearchPaths = try includeSearchPaths. map { try AbsolutePath ( validating: $0, relativeTo: basePath) }
402
+ updatedProperties. append ( " includeSearchPath " )
403
+ }
404
+
405
+ if let librarySearchPaths = newConfiguration. librarySearchPaths, !librarySearchPaths. isEmpty {
406
+ self . librarySearchPaths = try librarySearchPaths. map { try AbsolutePath ( validating: $0, relativeTo: basePath) }
407
+ updatedProperties. append ( " librarySearchPath " )
408
+ }
409
+
410
+ if let toolsetPaths = newConfiguration. toolsetPaths, !toolsetPaths. isEmpty {
411
+ self . toolsetPaths = try toolsetPaths. map { try AbsolutePath ( validating: $0, relativeTo: basePath) }
412
+ updatedProperties. append ( " toolsetPath " )
413
+ }
414
+
415
+ return updatedProperties
416
+ }
424
417
}
425
418
426
419
/// Configuration of file system paths used by this Swift SDK when building.
427
- public var pathsConfiguration : PathsConfiguration
420
+ public var pathsConfiguration : PathsConfiguration < Basics . AbsolutePath >
428
421
429
422
/// Creates a Swift SDK with the specified properties.
430
423
@available ( * , deprecated, message: " use `init(targetTriple:sdkRootDir:toolset:)` instead " )
@@ -471,7 +464,7 @@ public struct SwiftSDK: Equatable {
471
464
hostTriple: Triple ? = nil ,
472
465
targetTriple: Triple ? = nil ,
473
466
toolset: Toolset ,
474
- pathsConfiguration: PathsConfiguration ,
467
+ pathsConfiguration: PathsConfiguration < Basics . AbsolutePath > ,
475
468
supportsTesting: Bool
476
469
) {
477
470
let xctestSupport : XCTestSupport
@@ -496,7 +489,7 @@ public struct SwiftSDK: Equatable {
496
489
hostTriple: Triple ? = nil ,
497
490
targetTriple: Triple ? = nil ,
498
491
toolset: Toolset ,
499
- pathsConfiguration: PathsConfiguration ,
492
+ pathsConfiguration: PathsConfiguration < Basics . AbsolutePath > ,
500
493
xctestSupport: XCTestSupport = . supported
501
494
) {
502
495
self . hostTriple = hostTriple
@@ -1208,7 +1201,7 @@ extension Optional where Wrapped == [Basics.AbsolutePath] {
1208
1201
}
1209
1202
}
1210
1203
1211
- extension SwiftSDK . PathsConfiguration : CustomStringConvertible {
1204
+ extension SwiftSDK . PathsConfiguration : CustomStringConvertible where Path == Basics . AbsolutePath {
1212
1205
public var description : String {
1213
1206
"""
1214
1207
sdkRootPath: \( sdkRootPath. configurationString)
@@ -1220,3 +1213,13 @@ extension SwiftSDK.PathsConfiguration: CustomStringConvertible {
1220
1213
"""
1221
1214
}
1222
1215
}
1216
+
1217
+ extension Basics . AbsolutePath {
1218
+ fileprivate init ( validating string: String , relativeTo basePath: Basics . AbsolutePath ? ) throws {
1219
+ if let basePath {
1220
+ try self . init ( validating: string, relativeTo: basePath)
1221
+ } else {
1222
+ try self . init ( validating: string)
1223
+ }
1224
+ }
1225
+ }
0 commit comments