@@ -41,20 +41,22 @@ struct SessionFailedError: Error {
4141 var diagnostics : [ SwiftBuild . SwiftBuildMessage . DiagnosticInfo ]
4242}
4343
44- func withService(
44+ func withService< T > (
4545 connectionMode: SWBBuildServiceConnectionMode = . default,
4646 variant: SWBBuildServiceVariant = . default,
4747 serviceBundleURL: URL ? = nil ,
48- body: @escaping ( _ service: SWBBuildService ) async throws -> Void
49- ) async throws {
48+ body: @escaping ( _ service: SWBBuildService ) async throws -> T
49+ ) async throws -> T {
5050 let service = try await SWBBuildService ( connectionMode: connectionMode, variant: variant, serviceBundleURL: serviceBundleURL)
51+ let result : T
5152 do {
52- try await body ( service)
53+ result = try await body ( service)
5354 } catch {
5455 await service. close ( )
5556 throw error
5657 }
5758 await service. close ( )
59+ return result
5860}
5961
6062public func createSession(
@@ -279,20 +281,20 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
279281 SwiftLanguageVersion . supportedSwiftLanguageVersions
280282 }
281283
282- public func build( subset: BuildSubset ) async throws {
284+ public func build( subset: BuildSubset ) async throws -> BuildResult {
283285 guard !buildParameters. shouldSkipBuilding else {
284- return
286+ return BuildResult ( serializedDiagnosticPathsByTargetName : . failure ( StringError ( " Building was skipped " ) ) )
285287 }
286288
287289 try await writePIF ( buildParameters: buildParameters)
288290
289- try await startSWBuildOperation ( pifTargetName: subset. pifTargetName)
291+ return try await startSWBuildOperation ( pifTargetName: subset. pifTargetName)
290292 }
291293
292- private func startSWBuildOperation( pifTargetName: String ) async throws {
294+ private func startSWBuildOperation( pifTargetName: String ) async throws -> BuildResult {
293295 let buildStartTime = ContinuousClock . Instant. now
294296
295- try await withService ( connectionMode: . inProcessStatic( swiftbuildServiceEntryPoint) ) { service in
297+ return try await withService ( connectionMode: . inProcessStatic( swiftbuildServiceEntryPoint) ) { service in
296298 let derivedDataPath = self . buildParameters. dataPath
297299
298300 let progressAnimation = ProgressAnimation . percent (
@@ -302,6 +304,7 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
302304 isColorized: self . buildParameters. outputParameters. isColorized
303305 )
304306
307+ var serializedDiagnosticPathsByTargetName : [ String : [ Basics . AbsolutePath ] ] = [ : ]
305308 do {
306309 try await withSession ( service: service, name: self . buildParameters. pifManifest. pathString, toolchainPath: self . buildParameters. toolchain. toolchainDir, packageManagerResourcesDirectory: self . packageManagerResourcesDirectory) { session, _ in
307310 self . outputStream. send ( " Building for \( self . buildParameters. configuration == . debug ? " debugging " : " production " ) ... \n " )
@@ -451,6 +454,11 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
451454 }
452455 let targetInfo = try buildState. target ( for: startedInfo)
453456 self . delegate? . buildSystem ( self , didFinishCommand: BuildSystemCommand ( startedInfo, targetInfo: targetInfo) )
457+ if let targetName = targetInfo? . targetName {
458+ serializedDiagnosticPathsByTargetName [ targetName, default: [ ] ] . append ( contentsOf: startedInfo. serializedDiagnosticsPaths. compactMap {
459+ try ? Basics . AbsolutePath ( validating: $0. pathString)
460+ } )
461+ }
454462 case . targetStarted( let info) :
455463 try buildState. started ( target: info)
456464 case . planningOperationStarted, . planningOperationCompleted, . reportBuildDescription, . reportPathMap, . preparedForIndex, . backtraceFrame, . buildStarted, . preparationComplete, . targetUpToDate, . targetComplete, . taskUpToDate:
@@ -503,6 +511,7 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
503511 } catch {
504512 throw error
505513 }
514+ return BuildResult ( serializedDiagnosticPathsByTargetName: . success( serializedDiagnosticPathsByTargetName) )
506515 }
507516 }
508517
0 commit comments