@@ -132,23 +132,121 @@ struct ConfigureSwiftSDK: AsyncParsableCommand {
132132 hostTimeTriple: triple,
133133 swiftSDKBundleStore: bundleStore
134134 )
135- let config = SwiftSDK . PathsConfiguration (
136- sdkRootPath: self . sdkRootPath,
137- swiftResourcesPath: self . swiftResourcesPath,
138- swiftStaticResourcesPath: self . swiftStaticResourcesPath,
139- includeSearchPaths: self . includeSearchPath,
140- librarySearchPaths: self . librarySearchPath,
141- toolsetPaths: self . toolsetPath
142- )
143- if try ! configurationStore. configure (
135+
136+ let targetTriples : [ Triple ]
137+ if let targetTriple = self . targetTriple {
138+ targetTriples = try [ Triple ( targetTriple) ]
139+ } else {
140+ // when target-triple is unspecified, configure every triple for the SDK
141+ let validBundles = try configurationStore. swiftSDKs ( for: sdkID)
142+ targetTriples = validBundles. compactMap ( \. targetTriple)
143+ if targetTriples. isEmpty {
144+ throw SwiftSDKError . swiftSDKNotFound (
145+ artifactID: sdkID,
146+ hostTriple: triple,
147+ targetTriple: nil
148+ )
149+ }
150+ }
151+
152+ for targetTriple in targetTriples {
153+ guard let swiftSDK = try configurationStore. readConfiguration (
144154 sdkID: sdkID,
145- targetTriple: targetTriple,
146- showConfiguration: shouldShowConfiguration,
147- resetConfiguration: shouldReset,
148- config: config
149- ) {
155+ targetTriple: targetTriple
156+ ) else {
157+ throw SwiftSDKError . swiftSDKNotFound (
158+ artifactID: sdkID,
159+ hostTriple: triple,
160+ targetTriple: targetTriple
161+ )
162+ }
163+
164+ if self . shouldShowConfiguration {
165+ print ( swiftSDK. pathsConfiguration)
166+ return
167+ }
168+
169+ var configuration = swiftSDK. pathsConfiguration
170+ if self . shouldReset {
171+ if try ! configurationStore. resetConfiguration ( sdkID: sdkID, targetTriple: targetTriple) {
172+ observabilityScope. emit (
173+ warning: " No configuration for Swift SDK ` \( sdkID) ` "
174+ )
175+ } else {
176+ observabilityScope. emit (
177+ info: """
178+ All configuration properties of Swift SDK ` \( sdkID) ` for target triple \
179+ ` \( targetTriple) ` were successfully reset.
180+ """
181+ )
182+ }
183+ } else {
184+ var updatedProperties = [ String] ( )
185+
186+ let currentWorkingDirectory : AbsolutePath ? = fileSystem. currentWorkingDirectory
187+
188+ if let sdkRootPath {
189+ configuration. sdkRootPath = try AbsolutePath ( validating: sdkRootPath, relativeTo: currentWorkingDirectory)
190+ updatedProperties. append ( CodingKeys . sdkRootPath. stringValue)
191+ }
192+
193+ if let swiftResourcesPath {
194+ configuration. swiftResourcesPath =
195+ try AbsolutePath ( validating: swiftResourcesPath, relativeTo: currentWorkingDirectory)
196+ updatedProperties. append ( CodingKeys . swiftResourcesPath. stringValue)
197+ }
198+
199+ if let swiftStaticResourcesPath {
200+ configuration. swiftResourcesPath =
201+ try AbsolutePath ( validating: swiftStaticResourcesPath, relativeTo: currentWorkingDirectory)
202+ updatedProperties. append ( CodingKeys . swiftStaticResourcesPath. stringValue)
203+ }
204+
205+ if !includeSearchPath. isEmpty {
206+ configuration. includeSearchPaths =
207+ try includeSearchPath. map { try AbsolutePath ( validating: $0, relativeTo: currentWorkingDirectory) }
208+ updatedProperties. append ( CodingKeys . includeSearchPath. stringValue)
209+ }
210+
211+ if !librarySearchPath. isEmpty {
212+ configuration. librarySearchPaths =
213+ try librarySearchPath. map { try AbsolutePath ( validating: $0, relativeTo: currentWorkingDirectory) }
214+ updatedProperties. append ( CodingKeys . librarySearchPath. stringValue)
215+ }
216+
217+ if !toolsetPath. isEmpty {
218+ configuration. toolsetPaths =
219+ try toolsetPath. map { try AbsolutePath ( validating: $0, relativeTo: currentWorkingDirectory) }
220+ updatedProperties. append ( CodingKeys . toolsetPath. stringValue)
221+ }
222+
223+ guard !updatedProperties. isEmpty else {
224+ observabilityScope. emit (
225+ error: """
226+ No properties of Swift SDK ` \( sdkID) ` for target triple ` \( targetTriple) ` were updated \
227+ since none were specified. Pass `--help` flag to see the list of all available properties.
228+ """
229+ )
230+ return
231+ }
232+
233+ var swiftSDK = swiftSDK
234+ swiftSDK. pathsConfiguration = configuration
235+ swiftSDK. targetTriple = targetTriple
236+ try configurationStore. updateConfiguration ( sdkID: sdkID, swiftSDK: swiftSDK)
237+
238+ observabilityScope. emit (
239+ info: """
240+ These properties of Swift SDK ` \( sdkID) ` for target triple \
241+ ` \( targetTriple) ` were successfully updated: \( updatedProperties. joined ( separator: " , " ) ) .
242+ """
243+ )
244+ }
245+
246+ if observabilityScope. errorsReported {
150247 throw ExitCode . failure
151248 }
249+ }
152250 } catch {
153251 commandError = error
154252 }
0 commit comments