From 72fb71742a28c933a51e0212291cdf384e3ca829 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Fri, 20 Jun 2025 22:04:38 -0400 Subject: [PATCH 01/17] Allow omitting the target triple for swift sdk configure --- .../Documentation.docc/SDK/SDKConfigure.md | 2 +- Sources/PackageModel/SwiftSDKs/SwiftSDK.swift | 17 +++++++++----- .../SwiftSDKConfigurationStore.swift | 16 ++++++++++++++ .../SwiftSDKCommand/ConfigureSwiftSDK.swift | 22 +++++++++++++++++-- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/Sources/PackageManagerDocs/Documentation.docc/SDK/SDKConfigure.md b/Sources/PackageManagerDocs/Documentation.docc/SDK/SDKConfigure.md index 5198bcdf4ee..3e115644fb9 100644 --- a/Sources/PackageManagerDocs/Documentation.docc/SDK/SDKConfigure.md +++ b/Sources/PackageManagerDocs/Documentation.docc/SDK/SDKConfigure.md @@ -8,7 +8,7 @@ Manages configuration options for installed Swift SDKs. ``` -sdk configure [--package-path=] [--cache-path=] [--config-path=] [--security-path=] [--scratch-path=] [--swift-sdks-path=] [--toolset=...] [--pkg-config-path=...] [--sdk-root-path=] [--swift-resources-path=] [--swift-static-resources-path=] [--include-search-path=...] [--library-search-path=...] [--toolset-path=...] [--reset] [--show-configuration] [--version] [--help] +sdk configure [--package-path=] [--cache-path=] [--config-path=] [--security-path=] [--scratch-path=] [--swift-sdks-path=] [--toolset=...] [--pkg-config-path=...] [--sdk-root-path=] [--swift-resources-path=] [--swift-static-resources-path=] [--include-search-path=...] [--library-search-path=...] [--toolset-path=...] [--reset] [--show-configuration] [] [--version] [--help] ``` - term **--package-path=\**: diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift index cdcdfd781f4..9e8b00b9183 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift @@ -53,7 +53,7 @@ public enum SwiftSDKError: Swift.Error { case unserializableMetadata /// No configuration values are available for this Swift SDK and target triple. - case swiftSDKNotFound(artifactID: String, hostTriple: Triple, targetTriple: Triple) + case swiftSDKNotFound(artifactID: String, hostTriple: Triple, targetTriple: Triple?) /// A Swift SDK bundle with this name is already installed, can't install a new bundle with the same name. case swiftSDKBundleAlreadyInstalled(bundleName: String) @@ -108,10 +108,17 @@ extension SwiftSDKError: CustomStringConvertible { properties required for initialization """ case .swiftSDKNotFound(let artifactID, let hostTriple, let targetTriple): - return """ - Swift SDK with ID `\(artifactID)`, host triple \(hostTriple), and target triple \(targetTriple) is not \ - currently installed. - """ + if let targetTriple { + return """ + Swift SDK with ID `\(artifactID)`, host triple \(hostTriple), and target triple \(targetTriple) is not \ + currently installed. + """ + } else { + return """ + Swift SDK with ID `\(artifactID)` is not \ + currently installed. + """ + } case .swiftSDKBundleAlreadyInstalled(let bundleName): return """ Swift SDK bundle with name `\(bundleName)` is already installed. Can't install a new bundle \ diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift index 105fae09b6c..0d2810bcb89 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift @@ -85,6 +85,22 @@ public final class SwiftSDKConfigurationStore { try encoder.encode(path: configurationPath, fileSystem: fileSystem, properties) } + public func swiftSDKs(for id: String) throws -> [SwiftSDK] { + for bundle in try self.swiftSDKBundleStore.allValidBundles { + for (artifactID, variants) in bundle.artifacts { + guard artifactID == id else { + continue + } + + for variant in variants { + return variant.swiftSDKs + } + } + } + + return [] + } + public func readConfiguration( sdkID: String, targetTriple: Triple diff --git a/Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift b/Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift index 63503962043..b88f5200f8d 100644 --- a/Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift +++ b/Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift @@ -90,7 +90,7 @@ struct ConfigureSwiftSDK: AsyncParsableCommand { var sdkID: String @Argument(help: "The target triple of the Swift SDK to configure.") - var targetTriple: String + var targetTriple: String? /// The file system used by default by this command. private var fileSystem: FileSystem { localFileSystem } @@ -132,8 +132,24 @@ struct ConfigureSwiftSDK: AsyncParsableCommand { hostTimeTriple: triple, swiftSDKBundleStore: bundleStore ) - let targetTriple = try Triple(self.targetTriple) + let targetTriples: [Triple] + if let targetTriple = self.targetTriple { + targetTriples = try [Triple(targetTriple)] + } else { + // when target-triple is unspecified, configure every triple for the SDK + let validBundles = try configurationStore.swiftSDKs(for: sdkID) + targetTriples = validBundles.compactMap(\.targetTriple) + if targetTriples.isEmpty { + throw SwiftSDKError.swiftSDKNotFound( + artifactID: sdkID, + hostTriple: triple, + targetTriple: nil + ) + } + } + + for targetTriple in targetTriples { guard let swiftSDK = try configurationStore.readConfiguration( sdkID: sdkID, targetTriple: targetTriple @@ -216,6 +232,7 @@ struct ConfigureSwiftSDK: AsyncParsableCommand { var swiftSDK = swiftSDK swiftSDK.pathsConfiguration = configuration + swiftSDK.targetTriple = targetTriple try configurationStore.updateConfiguration(sdkID: sdkID, swiftSDK: swiftSDK) observabilityScope.emit( @@ -229,6 +246,7 @@ struct ConfigureSwiftSDK: AsyncParsableCommand { if observabilityScope.errorsReported { throw ExitCode.failure } + } } catch { commandError = error } From 4fdc6fe4330a5cd99f579d0caff847b15e79b9c2 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Mon, 23 Jun 2025 22:35:19 -0400 Subject: [PATCH 02/17] Move SDK configuration to SwiftSDKConfigurationStore and add tests --- Sources/PackageModel/SwiftSDKs/SwiftSDK.swift | 197 +++++++++--------- .../SwiftSDKs/SwiftSDKBundleStore.swift | 2 +- .../SwiftSDKConfigurationStore.swift | 88 ++++++++ .../SwiftSDKCommand/ConfigureSwiftSDK.swift | 136 ++---------- .../SwiftSDKBundleTests.swift | 83 ++++++++ 5 files changed, 286 insertions(+), 220 deletions(-) diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift index 9e8b00b9183..98d0675273e 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift @@ -266,14 +266,14 @@ public struct SwiftSDK: Equatable { /// deserialization. public private(set) var toolset: Toolset - public struct PathsConfiguration: Equatable { + public struct PathsConfiguration: Equatable { public init( - sdkRootPath: Basics.AbsolutePath?, - swiftResourcesPath: Basics.AbsolutePath? = nil, - swiftStaticResourcesPath: Basics.AbsolutePath? = nil, - includeSearchPaths: [Basics.AbsolutePath]? = nil, - librarySearchPaths: [Basics.AbsolutePath]? = nil, - toolsetPaths: [Basics.AbsolutePath]? = nil + sdkRootPath: Path? = nil, + swiftResourcesPath: Path? = nil, + swiftStaticResourcesPath: Path? = nil, + includeSearchPaths: [Path]? = nil, + librarySearchPaths: [Path]? = nil, + toolsetPaths: [Path]? = nil ) { self.sdkRootPath = sdkRootPath self.swiftResourcesPath = swiftResourcesPath @@ -284,22 +284,22 @@ public struct SwiftSDK: Equatable { } /// Root directory path of the SDK used to compile for the target triple. - public var sdkRootPath: Basics.AbsolutePath? + public var sdkRootPath: Path? /// Path containing Swift resources for dynamic linking. - public var swiftResourcesPath: Basics.AbsolutePath? + public var swiftResourcesPath: Path? /// Path containing Swift resources for static linking. - public var swiftStaticResourcesPath: Basics.AbsolutePath? + public var swiftStaticResourcesPath: Path? /// Array of paths containing headers. - public var includeSearchPaths: [Basics.AbsolutePath]? + public var includeSearchPaths: [Path]? /// Array of paths containing libraries. - public var librarySearchPaths: [Basics.AbsolutePath]? + public var librarySearchPaths: [Path]? /// Array of paths containing toolset files. - public var toolsetPaths: [Basics.AbsolutePath]? + public var toolsetPaths: [Path]? /// Initialize paths configuration from values deserialized using v3 schema. /// - Parameters: @@ -308,92 +308,50 @@ public struct SwiftSDK: Equatable { fileprivate init( _ properties: SerializedDestinationV3.TripleProperties, swiftSDKDirectory: Basics.AbsolutePath? = nil - ) throws { - if let swiftSDKDirectory { - self.init( - sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath, relativeTo: swiftSDKDirectory), - swiftResourcesPath: try properties.swiftResourcesPath.map { - try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) - }, - swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map { - try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) - }, - includeSearchPaths: try properties.includeSearchPaths?.map { - try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) - }, - librarySearchPaths: try properties.librarySearchPaths?.map { - try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) - }, - toolsetPaths: try properties.toolsetPaths?.map { - try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) - } - ) - } else { - self.init( - sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath), - swiftResourcesPath: try properties.swiftResourcesPath.map { - try AbsolutePath(validating: $0) - }, - swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map { - try AbsolutePath(validating: $0) - }, - includeSearchPaths: try properties.includeSearchPaths?.map { - try AbsolutePath(validating: $0) - }, - librarySearchPaths: try properties.librarySearchPaths?.map { - try AbsolutePath(validating: $0) - }, - toolsetPaths: try properties.toolsetPaths?.map { - try AbsolutePath(validating: $0) - } - ) - } + ) throws where Path == Basics.AbsolutePath { + self.init( + sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath, relativeTo: swiftSDKDirectory), + swiftResourcesPath: try properties.swiftResourcesPath.map { + try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) + }, + swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map { + try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) + }, + includeSearchPaths: try properties.includeSearchPaths?.map { + try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) + }, + librarySearchPaths: try properties.librarySearchPaths?.map { + try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) + }, + toolsetPaths: try properties.toolsetPaths?.map { + try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) + } + ) } /// Initialize paths configuration from values deserialized using v4 schema. /// - Parameters: /// - properties: properties of a Swift SDK for the given triple. /// - swiftSDKDirectory: directory used for converting relative paths in `properties` to absolute paths. - fileprivate init(_ properties: SwiftSDKMetadataV4.TripleProperties, swiftSDKDirectory: Basics.AbsolutePath? = nil) throws { - if let swiftSDKDirectory { - self.init( - sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath, relativeTo: swiftSDKDirectory), - swiftResourcesPath: try properties.swiftResourcesPath.map { - try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) - }, - swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map { - try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) - }, - includeSearchPaths: try properties.includeSearchPaths?.map { - try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) - }, - librarySearchPaths: try properties.librarySearchPaths?.map { - try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) - }, - toolsetPaths: try properties.toolsetPaths?.map { - try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) - } - ) - } else { - self.init( - sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath), - swiftResourcesPath: try properties.swiftResourcesPath.map { - try AbsolutePath(validating: $0) - }, - swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map { - try AbsolutePath(validating: $0) - }, - includeSearchPaths: try properties.includeSearchPaths?.map { - try AbsolutePath(validating: $0) - }, - librarySearchPaths: try properties.librarySearchPaths?.map { - try AbsolutePath(validating: $0) - }, - toolsetPaths: try properties.toolsetPaths?.map { - try AbsolutePath(validating: $0) - } - ) - } + fileprivate init(_ properties: SwiftSDKMetadataV4.TripleProperties, swiftSDKDirectory: Basics.AbsolutePath? = nil) throws where Path == Basics.AbsolutePath { + self.init( + sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath, relativeTo: swiftSDKDirectory), + swiftResourcesPath: try properties.swiftResourcesPath.map { + try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) + }, + swiftStaticResourcesPath: try properties.swiftStaticResourcesPath.map { + try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) + }, + includeSearchPaths: try properties.includeSearchPaths?.map { + try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) + }, + librarySearchPaths: try properties.librarySearchPaths?.map { + try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) + }, + toolsetPaths: try properties.toolsetPaths?.map { + try AbsolutePath(validating: $0, relativeTo: swiftSDKDirectory) + } + ) } public mutating func merge(with newConfiguration: Self) { @@ -421,10 +379,45 @@ public struct SwiftSDK: Equatable { self.toolsetPaths = toolsetPaths } } + + public mutating func merge(with newConfiguration: PathsConfiguration, relativeTo basePath: Path?) throws -> [String] where Path == Basics.AbsolutePath { + var updatedProperties: [String] = [] + if let sdkRootPath = newConfiguration.sdkRootPath { + self.sdkRootPath = try AbsolutePath(validating: sdkRootPath, relativeTo: basePath) + updatedProperties.append("sdkRootPath") + } + + if let swiftResourcesPath = newConfiguration.swiftResourcesPath { + self.swiftResourcesPath = try AbsolutePath(validating: swiftResourcesPath, relativeTo: basePath) + updatedProperties.append("swiftResourcesPath") + } + + if let swiftStaticResourcesPath = newConfiguration.swiftStaticResourcesPath { + self.swiftResourcesPath = try AbsolutePath(validating: swiftStaticResourcesPath, relativeTo: basePath) + updatedProperties.append("swiftStaticResourcesPath") + } + + if let includeSearchPaths = newConfiguration.includeSearchPaths, !includeSearchPaths.isEmpty { + self.includeSearchPaths = try includeSearchPaths.map { try AbsolutePath(validating: $0, relativeTo: basePath) } + updatedProperties.append("includeSearchPath") + } + + if let librarySearchPaths = newConfiguration.librarySearchPaths, !librarySearchPaths.isEmpty { + self.librarySearchPaths = try librarySearchPaths.map { try AbsolutePath(validating: $0, relativeTo: basePath) } + updatedProperties.append("librarySearchPath") + } + + if let toolsetPaths = newConfiguration.toolsetPaths, !toolsetPaths.isEmpty { + self.toolsetPaths = try toolsetPaths.map { try AbsolutePath(validating: $0, relativeTo: basePath) } + updatedProperties.append("toolsetPath") + } + + return updatedProperties + } } /// Configuration of file system paths used by this Swift SDK when building. - public var pathsConfiguration: PathsConfiguration + public var pathsConfiguration: PathsConfiguration /// Creates a Swift SDK with the specified properties. @available(*, deprecated, message: "use `init(targetTriple:sdkRootDir:toolset:)` instead") @@ -471,7 +464,7 @@ public struct SwiftSDK: Equatable { hostTriple: Triple? = nil, targetTriple: Triple? = nil, toolset: Toolset, - pathsConfiguration: PathsConfiguration, + pathsConfiguration: PathsConfiguration, supportsTesting: Bool ) { let xctestSupport: XCTestSupport @@ -496,7 +489,7 @@ public struct SwiftSDK: Equatable { hostTriple: Triple? = nil, targetTriple: Triple? = nil, toolset: Toolset, - pathsConfiguration: PathsConfiguration, + pathsConfiguration: PathsConfiguration, xctestSupport: XCTestSupport = .supported ) { self.hostTriple = hostTriple @@ -1208,7 +1201,7 @@ extension Optional where Wrapped == [Basics.AbsolutePath] { } } -extension SwiftSDK.PathsConfiguration: CustomStringConvertible { +extension SwiftSDK.PathsConfiguration: CustomStringConvertible where Path == Basics.AbsolutePath { public var description: String { """ sdkRootPath: \(sdkRootPath.configurationString) @@ -1220,3 +1213,13 @@ extension SwiftSDK.PathsConfiguration: CustomStringConvertible { """ } } + +extension Basics.AbsolutePath { + fileprivate init(validating string: String, relativeTo basePath: Basics.AbsolutePath?) throws { + if let basePath { + try self.init(validating: string, relativeTo: basePath) + } else { + try self.init(validating: string) + } + } +} diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDKBundleStore.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDKBundleStore.swift index 39bc3d22a43..5b506feba78 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDKBundleStore.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDKBundleStore.swift @@ -70,7 +70,7 @@ public final class SwiftSDKBundleStore { let fileSystem: any FileSystem /// Observability scope used for logging. - private let observabilityScope: ObservabilityScope + let observabilityScope: ObservabilityScope /// Closure invoked for output produced by this store during its operation. private let outputHandler: (Output) -> Void diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift index 0d2810bcb89..627fdd9a0c3 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift @@ -157,4 +157,92 @@ public final class SwiftSDKConfigurationStore { try fileSystem.removeFileTree(configurationPath) return true } + + public func configure( + sdkID: String, + targetTriple: String?, + showConfiguration: Bool, + resetConfiguration: Bool, + config: SwiftSDK.PathsConfiguration + ) throws -> Bool { + let targetTriples: [Triple] + if let targetTriple = targetTriple { + targetTriples = try [Triple(targetTriple)] + } else { + // when target-triple is unspecified, configure every triple for the SDK + let validBundles = try self.swiftSDKs(for: sdkID) + targetTriples = validBundles.compactMap(\.targetTriple) + if targetTriples.isEmpty { + throw SwiftSDKError.swiftSDKNotFound( + artifactID: sdkID, + hostTriple: hostTriple, + targetTriple: nil + ) + } + } + + for targetTriple in targetTriples { + guard let swiftSDK = try self.readConfiguration( + sdkID: sdkID, + targetTriple: targetTriple + ) else { + throw SwiftSDKError.swiftSDKNotFound( + artifactID: sdkID, + hostTriple: hostTriple, + targetTriple: targetTriple + ) + } + + if showConfiguration { + print(swiftSDK.pathsConfiguration) + continue + } + + if resetConfiguration { + if try !self.resetConfiguration(sdkID: sdkID, targetTriple: targetTriple) { + swiftSDKBundleStore.observabilityScope.emit( + warning: "No configuration for Swift SDK `\(sdkID)`" + ) + } else { + swiftSDKBundleStore.observabilityScope.emit( + info: """ + All configuration properties of Swift SDK `\(sdkID)` for target triple \ + `\(targetTriple)` were successfully reset. + """ + ) + } + } else { + var configuration = swiftSDK.pathsConfiguration + let updatedProperties = try configuration.merge(with: config, relativeTo: fileSystem.currentWorkingDirectory) + + guard !updatedProperties.isEmpty else { + swiftSDKBundleStore.observabilityScope.emit( + error: """ + No properties of Swift SDK `\(sdkID)` for target triple `\(targetTriple)` were updated \ + since none were specified. Pass `--help` flag to see the list of all available properties. + """ + ) + return false + } + + var swiftSDK = swiftSDK + swiftSDK.pathsConfiguration = configuration + swiftSDK.targetTriple = targetTriple + try self.updateConfiguration(sdkID: sdkID, swiftSDK: swiftSDK) + + swiftSDKBundleStore.observabilityScope.emit( + info: """ + These properties of Swift SDK `\(sdkID)` for target triple \ + `\(targetTriple)` were successfully updated: \(updatedProperties.joined(separator: ", ")). + """ + ) + } + + if swiftSDKBundleStore.observabilityScope.errorsReported { + return false + } + } + + return true + } } diff --git a/Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift b/Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift index b88f5200f8d..65be7b6e34d 100644 --- a/Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift +++ b/Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift @@ -132,121 +132,23 @@ struct ConfigureSwiftSDK: AsyncParsableCommand { hostTimeTriple: triple, swiftSDKBundleStore: bundleStore ) - - let targetTriples: [Triple] - if let targetTriple = self.targetTriple { - targetTriples = try [Triple(targetTriple)] - } else { - // when target-triple is unspecified, configure every triple for the SDK - let validBundles = try configurationStore.swiftSDKs(for: sdkID) - targetTriples = validBundles.compactMap(\.targetTriple) - if targetTriples.isEmpty { - throw SwiftSDKError.swiftSDKNotFound( - artifactID: sdkID, - hostTriple: triple, - targetTriple: nil - ) - } - } - - for targetTriple in targetTriples { - guard let swiftSDK = try configurationStore.readConfiguration( + let config = SwiftSDK.PathsConfiguration( + sdkRootPath: self.sdkRootPath, + swiftResourcesPath: self.swiftResourcesPath, + swiftStaticResourcesPath: self.swiftStaticResourcesPath, + includeSearchPaths: self.includeSearchPath, + librarySearchPaths: self.librarySearchPath, + toolsetPaths: self.toolsetPath + ) + if try configurationStore.configure( sdkID: sdkID, - targetTriple: targetTriple - ) else { - throw SwiftSDKError.swiftSDKNotFound( - artifactID: sdkID, - hostTriple: triple, - targetTriple: targetTriple - ) - } - - if self.shouldShowConfiguration { - print(swiftSDK.pathsConfiguration) - return - } - - var configuration = swiftSDK.pathsConfiguration - if self.shouldReset { - if try !configurationStore.resetConfiguration(sdkID: sdkID, targetTriple: targetTriple) { - observabilityScope.emit( - warning: "No configuration for Swift SDK `\(sdkID)`" - ) - } else { - observabilityScope.emit( - info: """ - All configuration properties of Swift SDK `\(sdkID)` for target triple \ - `\(targetTriple)` were successfully reset. - """ - ) - } - } else { - var updatedProperties = [String]() - - let currentWorkingDirectory: AbsolutePath? = fileSystem.currentWorkingDirectory - - if let sdkRootPath { - configuration.sdkRootPath = try AbsolutePath(validating: sdkRootPath, relativeTo: currentWorkingDirectory) - updatedProperties.append(CodingKeys.sdkRootPath.stringValue) - } - - if let swiftResourcesPath { - configuration.swiftResourcesPath = - try AbsolutePath(validating: swiftResourcesPath, relativeTo: currentWorkingDirectory) - updatedProperties.append(CodingKeys.swiftResourcesPath.stringValue) - } - - if let swiftStaticResourcesPath { - configuration.swiftResourcesPath = - try AbsolutePath(validating: swiftStaticResourcesPath, relativeTo: currentWorkingDirectory) - updatedProperties.append(CodingKeys.swiftStaticResourcesPath.stringValue) - } - - if !includeSearchPath.isEmpty { - configuration.includeSearchPaths = - try includeSearchPath.map { try AbsolutePath(validating: $0, relativeTo: currentWorkingDirectory) } - updatedProperties.append(CodingKeys.includeSearchPath.stringValue) - } - - if !librarySearchPath.isEmpty { - configuration.librarySearchPaths = - try librarySearchPath.map { try AbsolutePath(validating: $0, relativeTo: currentWorkingDirectory) } - updatedProperties.append(CodingKeys.librarySearchPath.stringValue) - } - - if !toolsetPath.isEmpty { - configuration.toolsetPaths = - try toolsetPath.map { try AbsolutePath(validating: $0, relativeTo: currentWorkingDirectory) } - updatedProperties.append(CodingKeys.toolsetPath.stringValue) - } - - guard !updatedProperties.isEmpty else { - observabilityScope.emit( - error: """ - No properties of Swift SDK `\(sdkID)` for target triple `\(targetTriple)` were updated \ - since none were specified. Pass `--help` flag to see the list of all available properties. - """ - ) - return - } - - var swiftSDK = swiftSDK - swiftSDK.pathsConfiguration = configuration - swiftSDK.targetTriple = targetTriple - try configurationStore.updateConfiguration(sdkID: sdkID, swiftSDK: swiftSDK) - - observabilityScope.emit( - info: """ - These properties of Swift SDK `\(sdkID)` for target triple \ - `\(targetTriple)` were successfully updated: \(updatedProperties.joined(separator: ", ")). - """ - ) - } - - if observabilityScope.errorsReported { + targetTriple: targetTriple, + showConfiguration: shouldShowConfiguration, + resetConfiguration: shouldReset, + config: config + ) == false { throw ExitCode.failure } - } } catch { commandError = error } @@ -259,13 +161,3 @@ struct ConfigureSwiftSDK: AsyncParsableCommand { } } } - -extension AbsolutePath { - fileprivate init(validating string: String, relativeTo basePath: AbsolutePath?) throws { - if let basePath { - try self.init(validating: string, relativeTo: basePath) - } else { - try self.init(validating: string) - } - } -} diff --git a/Tests/PackageModelTests/SwiftSDKBundleTests.swift b/Tests/PackageModelTests/SwiftSDKBundleTests.swift index a65ed0df18a..035d77e681f 100644 --- a/Tests/PackageModelTests/SwiftSDKBundleTests.swift +++ b/Tests/PackageModelTests/SwiftSDKBundleTests.swift @@ -551,4 +551,87 @@ final class SwiftSDKBundleTests: XCTestCase { ), ]) } + + func testConfigureSDKRootPath() async throws { + func createConfigurationStore() async throws -> (SwiftSDKConfigurationStore, FileSystem) { + let (fileSystem, bundles, swiftSDKsDirectory) = try generateTestFileSystem( + bundleArtifacts: [ + .init(id: testArtifactID, supportedTriples: [arm64Triple, i686Triple]), + ] + ) + let system = ObservabilitySystem.makeForTesting() + + var output = [SwiftSDKBundleStore.Output]() + let store = SwiftSDKBundleStore( + swiftSDKsDirectory: swiftSDKsDirectory, + hostToolchainBinDir: "/tmp", + fileSystem: fileSystem, + observabilityScope: system.topScope, + outputHandler: { + output.append($0) + } + ) + + let archiver = MockArchiver() + for bundle in bundles { + try await store.install(bundlePathOrURL: bundle.path, archiver) + } + + let hostTriple = try Triple("arm64-apple-macosx14.0") + let sdk = try store.selectBundle( + matching: testArtifactID, + hostTriple: hostTriple + ) + + XCTAssertEqual(sdk.targetTriple, targetTriple) + XCTAssertEqual(output, [ + .installationSuccessful( + bundlePathOrURL: bundles[0].path, + bundleName: AbsolutePath(bundles[0].path).components.last! + ) + ]) + + let config = try SwiftSDKConfigurationStore( + hostTimeTriple: hostTriple, + swiftSDKBundleStore: store + ) + + return (config, fileSystem) + } + + do { + let (config, _) = try await createConfigurationStore() + let args = SwiftSDK.PathsConfiguration() + let configSuccess = try config.configure(sdkID: testArtifactID, targetTriple: nil, showConfiguration: false, resetConfiguration: false, config: args) + XCTAssertEqual(configSuccess, false, "Expected failure for SwiftSDKConfigurationStore.configure with no updated properties") + } + + let targetTripleConfigPath = AbsolutePath("/sdks/configuration/\(testArtifactID)_\(targetTriple.tripleString).json") + + do { + let (config, fileSystem) = try await createConfigurationStore() + var args = SwiftSDK.PathsConfiguration() + args.sdkRootPath = "/some/sdk/root/path" + let configSuccess = try config.configure(sdkID: testArtifactID, targetTriple: targetTriple.tripleString, showConfiguration: false, resetConfiguration: false, config: args) + XCTAssertTrue(configSuccess) + XCTAssertTrue(fileSystem.isFile(targetTripleConfigPath)) + + let updatedConfig = try config.readConfiguration(sdkID: testArtifactID, targetTriple: targetTriple) + XCTAssertEqual(args.sdkRootPath, updatedConfig?.pathsConfiguration.sdkRootPath?.pathString) + } + + do { + let (config, fileSystem) = try await createConfigurationStore() + var args = SwiftSDK.PathsConfiguration() + args.sdkRootPath = "/some/sdk/root/path" + // an empty targetTriple will configure all triples + let configSuccess = try config.configure(sdkID: testArtifactID, targetTriple: nil, showConfiguration: false, resetConfiguration: false, config: args) + XCTAssertTrue(configSuccess) + XCTAssertTrue(fileSystem.isFile(targetTripleConfigPath)) + + let resetSuccess = try config.configure(sdkID: testArtifactID, targetTriple: nil, showConfiguration: false, resetConfiguration: true, config: args) + XCTAssertTrue(resetSuccess, "Reset configuration should succeed") + XCTAssertFalse(fileSystem.isFile(targetTripleConfigPath), "Reset configuration should clear configuration folder") + } + } } From 018e73d602de5a8b9ac4c4cafb1fa9fa49d22ddb Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 24 Jun 2025 08:30:29 -0400 Subject: [PATCH 03/17] Make swiftSDKs(for:) private --- Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift index 627fdd9a0c3..5b5de626374 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift @@ -85,7 +85,7 @@ public final class SwiftSDKConfigurationStore { try encoder.encode(path: configurationPath, fileSystem: fileSystem, properties) } - public func swiftSDKs(for id: String) throws -> [SwiftSDK] { + private func swiftSDKs(for id: String) throws -> [SwiftSDK] { for bundle in try self.swiftSDKBundleStore.allValidBundles { for (artifactID, variants) in bundle.artifacts { guard artifactID == id else { From 1524b41e912089c06cae6651f6090605bc744147 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 24 Jun 2025 08:32:39 -0400 Subject: [PATCH 04/17] Update Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift Co-authored-by: Max Desiatov --- .../PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift index 5b5de626374..4335976c6bc 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift @@ -218,9 +218,9 @@ public final class SwiftSDKConfigurationStore { guard !updatedProperties.isEmpty else { swiftSDKBundleStore.observabilityScope.emit( error: """ - No properties of Swift SDK `\(sdkID)` for target triple `\(targetTriple)` were updated \ - since none were specified. Pass `--help` flag to see the list of all available properties. - """ + No properties of Swift SDK `\(sdkID)` for target triple `\(targetTriple)` were updated \ + since none were specified. Pass `--help` flag to see the list of all available properties. + """ ) return false } From 6d090cd3cdc44c1d34c4e9cc168356f2f262120a Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 24 Jun 2025 08:32:53 -0400 Subject: [PATCH 05/17] Update Sources/PackageModel/SwiftSDKs/SwiftSDK.swift Co-authored-by: Max Desiatov --- Sources/PackageModel/SwiftSDKs/SwiftSDK.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift index 98d0675273e..7dfa2cc05b9 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift @@ -333,7 +333,10 @@ public struct SwiftSDK: Equatable { /// - Parameters: /// - properties: properties of a Swift SDK for the given triple. /// - swiftSDKDirectory: directory used for converting relative paths in `properties` to absolute paths. - fileprivate init(_ properties: SwiftSDKMetadataV4.TripleProperties, swiftSDKDirectory: Basics.AbsolutePath? = nil) throws where Path == Basics.AbsolutePath { + fileprivate init( + _ properties: SwiftSDKMetadataV4.TripleProperties, + swiftSDKDirectory: Basics.AbsolutePath? = nil + ) throws where Path == Basics.AbsolutePath { self.init( sdkRootPath: try AbsolutePath(validating: properties.sdkRootPath, relativeTo: swiftSDKDirectory), swiftResourcesPath: try properties.swiftResourcesPath.map { From 94f0e72d14971ab22c6eb8e1808220407cea9413 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 24 Jun 2025 08:33:06 -0400 Subject: [PATCH 06/17] Update Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift Co-authored-by: Max Desiatov --- .../PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift index 4335976c6bc..86178bb1b56 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift @@ -232,9 +232,9 @@ public final class SwiftSDKConfigurationStore { swiftSDKBundleStore.observabilityScope.emit( info: """ - These properties of Swift SDK `\(sdkID)` for target triple \ - `\(targetTriple)` were successfully updated: \(updatedProperties.joined(separator: ", ")). - """ + These properties of Swift SDK `\(sdkID)` for target triple \ + `\(targetTriple)` were successfully updated: \(updatedProperties.joined(separator: ", ")). + """ ) } From 7323ea60b06274b5cfa53db7881daf063581d7aa Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 24 Jun 2025 08:33:22 -0400 Subject: [PATCH 07/17] Update Tests/PackageModelTests/SwiftSDKBundleTests.swift Co-authored-by: Max Desiatov --- Tests/PackageModelTests/SwiftSDKBundleTests.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Tests/PackageModelTests/SwiftSDKBundleTests.swift b/Tests/PackageModelTests/SwiftSDKBundleTests.swift index 035d77e681f..241c777ecbc 100644 --- a/Tests/PackageModelTests/SwiftSDKBundleTests.swift +++ b/Tests/PackageModelTests/SwiftSDKBundleTests.swift @@ -602,7 +602,13 @@ final class SwiftSDKBundleTests: XCTestCase { do { let (config, _) = try await createConfigurationStore() let args = SwiftSDK.PathsConfiguration() - let configSuccess = try config.configure(sdkID: testArtifactID, targetTriple: nil, showConfiguration: false, resetConfiguration: false, config: args) + let configSuccess = try config.configure( + sdkID: testArtifactID, + targetTriple: nil, + showConfiguration: false, + resetConfiguration: false, + config: args + ) XCTAssertEqual(configSuccess, false, "Expected failure for SwiftSDKConfigurationStore.configure with no updated properties") } From d7ce846acf63626e5d7b52bf7d5a53b2ae79e9c5 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 24 Jun 2025 08:33:42 -0400 Subject: [PATCH 08/17] Update Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift Co-authored-by: Max Desiatov --- .../PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift index 86178bb1b56..effed02480e 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift @@ -206,9 +206,9 @@ public final class SwiftSDKConfigurationStore { } else { swiftSDKBundleStore.observabilityScope.emit( info: """ - All configuration properties of Swift SDK `\(sdkID)` for target triple \ - `\(targetTriple)` were successfully reset. - """ + All configuration properties of Swift SDK `\(sdkID)` for target triple \ + `\(targetTriple)` were successfully reset. + """ ) } } else { From bbc9e152eab21be2a59e594d8b31e115cb4dfc4f Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 24 Jun 2025 08:33:59 -0400 Subject: [PATCH 09/17] Update Sources/PackageModel/SwiftSDKs/SwiftSDK.swift Co-authored-by: Max Desiatov --- Sources/PackageModel/SwiftSDKs/SwiftSDK.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift index 7dfa2cc05b9..c028887cd98 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift @@ -115,8 +115,7 @@ extension SwiftSDKError: CustomStringConvertible { """ } else { return """ - Swift SDK with ID `\(artifactID)` is not \ - currently installed. + Swift SDK with ID `\(artifactID)` is not currently installed. """ } case .swiftSDKBundleAlreadyInstalled(let bundleName): From bb6a0d8a4ccc5d7507f080413559157a8b03cb6a Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 24 Jun 2025 08:36:45 -0400 Subject: [PATCH 10/17] Update format of if statement --- Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift b/Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift index 65be7b6e34d..1c6f9512e93 100644 --- a/Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift +++ b/Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift @@ -140,13 +140,13 @@ struct ConfigureSwiftSDK: AsyncParsableCommand { librarySearchPaths: self.librarySearchPath, toolsetPaths: self.toolsetPath ) - if try configurationStore.configure( + if try !configurationStore.configure( sdkID: sdkID, targetTriple: targetTriple, showConfiguration: shouldShowConfiguration, resetConfiguration: shouldReset, config: config - ) == false { + ) { throw ExitCode.failure } } catch { From bf6ea45e3cb40203cee233d39647e0d2e9ed04a1 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 24 Jun 2025 08:38:25 -0400 Subject: [PATCH 11/17] Make SwiftSDK.merge function internal and fix line-length formatting --- Sources/PackageModel/SwiftSDKs/SwiftSDK.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift index c028887cd98..10b895c38f6 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift @@ -382,7 +382,10 @@ public struct SwiftSDK: Equatable { } } - public mutating func merge(with newConfiguration: PathsConfiguration, relativeTo basePath: Path?) throws -> [String] where Path == Basics.AbsolutePath { + mutating func merge( + with newConfiguration: PathsConfiguration, + relativeTo basePath: Path? + ) throws -> [String] where Path == Basics.AbsolutePath { var updatedProperties: [String] = [] if let sdkRootPath = newConfiguration.sdkRootPath { self.sdkRootPath = try AbsolutePath(validating: sdkRootPath, relativeTo: basePath) From 673580901d18e48a221b658a9de45a07e6d69d24 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 24 Jun 2025 10:25:22 -0400 Subject: [PATCH 12/17] Update Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift Co-authored-by: Max Desiatov --- Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift index effed02480e..639ede7dc1b 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift @@ -169,7 +169,7 @@ public final class SwiftSDKConfigurationStore { if let targetTriple = targetTriple { targetTriples = try [Triple(targetTriple)] } else { - // when target-triple is unspecified, configure every triple for the SDK + // when `targetTriple` is unspecified, configure every triple for the SDK let validBundles = try self.swiftSDKs(for: sdkID) targetTriples = validBundles.compactMap(\.targetTriple) if targetTriples.isEmpty { From dec4007af3bd01998faab5edad7459c8d2a16264 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 24 Jun 2025 10:26:58 -0400 Subject: [PATCH 13/17] Add comments for PathsConfiguration --- Sources/PackageModel/SwiftSDKs/SwiftSDK.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift index 10b895c38f6..d04216cc651 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDK.swift @@ -265,6 +265,9 @@ public struct SwiftSDK: Equatable { /// deserialization. public private(set) var toolset: Toolset + /// The paths associated with a Swift SDK. The Path type can be a `String` + /// to encapsulate the arguments for the `SwiftSDKConfigurationStore.configure` + /// function, or can be a fully-realized `AbsolutePath` when deserialized from a configuration. public struct PathsConfiguration: Equatable { public init( sdkRootPath: Path? = nil, From 62596eb0a664223ce93a771f6ff78c276a00eb5d Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 24 Jun 2025 10:36:02 -0400 Subject: [PATCH 14/17] Make SwiftSDKConfigurationStore.configure package accessible and add docs --- .../SwiftSDKs/SwiftSDKConfigurationStore.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift index 639ede7dc1b..a3e84b9bb7c 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift @@ -158,7 +158,15 @@ public final class SwiftSDKConfigurationStore { return true } - public func configure( + /// Configures the specified SDK and identified target triple with the configuration parameter. + /// - Parameters: + /// - sdkID: ID of the Swift SDK to operate on. + /// - tripleString: run-time triple for which the properties should be configured, or nil to configure all triples for the SDK + /// - showConfiguration: if true, simply print the current configuration for the target triple(s) + /// - resetConfiguration: if true, reset the configuration for the target triple(s) + /// - config: the configuration parameters to set for for the target triple(s) + /// - Returns: `true` if custom configuration was successful, `false` if no configuration was performed. + package func configure( sdkID: String, targetTriple: String?, showConfiguration: Bool, From 8271ac3ad98f373c3aefb919276025c51af65420 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 24 Jun 2025 10:45:08 -0400 Subject: [PATCH 15/17] Update Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift Co-authored-by: Max Desiatov --- .../PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift index a3e84b9bb7c..6f446551233 100644 --- a/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift +++ b/Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift @@ -158,10 +158,10 @@ public final class SwiftSDKConfigurationStore { return true } - /// Configures the specified SDK and identified target triple with the configuration parameter. + /// Configures the specified Swift SDK and identified target triple with the configuration parameter. /// - Parameters: /// - sdkID: ID of the Swift SDK to operate on. - /// - tripleString: run-time triple for which the properties should be configured, or nil to configure all triples for the SDK + /// - tripleString: run-time triple for which the properties should be configured, or nil to configure all triples for the Swift SDK /// - showConfiguration: if true, simply print the current configuration for the target triple(s) /// - resetConfiguration: if true, reset the configuration for the target triple(s) /// - config: the configuration parameters to set for for the target triple(s) From b8bc8d841eeb57aa6c065adc5a018064ca01b4a0 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Tue, 24 Jun 2025 10:50:05 -0400 Subject: [PATCH 16/17] Fix line lengths in test case --- .../SwiftSDKBundleTests.swift | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/Tests/PackageModelTests/SwiftSDKBundleTests.swift b/Tests/PackageModelTests/SwiftSDKBundleTests.swift index 241c777ecbc..c53fbb0cdcf 100644 --- a/Tests/PackageModelTests/SwiftSDKBundleTests.swift +++ b/Tests/PackageModelTests/SwiftSDKBundleTests.swift @@ -618,11 +618,20 @@ final class SwiftSDKBundleTests: XCTestCase { let (config, fileSystem) = try await createConfigurationStore() var args = SwiftSDK.PathsConfiguration() args.sdkRootPath = "/some/sdk/root/path" - let configSuccess = try config.configure(sdkID: testArtifactID, targetTriple: targetTriple.tripleString, showConfiguration: false, resetConfiguration: false, config: args) + let configSuccess = try config.configure( + sdkID: testArtifactID, + targetTriple: targetTriple.tripleString, + showConfiguration: false, + resetConfiguration: false, + config: args + ) XCTAssertTrue(configSuccess) XCTAssertTrue(fileSystem.isFile(targetTripleConfigPath)) - let updatedConfig = try config.readConfiguration(sdkID: testArtifactID, targetTriple: targetTriple) + let updatedConfig = try config.readConfiguration( + sdkID: testArtifactID, + targetTriple: targetTriple + ) XCTAssertEqual(args.sdkRootPath, updatedConfig?.pathsConfiguration.sdkRootPath?.pathString) } @@ -631,11 +640,23 @@ final class SwiftSDKBundleTests: XCTestCase { var args = SwiftSDK.PathsConfiguration() args.sdkRootPath = "/some/sdk/root/path" // an empty targetTriple will configure all triples - let configSuccess = try config.configure(sdkID: testArtifactID, targetTriple: nil, showConfiguration: false, resetConfiguration: false, config: args) + let configSuccess = try config.configure( + sdkID: testArtifactID, + targetTriple: nil, + showConfiguration: false, + resetConfiguration: false, + config: args + ) XCTAssertTrue(configSuccess) XCTAssertTrue(fileSystem.isFile(targetTripleConfigPath)) - let resetSuccess = try config.configure(sdkID: testArtifactID, targetTriple: nil, showConfiguration: false, resetConfiguration: true, config: args) + let resetSuccess = try config.configure( + sdkID: testArtifactID, + targetTriple: nil, + showConfiguration: false, + resetConfiguration: true, + config: args + ) XCTAssertTrue(resetSuccess, "Reset configuration should succeed") XCTAssertFalse(fileSystem.isFile(targetTripleConfigPath), "Reset configuration should clear configuration folder") } From b155f05e0c60fd5e151a7b6008b72c6fde441327 Mon Sep 17 00:00:00 2001 From: Marc Prud'hommeaux Date: Fri, 27 Jun 2025 13:00:40 -0400 Subject: [PATCH 17/17] Fix windows path for sdkRootPath test case --- Tests/PackageModelTests/SwiftSDKBundleTests.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Tests/PackageModelTests/SwiftSDKBundleTests.swift b/Tests/PackageModelTests/SwiftSDKBundleTests.swift index c53fbb0cdcf..8262336c8c3 100644 --- a/Tests/PackageModelTests/SwiftSDKBundleTests.swift +++ b/Tests/PackageModelTests/SwiftSDKBundleTests.swift @@ -614,10 +614,16 @@ final class SwiftSDKBundleTests: XCTestCase { let targetTripleConfigPath = AbsolutePath("/sdks/configuration/\(testArtifactID)_\(targetTriple.tripleString).json") + #if os(Windows) + let sdkRootPath = "C:\\some\\sdk\\root\\path" + #else + let sdkRootPath = "/some/sdk/root/path" + #endif + do { let (config, fileSystem) = try await createConfigurationStore() var args = SwiftSDK.PathsConfiguration() - args.sdkRootPath = "/some/sdk/root/path" + args.sdkRootPath = sdkRootPath let configSuccess = try config.configure( sdkID: testArtifactID, targetTriple: targetTriple.tripleString, @@ -638,7 +644,7 @@ final class SwiftSDKBundleTests: XCTestCase { do { let (config, fileSystem) = try await createConfigurationStore() var args = SwiftSDK.PathsConfiguration() - args.sdkRootPath = "/some/sdk/root/path" + args.sdkRootPath = sdkRootPath // an empty targetTriple will configure all triples let configSuccess = try config.configure( sdkID: testArtifactID,