Skip to content

Commit e930796

Browse files
authored
Filter codesign messages (#7285)
Right now we end up with this output on relink: ``` /Users/neonacho/Projects/public/swift-package-manager/.build/arm64-apple-macosx/debug/swift-bootstrap: replacing existing signature ``` This change specifically filters any output from `codesign` commands which haven't failed and we aren't in verbose mode. This should eventually be possible at the command level, but for the time being this allows us to avoid shipping SwiftPM with this messy output. rdar://118937939
1 parent d25b634 commit e930796

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// swift-tools-version: 5.11
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "DoNotFilterLinkerDiagnostics",
7+
targets: [
8+
.executableTarget(
9+
name: "DoNotFilterLinkerDiagnostics",
10+
linkerSettings: [
11+
.linkedLibrary("z"),
12+
.unsafeFlags(["-lz"]),
13+
// should produce: ld: warning: ignoring duplicate libraries: '-lz'
14+
]
15+
),
16+
]
17+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// The Swift Programming Language
2+
// https://docs.swift.org/swift-book
3+
4+
print("Hello, world!")

Sources/Build/BuildOperationBuildSystemDelegateHandler.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,10 @@ final class BuildOperationBuildSystemDelegateHandler: LLBuildBuildSystemDelegate
826826
process: ProcessHandle,
827827
result: CommandExtendedResult
828828
) {
829+
// FIXME: This should really happen at the command-level and is just a stopgap measure.
830+
let shouldFilterOutput = !self.logLevel.isVerbose && command.verboseDescription.hasPrefix("codesign ") && result.result != .failed
829831
queue.async {
830-
if let buffer = self.nonSwiftMessageBuffers[command.name] {
832+
if let buffer = self.nonSwiftMessageBuffers[command.name], !shouldFilterOutput {
831833
self.progressAnimation.clear()
832834
self.outputStream.send(buffer)
833835
self.outputStream.flush()
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import SPMTestSupport
14+
import XCTest
15+
16+
import var TSCBasic.localFileSystem
17+
18+
final class BuildSystemDelegateTests: XCTestCase {
19+
func testDoNotFilterLinkerDiagnostics() throws {
20+
try fixture(name: "Miscellaneous/DoNotFilterLinkerDiagnostics") { fixturePath in
21+
#if !os(macOS)
22+
// These linker diagnostics are only produced on macOS.
23+
try XCTSkipIf(true, "test is only supported on macOS")
24+
#endif
25+
let (fullLog, _) = try executeSwiftBuild(fixturePath)
26+
XCTAssertTrue(fullLog.contains("ld: warning: ignoring duplicate libraries: '-lz'"), "log didn't contain expected linker diagnostics")
27+
}
28+
}
29+
30+
func testFilterNonFatalCodesignMessages() throws {
31+
// Note: we can re-use the `TestableExe` fixture here since we just need an executable.
32+
try fixture(name: "Miscellaneous/TestableExe") { fixturePath in
33+
_ = try executeSwiftBuild(fixturePath)
34+
let execPath = fixturePath.appending(components: ".build", "debug", "TestableExe1")
35+
XCTAssertTrue(localFileSystem.exists(execPath), "executable not found at '\(execPath)'")
36+
try localFileSystem.removeFileTree(execPath)
37+
let (fullLog, _) = try executeSwiftBuild(fixturePath)
38+
XCTAssertFalse(fullLog.contains("replacing existing signature"), "log contained non-fatal codesigning messages")
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)