@@ -64,31 +64,8 @@ extension SwiftPackageCommand {
64
64
var options : MigrateOptions
65
65
66
66
public func run( _ swiftCommandState: SwiftCommandState ) async throws {
67
- let toolchain = try swiftCommandState. productsBuildParameters. toolchain
68
-
69
- let supportedFeatures = try Dictionary (
70
- uniqueKeysWithValues: toolchain. swiftCompilerSupportedFeatures
71
- . map { ( $0. name, $0) }
72
- )
73
-
74
- // First, let's validate that all of the features are supported
75
- // by the compiler and are migratable.
76
-
77
- var features : [ SwiftCompilerFeature ] = [ ]
78
- for name in self . options. features {
79
- guard let feature = supportedFeatures [ name] else {
80
- let migratableFeatures = supportedFeatures. map ( \. value) . filter ( \. migratable) . map ( \. name)
81
- throw ValidationError (
82
- " Unsupported feature: \( name) . Available features: \( migratableFeatures. joined ( separator: " , " ) ) "
83
- )
84
- }
85
-
86
- guard feature. migratable else {
87
- throw ValidationError ( " Feature ' \( name) ' is not migratable " )
88
- }
89
-
90
- features. append ( feature)
91
- }
67
+ // First, validate and resolve the requested feature names.
68
+ let features = try self . resolveRequestedFeatures ( swiftCommandState)
92
69
93
70
let buildSystem = try await createBuildSystem (
94
71
swiftCommandState,
@@ -188,6 +165,44 @@ extension SwiftPackageCommand {
188
165
}
189
166
}
190
167
168
+ /// Resolves the requested feature names.
169
+ private func resolveRequestedFeatures(
170
+ _ swiftCommandState: SwiftCommandState
171
+ ) throws -> [ SwiftCompilerFeature ] {
172
+ let toolchain = try swiftCommandState. productsBuildParameters. toolchain
173
+
174
+ // Query the compiler for supported features.
175
+ let supportedFeatures = try toolchain. swiftCompilerSupportedFeatures
176
+
177
+ var resolvedFeatures : [ SwiftCompilerFeature ] = [ ]
178
+
179
+ // Resolve the requested feature names, validating that they are
180
+ // supported by the compiler and migratable.
181
+ for name in self . options. features {
182
+ let feature = supportedFeatures. first { $0. name == name }
183
+
184
+ guard let feature else {
185
+ let migratableCommaSeparatedFeatures = supportedFeatures
186
+ . filter ( \. migratable)
187
+ . map ( \. name)
188
+ . sorted ( )
189
+ . joined ( separator: " , " )
190
+
191
+ throw ValidationError (
192
+ " Unsupported feature ' \( name) '. Available features: \( migratableCommaSeparatedFeatures) "
193
+ )
194
+ }
195
+
196
+ guard feature. migratable else {
197
+ throw ValidationError ( " Feature ' \( name) ' is not migratable " )
198
+ }
199
+
200
+ resolvedFeatures. append ( feature)
201
+ }
202
+
203
+ return resolvedFeatures
204
+ }
205
+
191
206
private func createBuildSystem(
192
207
_ swiftCommandState: SwiftCommandState ,
193
208
targets: OrderedSet < String > ,
0 commit comments