Skip to content

Commit bff6681

Browse files
committed
swift-package-migrate: Call SwiftFixIt once for all diagnostic files
This excludes the possibility of repeated fix-it application caused by accidental emission of migration warnings in dependency modules. Also add a comment for why we exclude plugins from migration.
1 parent c607f7f commit bff6681

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

Sources/Commands/PackageCommands/Migrate.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ extension SwiftPackageCommand {
125125
where graph.isRootPackage(buildDescription.package)
126126
{
127127
let module = buildDescription.module
128+
// FIXME: Plugin target init does not have a Swift settings
129+
// parameter, so we won't be able to enable the feature.
130+
// Exclude plugins from migration.
128131
guard module.type != .plugin, !module.implicit else {
129132
continue
130133
}
@@ -139,15 +142,13 @@ extension SwiftPackageCommand {
139142

140143
var summary = SwiftFixIt.Summary(numberOfFixItsApplied: 0, numberOfFilesChanged: 0)
141144
let fixItDuration = try ContinuousClock().measure {
142-
for (_, diagnosticFiles) in modules {
143-
let fixit = try SwiftFixIt(
144-
diagnosticFiles: diagnosticFiles,
145-
categories: Set(features.flatMap(\.categories)),
146-
excludedSourceDirectories: [swiftCommandState.scratchDirectory],
147-
fileSystem: swiftCommandState.fileSystem
148-
)
149-
summary += try fixit.applyFixIts()
150-
}
145+
let applier = try SwiftFixIt(
146+
diagnosticFiles: modules.values.joined(),
147+
categories: Set(features.flatMap(\.categories)),
148+
excludedSourceDirectories: [swiftCommandState.scratchDirectory],
149+
fileSystem: swiftCommandState.fileSystem
150+
)
151+
summary = try applier.applyFixIts()
151152
}
152153

153154
// Report the changes.

Sources/SwiftFixIt/SwiftFixIt.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ package struct SwiftFixIt /*: ~Copyable */ { // TODO: Crashes with ~Copyable
211211
private let diagnosticsPerFile: DiagnosticsPerFile
212212

213213
package init(
214-
diagnosticFiles: [AbsolutePath],
214+
diagnosticFiles: some Collection<AbsolutePath>,
215215
categories: Set<String> = [],
216216
excludedSourceDirectories: Set<AbsolutePath> = [],
217217
fileSystem: any FileSystem

0 commit comments

Comments
 (0)