@@ -21,6 +21,11 @@ public import enum SWBProtocol.BuildAction
2121import Foundation
2222public import SWBMacro
2323
24+ #if canImport(Darwin) && canImport(os.log)
25+ // For Previews logging
26+ import os. log
27+ #endif
28+
2429/// The minimal data we need to serialize to reconstruct `SwiftSourceFileIndexingInfo` from `generateIndexingInfoForTask`
2530public struct SwiftIndexingPayload : Serializable , Sendable {
2631 // If `USE_SWIFT_RESPONSE_FILE` is enabled, we use `filePaths`, otherwise `range`.
@@ -3548,6 +3553,7 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
35483553 let overlay = try vfs. toVFSOverlay ( ) . propertyListItem. asJSONFragment ( ) . asString
35493554 try fs. write ( newVFSOverlayPath!, contents: ByteString ( encodingAsUTF8: overlay) )
35503555 } catch {
3556+ logErrorForPreviews ( " Failed to generate vfsoverlay for \( inputPath. basename) , error: \( error) " )
35513557 return [ ]
35523558 }
35533559 } else {
@@ -3628,11 +3634,10 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
36283634
36293635 // The driver may have emitted an error even if it returned us a command line. In this case, don't return the command line since it likely won't work.
36303636 if commandLine. isEmpty || outputDelegate. engine. hasErrors {
3631- #if canImport(os )
3637+ logErrorForPreviews ( " Swift driver failed to compute command line for preview info. " )
36323638 for diagnostic in outputDelegate. engine. diagnostics. filter ( { $0. behavior == . error } ) {
3633- OSLog . log ( " Swift driver preview info error: \( diagnostic. data. description) " )
3639+ logErrorForPreviews ( " Swift driver preview info error: \( diagnostic. data. description) " )
36343640 }
3635- #endif
36363641 return [ ]
36373642 }
36383643 }
@@ -3959,3 +3964,14 @@ extension SwiftDiscoveredCommandLineToolSpecInfo {
39593964 return try await discoveredSwiftCompilerInfo ( producer, delegate, at: toolPath, blocklistsPathOverride: userSpecifiedBlocklists)
39603965 }
39613966}
3967+
3968+ #if canImport(Darwin) && canImport(os.log)
3969+ let previewsLogger = Logger ( subsystem: " com.apple.dt.Previews " , category: " swift-build " )
3970+ #endif
3971+
3972+ private func logErrorForPreviews( _ message: @autoclosure ( ) -> String ) {
3973+ #if canImport(Darwin) && canImport(os.log)
3974+ let resolved = message ( )
3975+ previewsLogger. error ( " \( resolved, privacy: . private) " )
3976+ #endif
3977+ }
0 commit comments