@@ -64,31 +64,8 @@ extension SwiftPackageCommand {
6464 var options : MigrateOptions
6565
6666 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)
9269
9370 let targets = self . options. targets
9471
@@ -188,6 +165,44 @@ extension SwiftPackageCommand {
188165 }
189166 }
190167
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+
191206 private func createBuildSystem(
192207 _ swiftCommandState: SwiftCommandState ,
193208 targets: OrderedSet < String > ,
0 commit comments