From 3ce3894737b308040e5303d33323c427015afd98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Boris=20B=C3=BCgling?= Date: Tue, 2 Jan 2024 09:37:25 -0800 Subject: [PATCH] Add `subsetDescriptor` to completion message (#7208) If we build just a specific product or target, add a `subsetDescriptor` to the complete message. This improves the confusing output when plugins are using executables, because we end up with multiple 'Build complete' messages. --- .../Tests/IntegrationTests/BasicTests.swift | 2 +- Sources/Build/BuildOperation.swift | 16 +++++++++++++++- ...ldOperationBuildSystemDelegateHandler.swift | 11 +++++++++-- Tests/CommandsTests/PackageToolTests.swift | 8 ++++---- Tests/FunctionalTests/PluginTests.swift | 18 +++++++++--------- 5 files changed, 38 insertions(+), 17 deletions(-) diff --git a/IntegrationTests/Tests/IntegrationTests/BasicTests.swift b/IntegrationTests/Tests/IntegrationTests/BasicTests.swift index 67b71358078..8cd4ddab56f 100644 --- a/IntegrationTests/Tests/IntegrationTests/BasicTests.swift +++ b/IntegrationTests/Tests/IntegrationTests/BasicTests.swift @@ -249,7 +249,7 @@ final class BasicTests: XCTestCase { XCTAssertContents(runError) { checker in checker.check(.regex("Compiling .*secho.*")) checker.check(.regex("Linking .*secho")) - checker.check(.contains("Build complete")) + checker.check(.contains("Build of product 'secho' complete")) } XCTAssertEqual(runOutput, "1 \"two\"\n") } diff --git a/Sources/Build/BuildOperation.swift b/Sources/Build/BuildOperation.swift index 6370ab2cc0a..fb0c33a9b7e 100644 --- a/Sources/Build/BuildOperation.swift +++ b/Sources/Build/BuildOperation.swift @@ -286,7 +286,21 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS let duration = buildStartTime.distance(to: .now()) - self.buildSystemDelegate?.buildComplete(success: success, duration: duration) + let subsetDescriptor: String? + switch subset { + case .product(let productName): + subsetDescriptor = "product '\(productName)'" + case .target(let targetName): + subsetDescriptor = "target: '\(targetName)'" + case .allExcludingTests, .allIncludingTests: + subsetDescriptor = nil + } + + self.buildSystemDelegate?.buildComplete( + success: success, + duration: duration, + subsetDescriptor: subsetDescriptor + ) self.delegate?.buildSystem(self, didFinishWithResult: success) guard success else { throw Diagnostics.fatalError } diff --git a/Sources/Build/BuildOperationBuildSystemDelegateHandler.swift b/Sources/Build/BuildOperationBuildSystemDelegateHandler.swift index 5832af110db..aebc43273da 100644 --- a/Sources/Build/BuildOperationBuildSystemDelegateHandler.swift +++ b/Sources/Build/BuildOperationBuildSystemDelegateHandler.swift @@ -956,11 +956,18 @@ final class BuildOperationBuildSystemDelegateHandler: LLBuildBuildSystemDelegate } } - func buildComplete(success: Bool, duration: DispatchTimeInterval) { + func buildComplete(success: Bool, duration: DispatchTimeInterval, subsetDescriptor: String? = nil) { + let subsetString: String + if let subsetDescriptor { + subsetString = "of \(subsetDescriptor) " + } else { + subsetString = "" + } + queue.sync { self.progressAnimation.complete(success: success) if success { - let message = cancelled ? "Build cancelled!" : "Build complete!" + let message = cancelled ? "Build \(subsetString)cancelled!" : "Build \(subsetString)complete!" self.progressAnimation.clear() self.outputStream.send("\(message) (\(duration.descriptionInSeconds))\n") self.outputStream.flush() diff --git a/Tests/CommandsTests/PackageToolTests.swift b/Tests/CommandsTests/PackageToolTests.swift index f3cf54bcb93..fef2d61fb5f 100644 --- a/Tests/CommandsTests/PackageToolTests.swift +++ b/Tests/CommandsTests/PackageToolTests.swift @@ -2398,7 +2398,7 @@ final class PackageToolTests: CommandsTestCase { XCTAssertNoMatch(stdout, .contains("Building for production...")) XCTAssertMatch(stdout, .contains("-module-name MyExecutable")) XCTAssertMatch(stdout, .contains("-DEXTRA_SWIFT_FLAG")) - XCTAssertMatch(stdout, .contains("Build complete!")) + XCTAssertMatch(stdout, .contains("Build of product 'MyExecutable' complete!")) XCTAssertMatch(stdout, .contains("succeeded: true")) XCTAssertMatch(stdout, .and(.contains("artifact-path:"), .contains("debug/MyExecutable"))) XCTAssertMatch(stdout, .and(.contains("artifact-kind:"), .contains("executable"))) @@ -2410,7 +2410,7 @@ final class PackageToolTests: CommandsTestCase { XCTAssertMatch(stdout, .contains("Building for production...")) XCTAssertNoMatch(stdout, .contains("Building for debug...")) XCTAssertNoMatch(stdout, .contains("-module-name MyExecutable")) - XCTAssertMatch(stdout, .contains("Build complete!")) + XCTAssertMatch(stdout, .contains("Build of product 'MyExecutable' complete!")) XCTAssertMatch(stdout, .contains("succeeded: true")) XCTAssertMatch(stdout, .and(.contains("artifact-path:"), .contains("release/MyExecutable"))) XCTAssertMatch(stdout, .and(.contains("artifact-kind:"), .contains("executable"))) @@ -2422,7 +2422,7 @@ final class PackageToolTests: CommandsTestCase { XCTAssertMatch(stdout, .contains("Building for production...")) XCTAssertNoMatch(stdout, .contains("Building for debug...")) XCTAssertNoMatch(stdout, .contains("-module-name MyLibrary")) - XCTAssertMatch(stdout, .contains("Build complete!")) + XCTAssertMatch(stdout, .contains("Build of product 'MyStaticLibrary' complete!")) XCTAssertMatch(stdout, .contains("succeeded: true")) XCTAssertMatch(stdout, .and(.contains("artifact-path:"), .contains("release/libMyStaticLibrary."))) XCTAssertMatch(stdout, .and(.contains("artifact-kind:"), .contains("staticLibrary"))) @@ -2434,7 +2434,7 @@ final class PackageToolTests: CommandsTestCase { XCTAssertMatch(stdout, .contains("Building for production...")) XCTAssertNoMatch(stdout, .contains("Building for debug...")) XCTAssertNoMatch(stdout, .contains("-module-name MyLibrary")) - XCTAssertMatch(stdout, .contains("Build complete!")) + XCTAssertMatch(stdout, .contains("Build of product 'MyDynamicLibrary' complete!")) XCTAssertMatch(stdout, .contains("succeeded: true")) XCTAssertMatch(stdout, .and(.contains("artifact-path:"), .contains("release/libMyDynamicLibrary."))) XCTAssertMatch(stdout, .and(.contains("artifact-kind:"), .contains("dynamicLibrary"))) diff --git a/Tests/FunctionalTests/PluginTests.swift b/Tests/FunctionalTests/PluginTests.swift index bf62d553e71..7b475458bb6 100644 --- a/Tests/FunctionalTests/PluginTests.swift +++ b/Tests/FunctionalTests/PluginTests.swift @@ -30,7 +30,7 @@ class PluginTests: XCTestCase { XCTAssert(stdout.contains("Linking MySourceGenBuildTool"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Generating foo.swift from foo.dat"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") - XCTAssert(stdout.contains("Build complete!"), "stdout:\n\(stdout)") + XCTAssert(stdout.contains("Build of product 'MyLocalTool' complete!"), "stdout:\n\(stdout)") } } @@ -43,7 +43,7 @@ class PluginTests: XCTestCase { XCTAssert(stdout.contains("Linking MySourceGenBuildTool"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Generating foo.swift from foo.dat"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Linking MyTool"), "stdout:\n\(stdout)") - XCTAssert(stdout.contains("Build complete!"), "stdout:\n\(stdout)") + XCTAssert(stdout.contains("Build of product 'MyTool' complete!"), "stdout:\n\(stdout)") } } @@ -56,7 +56,7 @@ class PluginTests: XCTestCase { XCTAssert(stdout.contains("Compiling MyOtherLocalTool bar.swift"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Compiling MyOtherLocalTool baz.swift"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Linking MyOtherLocalTool"), "stdout:\n\(stdout)") - XCTAssert(stdout.contains("Build complete!"), "stdout:\n\(stdout)") + XCTAssert(stdout.contains("Build of product 'MyOtherLocalTool' complete!"), "stdout:\n\(stdout)") } } @@ -125,7 +125,7 @@ class PluginTests: XCTestCase { XCTAssert(stdout.contains("Linking MySourceGenBuildTool"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Generating foo.swift from foo.dat"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") - XCTAssert(stdout.contains("Build complete!"), "stdout:\n\(stdout)") + XCTAssert(stdout.contains("Build of product 'MyLocalTool' complete!"), "stdout:\n\(stdout)") } } @@ -138,7 +138,7 @@ class PluginTests: XCTestCase { try fixture(name: "Miscellaneous/Plugins") { fixturePath in let (stdout, _) = try executeSwiftBuild(fixturePath.appending("SandboxTesterPlugin"), configuration: .Debug, extraArgs: ["--product", "MyLocalTool"]) XCTAssert(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") - XCTAssert(stdout.contains("Build complete!"), "stdout:\n\(stdout)") + XCTAssert(stdout.contains("Build of product 'MyLocalTool' complete!"), "stdout:\n\(stdout)") } } @@ -151,7 +151,7 @@ class PluginTests: XCTestCase { try fixture(name: "Miscellaneous/Plugins") { fixturePath in let (stdout, _) = try executeSwiftBuild(fixturePath.appending("MyBinaryToolPlugin"), configuration: .Debug, extraArgs: ["--product", "MyLocalTool"]) XCTAssert(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") - XCTAssert(stdout.contains("Build complete!"), "stdout:\n\(stdout)") + XCTAssert(stdout.contains("Build of product 'MyLocalTool' complete!"), "stdout:\n\(stdout)") } } @@ -164,7 +164,7 @@ class PluginTests: XCTestCase { try fixture(name: "Miscellaneous/Plugins") { fixturePath in let (stdout, _) = try executeSwiftBuild(fixturePath.appending("BinaryToolProductPlugin"), configuration: .Debug, extraArgs: ["--product", "MyLocalTool"]) XCTAssert(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") - XCTAssert(stdout.contains("Build complete!"), "stdout:\n\(stdout)") + XCTAssert(stdout.contains("Build of product 'MyLocalTool' complete!"), "stdout:\n\(stdout)") } } @@ -525,7 +525,7 @@ class PluginTests: XCTestCase { XCTAssert(stderr.contains("Linking RemoteTool"), "stdout:\n\(stderr)\n\(stdout)") XCTAssert(stderr.contains("Linking LocalTool"), "stdout:\n\(stderr)\n\(stdout)") XCTAssert(stderr.contains("Linking ImpliedLocalTool"), "stdout:\n\(stderr)\n\(stdout)") - XCTAssert(stderr.contains("Build complete!"), "stdout:\n\(stderr)\n\(stdout)") + XCTAssert(stderr.contains("Build of product 'ImpliedLocalTool' complete!"), "stdout:\n\(stderr)\n\(stdout)") XCTAssert(stdout.contains("A message from the remote tool."), "stdout:\n\(stderr)\n\(stdout)") XCTAssert(stdout.contains("A message from the local tool."), "stdout:\n\(stderr)\n\(stdout)") XCTAssert(stdout.contains("A message from the implied local tool."), "stdout:\n\(stderr)\n\(stdout)") @@ -1065,7 +1065,7 @@ class PluginTests: XCTestCase { XCTAssert(stdout.contains("Linking MySourceGenBuildTool"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Creating foo.swift from foo.dat"), "stdout:\n\(stdout)") XCTAssert(stdout.contains("Linking MyLocalTool"), "stdout:\n\(stdout)") - XCTAssert(stdout.contains("Build complete!"), "stdout:\n\(stdout)") + XCTAssert(stdout.contains("Build of product 'MyLocalTool' complete!"), "stdout:\n\(stdout)") } }