Skip to content

Commit 85d78e3

Browse files
marcpruxMaxDesiatov
andcommitted
Allow omitting the target triple for swift sdk configure (swiftlang#8856)
You can now run `swift sdk configure --sdk-root-path /some/sdk/root sdk-id` without needing to specify the target triple The Android SDK (swiftlang/swift#80788 (comment)) needs to have its `sdkRootPath` configured to point to an external NDK sysroot. But it contains many different target triples, like `armv7-unknown-linux-androideabi33` and `x86_64-unknown-linux-android29`, all of which need to be configured to point to the same sysroot. Following on to swiftlang#8687 and swiftlang/swift-evolution#2888, this PR enables running a single command to configure the entire SDK, like so: ``` swift run swift-sdk configure --sdk-root-path ~/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/sysroot swift-6.1-RELEASE-android-24-0.1 ``` This will result in configurations being created for each of the target triples for the SDK ID. <details> ``` % swift run swift-sdk configure --sdk-root-path ~/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/sysroot swift-6.1-RELEASE-android-24-0.1 info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android25` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi33` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android26` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi35` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android31` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi29` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android32` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android34` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android27` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi25` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi26` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi24` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android33` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android35` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android29` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android32` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android25` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android24` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi30` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android26` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android33` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi32` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android35` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android34` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android31` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android28` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android27` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android24` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android30` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi28` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `x86_64-unknown-linux-android28` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi27` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android30` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi34` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `armv7-unknown-linux-androideabi31` were successfully updated: sdkRootPath. info: These properties of Swift SDK `swift-6.1-RELEASE-android-24-0.1` for target triple `aarch64-unknown-linux-android29` were successfully updated: sdkRootPath. % ls ~/Library/org.swift.swiftpm/swift-sdks/configuration/ swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android24.json swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android25.json swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android26.json swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android27.json swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android28.json swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android29.json swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android30.json swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android31.json swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android32.json swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android33.json swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android34.json swift-6.1-RELEASE-android-24-0.1_aarch64-unknown-linux-android35.json swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi24.json swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi25.json swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi26.json swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi27.json swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi28.json swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi29.json swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi30.json swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi31.json swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi32.json swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi33.json swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi34.json swift-6.1-RELEASE-android-24-0.1_armv7-unknown-linux-androideabi35.json swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android24.json swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android25.json swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android26.json swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android27.json swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android28.json swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android29.json swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android30.json swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android31.json swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android32.json swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android33.json swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android34.json swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android35.json % cat ~/Library/org.swift.swiftpm/swift-sdks/configuration/swift-6.1-RELEASE-android-24-0.1_x86_64-unknown-linux-android31.json { "sdkRootPath" : "/Users/marc/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/sysroot", "swiftResourcesPath" : "/Users/marc/Library/org.swift.swiftpm/swift-sdks/swift-6.1-RELEASE-android-24-0.1.artifactbundle/swift-6.1-release-android-24-sdk/android-27c-sysroot/usr/lib/swift", "swiftStaticResourcesPath" : "/Users/marc/Library/org.swift.swiftpm/swift-sdks/swift-6.1-RELEASE-android-24-0.1.artifactbundle/swift-6.1-release-android-24-sdk/android-27c-sysroot/usr/lib/swift_static-x86_64", "toolsetPaths" : [ "/Users/marc/Library/org.swift.swiftpm/swift-sdks/swift-6.1-RELEASE-android-24-0.1.artifactbundle/swift-6.1-release-android-24-sdk/swift-toolset.json" ] } ``` </details> In addition, this fixes swiftlang#8584, where `swift sdk configure` with a specified target triple didn't work at all, and instead would configure some random target triple for the specified SDK. Make the `targetTriple` flag for `ConfigureSwiftSDK` optional and, when nil, apply the command to all triples included in the specified SDK. Fixes swiftlang#8584 and enables configuring multiple target triples with a single `swift sdk configure` command. --------- Co-authored-by: Max Desiatov <[email protected]> (cherry picked from commit 69f851d)
1 parent abd6543 commit 85d78e3

File tree

6 files changed

+379
-209
lines changed

6 files changed

+379
-209
lines changed

Sources/PackageManagerDocs/Documentation.docc/SDK/SDKConfigure.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,21 @@
88
Manages configuration options for installed Swift SDKs.
99

1010
```
11-
sdk configure [--package-path=<package-path>] [--cache-path=<cache-path>] [--config-path=<config-path>] [--security-path=<security-path>] [--scratch-path=<scratch-path>] [--swift-sdks-path=<swift-sdks-path>] [--toolset=<toolset>...] [--pkg-config-path=<pkg-config-path>...] [--sdk-root-path=<sdk-root-path>] [--swift-resources-path=<swift-resources-path>] [--swift-static-resources-path=<swift-static-resources-path>] [--include-search-path=<include-search-path>...] [--library-search-path=<library-search-path>...] [--toolset-path=<toolset-path>...] [--reset] [--show-configuration] <sdk-id> <target-triple> [--version] [--help]
11+
sdk configure [--package-path=<package-path>]
12+
[--cache-path=<cache-path>] [--config-path=<config-path>]
13+
[--security-path=<security-path>]
14+
[--scratch-path=<scratch-path>]
15+
[--swift-sdks-path=<swift-sdks-path>]
16+
[--toolset=<toolset>...]
17+
[--pkg-config-path=<pkg-config-path>...]
18+
[--sdk-root-path=<sdk-root-path>]
19+
[--swift-resources-path=<swift-resources-path>]
20+
[--swift-static-resources-path=<swift-static-resources-path>]
21+
[--include-search-path=<include-search-path>...]
22+
[--library-search-path=<library-search-path>...]
23+
[--toolset-path=<toolset-path>...] [--reset]
24+
[--show-configuration] <sdk-id> [target-triple...] [--version]
25+
[--help]
1226
```
1327

1428
- term **--package-path=\<package-path\>**:

Sources/PackageModel/SwiftSDKs/SwiftSDK.swift

Lines changed: 120 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public enum SwiftSDKError: Swift.Error {
5353
case unserializableMetadata
5454

5555
/// No configuration values are available for this Swift SDK and target triple.
56-
case swiftSDKNotFound(artifactID: String, hostTriple: Triple, targetTriple: Triple)
56+
case swiftSDKNotFound(artifactID: String, hostTriple: Triple, targetTriple: Triple?)
5757

5858
/// A Swift SDK bundle with this name is already installed, can't install a new bundle with the same name.
5959
case swiftSDKBundleAlreadyInstalled(bundleName: String)
@@ -108,10 +108,16 @@ extension SwiftSDKError: CustomStringConvertible {
108108
properties required for initialization
109109
"""
110110
case .swiftSDKNotFound(let artifactID, let hostTriple, let targetTriple):
111-
return """
112-
Swift SDK with ID `\(artifactID)`, host triple \(hostTriple), and target triple \(targetTriple) is not \
113-
currently installed.
114-
"""
111+
if let targetTriple {
112+
return """
113+
Swift SDK with ID `\(artifactID)`, host triple \(hostTriple), and target triple \(targetTriple) is not \
114+
currently installed.
115+
"""
116+
} else {
117+
return """
118+
Swift SDK with ID `\(artifactID)` is not currently installed.
119+
"""
120+
}
115121
case .swiftSDKBundleAlreadyInstalled(let bundleName):
116122
return """
117123
Swift SDK bundle with name `\(bundleName)` is already installed. Can't install a new bundle \
@@ -259,14 +265,17 @@ public struct SwiftSDK: Equatable {
259265
/// deserialization.
260266
public private(set) var toolset: Toolset
261267

262-
public struct PathsConfiguration: Equatable {
268+
/// The paths associated with a Swift SDK. The Path type can be a `String`
269+
/// to encapsulate the arguments for the `SwiftSDKConfigurationStore.configure`
270+
/// function, or can be a fully-realized `AbsolutePath` when deserialized from a configuration.
271+
public struct PathsConfiguration<Path: Equatable>: Equatable {
263272
public init(
264-
sdkRootPath: Basics.AbsolutePath?,
265-
swiftResourcesPath: Basics.AbsolutePath? = nil,
266-
swiftStaticResourcesPath: Basics.AbsolutePath? = nil,
267-
includeSearchPaths: [Basics.AbsolutePath]? = nil,
268-
librarySearchPaths: [Basics.AbsolutePath]? = nil,
269-
toolsetPaths: [Basics.AbsolutePath]? = nil
273+
sdkRootPath: Path? = nil,
274+
swiftResourcesPath: Path? = nil,
275+
swiftStaticResourcesPath: Path? = nil,
276+
includeSearchPaths: [Path]? = nil,
277+
librarySearchPaths: [Path]? = nil,
278+
toolsetPaths: [Path]? = nil
270279
) {
271280
self.sdkRootPath = sdkRootPath
272281
self.swiftResourcesPath = swiftResourcesPath
@@ -277,22 +286,22 @@ public struct SwiftSDK: Equatable {
277286
}
278287

279288
/// Root directory path of the SDK used to compile for the target triple.
280-
public var sdkRootPath: Basics.AbsolutePath?
289+
public var sdkRootPath: Path?
281290

282291
/// Path containing Swift resources for dynamic linking.
283-
public var swiftResourcesPath: Basics.AbsolutePath?
292+
public var swiftResourcesPath: Path?
284293

285294
/// Path containing Swift resources for static linking.
286-
public var swiftStaticResourcesPath: Basics.AbsolutePath?
295+
public var swiftStaticResourcesPath: Path?
287296

288297
/// Array of paths containing headers.
289-
public var includeSearchPaths: [Basics.AbsolutePath]?
298+
public var includeSearchPaths: [Path]?
290299

291300
/// Array of paths containing libraries.
292-
public var librarySearchPaths: [Basics.AbsolutePath]?
301+
public var librarySearchPaths: [Path]?
293302

294303
/// Array of paths containing toolset files.
295-
public var toolsetPaths: [Basics.AbsolutePath]?
304+
public var toolsetPaths: [Path]?
296305

297306
/// Initialize paths configuration from values deserialized using v3 schema.
298307
/// - Parameters:
@@ -301,92 +310,53 @@ public struct SwiftSDK: Equatable {
301310
fileprivate init(
302311
_ properties: SerializedDestinationV3.TripleProperties,
303312
swiftSDKDirectory: Basics.AbsolutePath? = nil
304-
) throws {
305-
if let swiftSDKDirectory {
306-
self.init(
307-
sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath, relativeTo: swiftSDKDirectory),
308-
swiftResourcesPath: try properties.swiftResourcesPath.map {
309-
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
310-
},
311-
swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map {
312-
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
313-
},
314-
includeSearchPaths: try properties.includeSearchPaths?.map {
315-
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
316-
},
317-
librarySearchPaths: try properties.librarySearchPaths?.map {
318-
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
319-
},
320-
toolsetPaths: try properties.toolsetPaths?.map {
321-
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
322-
}
323-
)
324-
} else {
325-
self.init(
326-
sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath),
327-
swiftResourcesPath: try properties.swiftResourcesPath.map {
328-
try AbsolutePath(validating: $0)
329-
},
330-
swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map {
331-
try AbsolutePath(validating: $0)
332-
},
333-
includeSearchPaths: try properties.includeSearchPaths?.map {
334-
try AbsolutePath(validating: $0)
335-
},
336-
librarySearchPaths: try properties.librarySearchPaths?.map {
337-
try AbsolutePath(validating: $0)
338-
},
339-
toolsetPaths: try properties.toolsetPaths?.map {
340-
try AbsolutePath(validating: $0)
341-
}
342-
)
343-
}
313+
) throws where Path == Basics.AbsolutePath {
314+
self.init(
315+
sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath, relativeTo: swiftSDKDirectory),
316+
swiftResourcesPath: try properties.swiftResourcesPath.map {
317+
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
318+
},
319+
swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map {
320+
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
321+
},
322+
includeSearchPaths: try properties.includeSearchPaths?.map {
323+
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
324+
},
325+
librarySearchPaths: try properties.librarySearchPaths?.map {
326+
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
327+
},
328+
toolsetPaths: try properties.toolsetPaths?.map {
329+
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
330+
}
331+
)
344332
}
345333

346334
/// Initialize paths configuration from values deserialized using v4 schema.
347335
/// - Parameters:
348336
/// - properties: properties of a Swift SDK for the given triple.
349337
/// - swiftSDKDirectory: directory used for converting relative paths in `properties` to absolute paths.
350-
fileprivate init(_ properties: SwiftSDKMetadataV4.TripleProperties, swiftSDKDirectory: Basics.AbsolutePath? = nil) throws {
351-
if let swiftSDKDirectory {
352-
self.init(
353-
sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath, relativeTo: swiftSDKDirectory),
354-
swiftResourcesPath: try properties.swiftResourcesPath.map {
355-
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
356-
},
357-
swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map {
358-
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
359-
},
360-
includeSearchPaths: try properties.includeSearchPaths?.map {
361-
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
362-
},
363-
librarySearchPaths: try properties.librarySearchPaths?.map {
364-
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
365-
},
366-
toolsetPaths: try properties.toolsetPaths?.map {
367-
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
368-
}
369-
)
370-
} else {
371-
self.init(
372-
sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath),
373-
swiftResourcesPath: try properties.swiftResourcesPath.map {
374-
try AbsolutePath(validating: $0)
375-
},
376-
swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map {
377-
try AbsolutePath(validating: $0)
378-
},
379-
includeSearchPaths: try properties.includeSearchPaths?.map {
380-
try AbsolutePath(validating: $0)
381-
},
382-
librarySearchPaths: try properties.librarySearchPaths?.map {
383-
try AbsolutePath(validating: $0)
384-
},
385-
toolsetPaths: try properties.toolsetPaths?.map {
386-
try AbsolutePath(validating: $0)
387-
}
388-
)
389-
}
338+
fileprivate init(
339+
_ properties: SwiftSDKMetadataV4.TripleProperties,
340+
swiftSDKDirectory: Basics.AbsolutePath? = nil
341+
) throws where Path == Basics.AbsolutePath {
342+
self.init(
343+
sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath, relativeTo: swiftSDKDirectory),
344+
swiftResourcesPath: try properties.swiftResourcesPath.map {
345+
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
346+
},
347+
swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map {
348+
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
349+
},
350+
includeSearchPaths: try properties.includeSearchPaths?.map {
351+
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
352+
},
353+
librarySearchPaths: try properties.librarySearchPaths?.map {
354+
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
355+
},
356+
toolsetPaths: try properties.toolsetPaths?.map {
357+
try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory)
358+
}
359+
)
390360
}
391361

392362
public mutating func merge(with newConfiguration: Self) {
@@ -414,10 +384,48 @@ public struct SwiftSDK: Equatable {
414384
self.toolsetPaths = toolsetPaths
415385
}
416386
}
387+
388+
mutating func merge(
389+
with newConfiguration: PathsConfiguration<String>,
390+
relativeTo basePath: Path?
391+
) throws -> [String] where Path == Basics.AbsolutePath {
392+
var updatedProperties: [String] = []
393+
if let sdkRootPath = newConfiguration.sdkRootPath {
394+
self.sdkRootPath = try AbsolutePath(validating: sdkRootPath, relativeTo: basePath)
395+
updatedProperties.append("sdkRootPath")
396+
}
397+
398+
if let swiftResourcesPath = newConfiguration.swiftResourcesPath {
399+
self.swiftResourcesPath = try AbsolutePath(validating: swiftResourcesPath, relativeTo: basePath)
400+
updatedProperties.append("swiftResourcesPath")
401+
}
402+
403+
if let swiftStaticResourcesPath = newConfiguration.swiftStaticResourcesPath {
404+
self.swiftResourcesPath = try AbsolutePath(validating: swiftStaticResourcesPath, relativeTo: basePath)
405+
updatedProperties.append("swiftStaticResourcesPath")
406+
}
407+
408+
if let includeSearchPaths = newConfiguration.includeSearchPaths, !includeSearchPaths.isEmpty {
409+
self.includeSearchPaths = try includeSearchPaths.map { try AbsolutePath(validating: $0, relativeTo: basePath) }
410+
updatedProperties.append("includeSearchPath")
411+
}
412+
413+
if let librarySearchPaths = newConfiguration.librarySearchPaths, !librarySearchPaths.isEmpty {
414+
self.librarySearchPaths = try librarySearchPaths.map { try AbsolutePath(validating: $0, relativeTo: basePath) }
415+
updatedProperties.append("librarySearchPath")
416+
}
417+
418+
if let toolsetPaths = newConfiguration.toolsetPaths, !toolsetPaths.isEmpty {
419+
self.toolsetPaths = try toolsetPaths.map { try AbsolutePath(validating: $0, relativeTo: basePath) }
420+
updatedProperties.append("toolsetPath")
421+
}
422+
423+
return updatedProperties
424+
}
417425
}
418426

419427
/// Configuration of file system paths used by this Swift SDK when building.
420-
public var pathsConfiguration: PathsConfiguration
428+
public var pathsConfiguration: PathsConfiguration<Basics.AbsolutePath>
421429

422430
/// Creates a Swift SDK with the specified properties.
423431
@available(*, deprecated, message: "use `init(targetTriple:sdkRootDir:toolset:)` instead")
@@ -464,7 +472,7 @@ public struct SwiftSDK: Equatable {
464472
hostTriple: Triple? = nil,
465473
targetTriple: Triple? = nil,
466474
toolset: Toolset,
467-
pathsConfiguration: PathsConfiguration,
475+
pathsConfiguration: PathsConfiguration<Basics.AbsolutePath>,
468476
supportsTesting: Bool
469477
) {
470478
let xctestSupport: XCTestSupport
@@ -489,7 +497,7 @@ public struct SwiftSDK: Equatable {
489497
hostTriple: Triple? = nil,
490498
targetTriple: Triple? = nil,
491499
toolset: Toolset,
492-
pathsConfiguration: PathsConfiguration,
500+
pathsConfiguration: PathsConfiguration<Basics.AbsolutePath>,
493501
xctestSupport: XCTestSupport = .supported
494502
) {
495503
self.hostTriple = hostTriple
@@ -1201,7 +1209,7 @@ extension Optional where Wrapped == [Basics.AbsolutePath] {
12011209
}
12021210
}
12031211

1204-
extension SwiftSDK.PathsConfiguration: CustomStringConvertible {
1212+
extension SwiftSDK.PathsConfiguration: CustomStringConvertible where Path == Basics.AbsolutePath {
12051213
public var description: String {
12061214
"""
12071215
sdkRootPath: \(sdkRootPath.configurationString)
@@ -1213,3 +1221,13 @@ extension SwiftSDK.PathsConfiguration: CustomStringConvertible {
12131221
"""
12141222
}
12151223
}
1224+
1225+
extension Basics.AbsolutePath {
1226+
fileprivate init(validating string: String, relativeTo basePath: Basics.AbsolutePath?) throws {
1227+
if let basePath {
1228+
try self.init(validating: string, relativeTo: basePath)
1229+
} else {
1230+
try self.init(validating: string)
1231+
}
1232+
}
1233+
}

Sources/PackageModel/SwiftSDKs/SwiftSDKBundleStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public final class SwiftSDKBundleStore {
7070
let fileSystem: any FileSystem
7171

7272
/// Observability scope used for logging.
73-
private let observabilityScope: ObservabilityScope
73+
let observabilityScope: ObservabilityScope
7474

7575
/// Closure invoked for output produced by this store during its operation.
7676
private let outputHandler: (Output) -> Void

0 commit comments

Comments
 (0)