swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.76k stars 1.35k forks source link

Plugin build diagnostics are badly formatted #8091

Open dabrahams opened 4 weeks ago

dabrahams commented 4 weeks ago

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

Description

They appear to be printing an Error's string representation

Expected behavior

A properly formatted diagnostic compatible with the Gnu coding standard for error message formatting.

Actual behavior

error: plugin compilation failed: <PluginCompilationResult(
    succeeded: false,
    commandLine: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -L /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/PluginAPI -lPackagePlugin -Xlinker -rpath -Xlinker /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/PluginAPI -target arm64-apple-macosx13.0 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -L /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -g -swift-version 6 -package-description-version 6.0.0 -I /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/PluginAPI -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -parse-as-library -Xfrontend -serialize-diagnostics-path -Xfrontend /Users/dave/src/citron/.build/plugins/cache/CitronParserGenerator.dia /Users/dave/src/citron/Plugins/CitronParserGenerator/CitronParserGenerator.swift -o /Users/dave/src/citron/.build/plugins/cache/CitronParserGenerator,
    executable: /Users/dave/src/citron/.build/plugins/cache/CitronParserGenerator
    diagnostics: /Users/dave/src/citron/.build/plugins/cache/CitronParserGenerator.dia
    compilerOutput: '/Users/dave/src/citron/Plugins/CitronParserGenerator/CitronParserGenerator.swift:8:83: error: value of type '\''URL'\'' has no member '\''extension'\''
 6 |   func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] {
 7 |     guard let target = target as? SourceModuleTarget else { return [] }
 8 |     let inputFiles = target.sourceFiles.filter({ [ "citron", "y"].contains($0.url.extension) })
   |                                                                                   `- error: value of type '\''URL'\'' has no member '\''extension'\''
 9 |     return try inputFiles.map {
10 |       let inputFile = $0
'
)>

Steps to reproduce

Checkout the spm-bad-diagnostic-reproducer tag from https://github.com/dabrahams/citron and do swift test

Swift Package Manager version/commit hash

Whatever ships with Swift 6

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2) Target: arm64-apple-macosx15.0 Darwin DaveA-MBP14-5.localdomain 24.0.0 Darwin Kernel Version 24.0.0: Tue Sep 24 23:39:07 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6000 arm64