diff --git a/Fixtures/Miscellaneous/DoNotFilterLinkerDiagnostics/Package.swift b/Fixtures/Miscellaneous/DoNotFilterLinkerDiagnostics/Package.swift new file mode 100644 index 00000000000..326e3041c52 --- /dev/null +++ b/Fixtures/Miscellaneous/DoNotFilterLinkerDiagnostics/Package.swift @@ -0,0 +1,17 @@ +// swift-tools-version: 5.11 + +import PackageDescription + +let package = Package( + name: "DoNotFilterLinkerDiagnostics", + targets: [ + .executableTarget( + name: "DoNotFilterLinkerDiagnostics", + linkerSettings: [ + .linkedLibrary("z"), + .unsafeFlags(["-lz"]), + // should produce: ld: warning: ignoring duplicate libraries: '-lz' + ] + ), + ] +) diff --git a/Fixtures/Miscellaneous/DoNotFilterLinkerDiagnostics/Sources/DoNotFilterLinkerDiagnostics/main.swift b/Fixtures/Miscellaneous/DoNotFilterLinkerDiagnostics/Sources/DoNotFilterLinkerDiagnostics/main.swift new file mode 100644 index 00000000000..44e20d5acc4 --- /dev/null +++ b/Fixtures/Miscellaneous/DoNotFilterLinkerDiagnostics/Sources/DoNotFilterLinkerDiagnostics/main.swift @@ -0,0 +1,4 @@ +// The Swift Programming Language +// https://docs.swift.org/swift-book + +print("Hello, world!") diff --git a/Sources/Build/BuildOperationBuildSystemDelegateHandler.swift b/Sources/Build/BuildOperationBuildSystemDelegateHandler.swift index 1a41e0fe067..482235fe985 100644 --- a/Sources/Build/BuildOperationBuildSystemDelegateHandler.swift +++ b/Sources/Build/BuildOperationBuildSystemDelegateHandler.swift @@ -826,8 +826,10 @@ final class BuildOperationBuildSystemDelegateHandler: LLBuildBuildSystemDelegate process: ProcessHandle, result: CommandExtendedResult ) { + // FIXME: This should really happen at the command-level and is just a stopgap measure. + let shouldFilterOutput = !self.logLevel.isVerbose && command.verboseDescription.hasPrefix("codesign ") && result.result != .failed queue.async { - if let buffer = self.nonSwiftMessageBuffers[command.name] { + if let buffer = self.nonSwiftMessageBuffers[command.name], !shouldFilterOutput { self.progressAnimation.clear() self.outputStream.send(buffer) self.outputStream.flush() diff --git a/Tests/BuildTests/BuildSystemDelegateTests.swift b/Tests/BuildTests/BuildSystemDelegateTests.swift new file mode 100644 index 00000000000..88308460126 --- /dev/null +++ b/Tests/BuildTests/BuildSystemDelegateTests.swift @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift open source project +// +// Copyright (c) 2024 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See http://swift.org/LICENSE.txt for license information +// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +import SPMTestSupport +import XCTest + +import var TSCBasic.localFileSystem + +final class BuildSystemDelegateTests: XCTestCase { + func testDoNotFilterLinkerDiagnostics() throws { + try fixture(name: "Miscellaneous/DoNotFilterLinkerDiagnostics") { fixturePath in + #if !os(macOS) + // These linker diagnostics are only produced on macOS. + try XCTSkipIf(true, "test is only supported on macOS") + #endif + let (fullLog, _) = try executeSwiftBuild(fixturePath) + XCTAssertTrue(fullLog.contains("ld: warning: ignoring duplicate libraries: '-lz'"), "log didn't contain expected linker diagnostics") + } + } + + func testFilterNonFatalCodesignMessages() throws { + // Note: we can re-use the `TestableExe` fixture here since we just need an executable. + try fixture(name: "Miscellaneous/TestableExe") { fixturePath in + _ = try executeSwiftBuild(fixturePath) + let execPath = fixturePath.appending(components: ".build", "debug", "TestableExe1") + XCTAssertTrue(localFileSystem.exists(execPath), "executable not found at '\(execPath)'") + try localFileSystem.removeFileTree(execPath) + let (fullLog, _) = try executeSwiftBuild(fixturePath) + XCTAssertFalse(fullLog.contains("replacing existing signature"), "log contained non-fatal codesigning messages") + } + } +}