Skip to content

Commit 43aa87a

Browse files
authored
[Commands] Migrate: Group manifest update errors per target (#8677)
### Motivation: If migrate fails to insert one or more features into the manifest for a target, let's produce a single error that lists all of the features, this makes the logging less noisy. ### Modifications: - Update `SwiftPackageCommand` to request manifest to all of the features related to a target and produce a single error if that fails. ### Result: If manifest has some non-standard ways of defining targets or settings that cannot be updated by `AddSettting`, migration logging is going to be more organized and less noisy.
1 parent 955d36a commit 43aa87a

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

Sources/Commands/PackageCommands/Migrate.swift

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,12 @@ extension SwiftPackageCommand {
137137

138138
print("> Updating manifest.")
139139
for module in modules.map(\.module) {
140-
print("> Adding feature(s) to '\(module.name)'.")
141-
for feature in features {
142-
self.updateManifest(
143-
for: module.name,
144-
add: feature,
145-
using: swiftCommandState
146-
)
147-
}
140+
swiftCommandState.observabilityScope.emit(debug: "Adding feature(s) to '\(module.name)'.")
141+
self.updateManifest(
142+
for: module.name,
143+
add: features,
144+
using: swiftCommandState
145+
)
148146
}
149147
}
150148

@@ -179,28 +177,28 @@ extension SwiftPackageCommand {
179177

180178
private func updateManifest(
181179
for target: String,
182-
add feature: SwiftCompilerFeature,
180+
add features: [SwiftCompilerFeature],
183181
using swiftCommandState: SwiftCommandState
184182
) {
185183
typealias SwiftSetting = SwiftPackageCommand.AddSetting.SwiftSetting
186184

187-
let setting: (SwiftSetting, String) = switch feature {
188-
case .upcoming(name: let name, migratable: _, enabledIn: _):
189-
(.upcomingFeature, "\(name)")
190-
case .experimental(name: let name, migratable: _):
191-
(.experimentalFeature, "\(name)")
185+
let settings: [(SwiftSetting, String)] = features.map {
186+
switch $0 {
187+
case .upcoming(name: let name, migratable: _, enabledIn: _):
188+
(.upcomingFeature, "\(name)")
189+
case .experimental(name: let name, migratable: _):
190+
(.experimentalFeature, "\(name)")
191+
}
192192
}
193193

194194
do {
195195
try SwiftPackageCommand.AddSetting.editSwiftSettings(
196196
of: target,
197197
using: swiftCommandState,
198-
[setting]
198+
settings
199199
)
200200
} catch {
201-
print(
202-
"! Couldn't update manifest due to - \(error); Please add '.enable\(feature.upcoming ? "Upcoming" : "Experimental")Feature(\"\(feature.name)\")' to target '\(target)' settings manually."
203-
)
201+
swiftCommandState.observabilityScope.emit(error: "Could not update manifest for '\(target)' (\(error)). Please enable '\(features.map(\.name).joined(separator: ", "))' features manually.")
204202
}
205203
}
206204

0 commit comments

Comments
 (0)