Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public import enum SWBProtocol.BuildAction
import Foundation
public import SWBMacro

#if canImport(Darwin) && canImport(os.log)
// For Previews logging
import os.log
#endif

/// The minimal data we need to serialize to reconstruct `SwiftSourceFileIndexingInfo` from `generateIndexingInfoForTask`
public struct SwiftIndexingPayload: Serializable, Sendable {
// If `USE_SWIFT_RESPONSE_FILE` is enabled, we use `filePaths`, otherwise `range`.
Expand Down Expand Up @@ -3548,6 +3553,7 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
let overlay = try vfs.toVFSOverlay().propertyListItem.asJSONFragment().asString
try fs.write(newVFSOverlayPath!, contents: ByteString(encodingAsUTF8: overlay))
} catch {
logErrorForPreviews("Failed to generate vfsoverlay for \(inputPath.basename), error: \(error)")
return []
}
} else {
Expand Down Expand Up @@ -3628,11 +3634,10 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi

// 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.
if commandLine.isEmpty || outputDelegate.engine.hasErrors {
#if canImport(os)
logErrorForPreviews("Swift driver failed to compute command line for preview info.")
for diagnostic in outputDelegate.engine.diagnostics.filter({ $0.behavior == .error }) {
OSLog.log("Swift driver preview info error: \(diagnostic.data.description)")
logErrorForPreviews("Swift driver preview info error: \(diagnostic.data.description)")
}
#endif
return []
}
}
Expand Down Expand Up @@ -3959,3 +3964,14 @@ extension SwiftDiscoveredCommandLineToolSpecInfo {
return try await discoveredSwiftCompilerInfo(producer, delegate, at: toolPath, blocklistsPathOverride: userSpecifiedBlocklists)
}
}

#if canImport(Darwin) && canImport(os.log)
let previewsLogger = Logger(subsystem: "com.apple.dt.Previews", category: "swift-build")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about subsystem=org.swiftlang.swift-build, category=preview-info?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to match the existing subsystem that is used by our public logging profile to selectively un-redact when we need deeper diagnostics.

#endif

private func logErrorForPreviews(_ message: @autoclosure () -> String) {
#if canImport(Darwin) && canImport(os.log)
let resolved = message()
previewsLogger.error("\(resolved, privacy: .private)")
#endif
}
Loading