@@ -92,10 +92,12 @@ extension SwiftPackageCommand {
9292
9393 let targets = self . options. targets
9494
95+ let delegate = DiagnosticsCapturingBuildSystemDelegate ( )
9596 let buildSystem = try await createBuildSystem (
9697 swiftCommandState,
9798 targets: targets,
98- features: features
99+ features: features,
100+ delegate: delegate
99101 )
100102
101103 // Next, let's build all of the individual targets or the
@@ -110,42 +112,66 @@ extension SwiftPackageCommand {
110112 try await buildSystem. build ( subset: . allIncludingTests)
111113 }
112114
113- // Determine all of the targets we need up update.
114- let buildPlan = try buildSystem. buildPlan
115-
116- var modules : [ any ModuleBuildDescription ] = [ ]
117- if !targets. isEmpty {
118- for buildDescription in buildPlan. buildModules
119- where targets. contains ( buildDescription. module. name) {
120- modules. append ( buildDescription)
115+ var summary = SwiftFixIt . Summary ( numberOfFixItsApplied: 0 , numberOfFilesChanged: 0 )
116+ let fixItDuration : Duration
117+ let targetsToUpdateInManifest : [ String ]
118+ if buildSystem. supportsSerializedDaignosticsCollectionViaDelegate {
119+ let diagnosticPaths = delegate. serializedDiagnosticsPathsByTarget
120+ let graph = try await buildSystem. getPackageGraph ( )
121+ var targets = targets
122+ targetsToUpdateInManifest = targets. elements
123+ if targets. isEmpty {
124+ targets = OrderedSet ( graph. rootPackages. flatMap { $0. manifest. targets. map ( \. name) } )
125+ }
126+ print ( " > Applying fix-its " )
127+ fixItDuration = try ContinuousClock ( ) . measure {
128+ for target in targets {
129+ let fixit = try SwiftFixIt (
130+ diagnosticFiles: Array ( diagnosticPaths [ target] ?? [ ] ) ,
131+ categories: Set ( features. flatMap ( \. categories) ) ,
132+ fileSystem: swiftCommandState. fileSystem
133+ )
134+ summary += try fixit. applyFixIts ( )
135+ }
121136 }
122137 } else {
123- let graph = try await buildSystem. getPackageGraph ( )
124- for buildDescription in buildPlan. buildModules
125- where graph. isRootPackage ( buildDescription. package )
126- {
127- let module = buildDescription. module
128- guard module. type != . plugin, !module. implicit else {
129- continue
138+ // Determine all of the targets we need up update.
139+ let buildPlan = try buildSystem. buildPlan
140+
141+ var modules : [ any ModuleBuildDescription ] = [ ]
142+ if !targets. isEmpty {
143+ for buildDescription in buildPlan. buildModules
144+ where targets. contains ( buildDescription. module. name) {
145+ modules. append ( buildDescription)
146+ }
147+ } else {
148+ let graph = try await buildSystem. getPackageGraph ( )
149+ for buildDescription in buildPlan. buildModules
150+ where graph. isRootPackage ( buildDescription. package )
151+ {
152+ let module = buildDescription. module
153+ guard module. type != . plugin, !module. implicit else {
154+ continue
155+ }
156+ modules. append ( buildDescription)
130157 }
131- modules. append ( buildDescription)
132158 }
133- }
159+ targetsToUpdateInManifest = modules . map ( \ . module . name )
134160
135- // If the build suceeded, let's extract all of the diagnostic
136- // files from build plan and feed them to the fix-it tool.
161+ // If the build suceeded, let's extract all of the diagnostic
162+ // files from build plan and feed them to the fix-it tool.
137163
138- print ( " > Applying fix-its " )
164+ print ( " > Applying fix-its " )
139165
140- var summary = SwiftFixIt . Summary ( numberOfFixItsApplied : 0 , numberOfFilesChanged : 0 )
141- let fixItDuration = try ContinuousClock ( ) . measure {
142- for module in modules {
143- let fixit = try SwiftFixIt (
144- diagnosticFiles : module . diagnosticFiles ,
145- categories : Set ( features . flatMap ( \ . categories ) ) ,
146- fileSystem : swiftCommandState . fileSystem
147- )
148- summary += try fixit . applyFixIts ( )
166+ fixItDuration = try ContinuousClock ( ) . measure {
167+ for module in modules {
168+ let fixit = try SwiftFixIt (
169+ diagnosticFiles : module . diagnosticFiles ,
170+ categories : Set ( features . flatMap ( \ . categories ) ) ,
171+ fileSystem : swiftCommandState . fileSystem
172+ )
173+ summary += try fixit . applyFixIts ( )
174+ }
149175 }
150176 }
151177
@@ -176,10 +202,10 @@ extension SwiftPackageCommand {
176202 // manifest with newly adopted feature settings.
177203
178204 print ( " > Updating manifest " )
179- for module in modules . map ( \ . module ) {
180- swiftCommandState. observabilityScope. emit ( debug: " Adding feature(s) to ' \( module . name ) ' " )
205+ for target in targetsToUpdateInManifest {
206+ swiftCommandState. observabilityScope. emit ( debug: " Adding feature(s) to ' \( target ) ' " )
181207 try self . updateManifest (
182- for: module . name ,
208+ for: target ,
183209 add: features,
184210 using: swiftCommandState
185211 )
@@ -189,7 +215,8 @@ extension SwiftPackageCommand {
189215 private func createBuildSystem(
190216 _ swiftCommandState: SwiftCommandState ,
191217 targets: OrderedSet < String > ,
192- features: [ SwiftCompilerFeature ]
218+ features: [ SwiftCompilerFeature ] ,
219+ delegate: BuildSystemDelegate
193220 ) async throws -> BuildSystem {
194221 let toolsBuildParameters = try swiftCommandState. toolsBuildParameters
195222 let destinationBuildParameters = try swiftCommandState. productsBuildParameters
@@ -227,7 +254,8 @@ extension SwiftPackageCommand {
227254 modulesGraph
228255 } ,
229256 outputStream: TSCBasic . stdoutStream,
230- observabilityScope: swiftCommandState. observabilityScope
257+ observabilityScope: swiftCommandState. observabilityScope,
258+ delegate: delegate
231259 )
232260 }
233261
0 commit comments