Skip to content

Commit 72fb717

Browse files
committed
Allow omitting the target triple for swift sdk configure
1 parent d6522b2 commit 72fb717

File tree

4 files changed

+49
-8
lines changed

4 files changed

+49
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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>] [--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]
1212
```
1313

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

Sources/PackageModel/SwiftSDKs/SwiftSDK.swift

Lines changed: 12 additions & 5 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,17 @@ 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 \
119+
currently installed.
120+
"""
121+
}
115122
case .swiftSDKBundleAlreadyInstalled(let bundleName):
116123
return """
117124
Swift SDK bundle with name `\(bundleName)` is already installed. Can't install a new bundle \

Sources/PackageModel/SwiftSDKs/SwiftSDKConfigurationStore.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,22 @@ public final class SwiftSDKConfigurationStore {
8585
try encoder.encode(path: configurationPath, fileSystem: fileSystem, properties)
8686
}
8787

88+
public func swiftSDKs(for id: String) throws -> [SwiftSDK] {
89+
for bundle in try self.swiftSDKBundleStore.allValidBundles {
90+
for (artifactID, variants) in bundle.artifacts {
91+
guard artifactID == id else {
92+
continue
93+
}
94+
95+
for variant in variants {
96+
return variant.swiftSDKs
97+
}
98+
}
99+
}
100+
101+
return []
102+
}
103+
88104
public func readConfiguration(
89105
sdkID: String,
90106
targetTriple: Triple

Sources/SwiftSDKCommand/ConfigureSwiftSDK.swift

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct ConfigureSwiftSDK: AsyncParsableCommand {
9090
var sdkID: String
9191

9292
@Argument(help: "The target triple of the Swift SDK to configure.")
93-
var targetTriple: String
93+
var targetTriple: String?
9494

9595
/// The file system used by default by this command.
9696
private var fileSystem: FileSystem { localFileSystem }
@@ -132,8 +132,24 @@ struct ConfigureSwiftSDK: AsyncParsableCommand {
132132
hostTimeTriple: triple,
133133
swiftSDKBundleStore: bundleStore
134134
)
135-
let targetTriple = try Triple(self.targetTriple)
136135

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 {
137153
guard let swiftSDK = try configurationStore.readConfiguration(
138154
sdkID: sdkID,
139155
targetTriple: targetTriple
@@ -216,6 +232,7 @@ struct ConfigureSwiftSDK: AsyncParsableCommand {
216232

217233
var swiftSDK = swiftSDK
218234
swiftSDK.pathsConfiguration = configuration
235+
swiftSDK.targetTriple = targetTriple
219236
try configurationStore.updateConfiguration(sdkID: sdkID, swiftSDK: swiftSDK)
220237

221238
observabilityScope.emit(
@@ -229,6 +246,7 @@ struct ConfigureSwiftSDK: AsyncParsableCommand {
229246
if observabilityScope.errorsReported {
230247
throw ExitCode.failure
231248
}
249+
}
232250
} catch {
233251
commandError = error
234252
}

0 commit comments

Comments
 (0)