diff --git a/Sources/SPMBuildCore/Plugins/PluginInvocation.swift b/Sources/SPMBuildCore/Plugins/PluginInvocation.swift index 30b73883e84..8c31dcf1e89 100644 --- a/Sources/SPMBuildCore/Plugins/PluginInvocation.swift +++ b/Sources/SPMBuildCore/Plugins/PluginInvocation.swift @@ -705,7 +705,8 @@ fileprivate func collectAccessibleTools( } // For an executable target we create a `builtTool`. else if executableOrBinaryModule.type == .executable { - return try [.builtTool(name: builtToolName, path: RelativePath(validating: executableOrBinaryModule.name))] + let exeName = executableOrBinaryModule.name + hostTriple.executableExtension + return try [.builtTool(name: builtToolName, path: RelativePath(validating: exeName))] } else { return [] diff --git a/Tests/BuildTests/PluginInvocationTests.swift b/Tests/BuildTests/PluginInvocationTests.swift index 4d97913bc41..175c07c55e8 100644 --- a/Tests/BuildTests/PluginInvocationTests.swift +++ b/Tests/BuildTests/PluginInvocationTests.swift @@ -120,10 +120,10 @@ final class PluginInvocationTests: XCTestCase { buildPlanResult.checkTargetsCount(5) // Note: plugins are not included here. buildPlanResult.check(destination: .target, for: "Foo") - + buildPlanResult.check(destination: .host, for: "FooTool") buildPlanResult.check(destination: .target, for: "FooTool") - + buildPlanResult.check(destination: .host, for: "FooToolLib") buildPlanResult.check(destination: .target, for: "FooToolLib") } @@ -135,7 +135,7 @@ final class PluginInvocationTests: XCTestCase { return try UserToolchain.default.targetTriple } } - + func compilePluginScript( sourceFiles: [AbsolutePath], pluginName: String, @@ -150,7 +150,7 @@ final class PluginInvocationTests: XCTestCase { completion(.failure(StringError("unimplemented"))) } } - + func runPluginScript( sourceFiles: [AbsolutePath], pluginName: String, @@ -175,7 +175,7 @@ final class PluginInvocationTests: XCTestCase { callbackQueue.sync { delegate.handleOutput(data: Data("Hello Plugin!".utf8)) } - + // Pretend it emitted a warning. try callbackQueue.sync { let message = Data(""" @@ -264,7 +264,7 @@ final class PluginInvocationTests: XCTestCase { XCTAssertEqual(evalFirstCommand.configuration.arguments, ["-c", "/Foo/Sources/Foo/SomeFile.abc"]) XCTAssertEqual(evalFirstCommand.configuration.environment, ["X": "Y"]) XCTAssertEqual(evalFirstCommand.configuration.workingDirectory, AbsolutePath("/Foo/Sources/Foo")) - XCTAssertEqual(evalFirstCommand.inputFiles, [builtToolsDir.appending("FooTool")]) + XCTAssertEqual(evalFirstCommand.inputFiles, [builtToolsDir.appending("FooTool" + ProcessInfo.exeSuffix)]) XCTAssertEqual(evalFirstCommand.outputFiles, []) XCTAssertEqual(evalFirstResult.diagnostics.count, 1) @@ -275,7 +275,7 @@ final class PluginInvocationTests: XCTestCase { XCTAssertEqual(evalFirstResult.textOutput, "Hello Plugin!") } - + func testCompilationDiagnostics() async throws { try await testWithTemporaryDirectory { tmpPath in // Create a sample package with a library target and a plugin. @@ -300,13 +300,13 @@ final class PluginInvocationTests: XCTestCase { ] ) """) - + let myLibraryTargetDir = packageDir.appending(components: "Sources", "MyLibrary") try localFileSystem.createDirectory(myLibraryTargetDir, recursive: true) try localFileSystem.writeFileContents(myLibraryTargetDir.appending("library.swift"), string: """ public func Foo() { } """) - + let myPluginTargetDir = packageDir.appending(components: "Plugins", "MyPlugin") try localFileSystem.createDirectory(myPluginTargetDir, recursive: true) try localFileSystem.writeFileContents(myPluginTargetDir.appending("plugin.swift"), string: """ @@ -329,7 +329,7 @@ final class PluginInvocationTests: XCTestCase { customManifestLoader: ManifestLoader(toolchain: UserToolchain.default), delegate: MockWorkspaceDelegate() ) - + // Load the root manifest. let rootInput = PackageGraphRootInput(packages: [packageDir], dependencies: []) let rootManifests = try await workspace.loadRootManifests( @@ -345,7 +345,7 @@ final class PluginInvocationTests: XCTestCase { ) XCTAssertNoDiagnostics(observability.diagnostics) XCTAssert(packageGraph.packages.count == 1, "\(packageGraph.packages)") - + // Find the build tool plugin. let buildToolPlugin = try XCTUnwrap(packageGraph.packages.first?.modules.map(\.underlying).first{ $0.name == "MyPlugin" } as? PluginModule) XCTAssertEqual(buildToolPlugin.name, "MyPlugin") @@ -358,10 +358,10 @@ final class PluginInvocationTests: XCTestCase { cacheDir: pluginCacheDir, toolchain: try UserToolchain.default ) - + // Define a plugin compilation delegate that just captures the passed information. class Delegate: PluginScriptCompilerDelegate { - var commandLine: [String]? + var commandLine: [String]? var environment: Environment? var compiledResult: PluginCompilationResult? var cachedResult: PluginCompilationResult? @@ -406,7 +406,7 @@ final class PluginInvocationTests: XCTestCase { XCTAssertNotNil(delegate.environment) XCTAssertEqual(delegate.compiledResult, result) XCTAssertNil(delegate.cachedResult) - + // Check the serialized diagnostics. We should have an error. let diaFileContents = try localFileSystem.readFileContents(result.diagnosticsFile) let diagnosticsSet = try SerializedDiagnostics(bytes: diaFileContents) @@ -431,7 +431,7 @@ final class PluginInvocationTests: XCTestCase { } } """) - + // Try to compile the fixed plugin. let firstExecModTime: Date do { @@ -573,7 +573,7 @@ final class PluginInvocationTests: XCTestCase { XCTAssertNotNil(delegate.environment) XCTAssertEqual(delegate.compiledResult, result) XCTAssertNil(delegate.cachedResult) - + // Check that the diagnostics no longer have a warning. let diaFileContents = try localFileSystem.readFileContents(result.diagnosticsFile) let diagnosticsSet = try SerializedDiagnostics(bytes: diaFileContents) @@ -627,7 +627,7 @@ final class PluginInvocationTests: XCTestCase { XCTAssertNotNil(delegate.environment) XCTAssertEqual(delegate.compiledResult, result) XCTAssertNil(delegate.cachedResult) - + // Check the diagnostics. We should have a different error than the original one. let diaFileContents = try localFileSystem.readFileContents(result.diagnosticsFile) let diagnosticsSet = try SerializedDiagnostics(bytes: diaFileContents) @@ -896,7 +896,7 @@ final class PluginInvocationTests: XCTestCase { } } """) - + let artifactVariants = [try UserToolchain.default.targetTriple].map { """ { "path": "Y", "supportedTriples": ["\($0.tripleString)"] } @@ -1124,7 +1124,7 @@ final class PluginInvocationTests: XCTestCase { let diags = result.flatMap(\.value.results).flatMap(\.diagnostics) testDiagnostics(diags) { result in - let msg = "a prebuild command cannot use executables built from source, including executable target 'Y'" + let msg = "a prebuild command cannot use executables built from source, including executable target '\("Y" + ProcessInfo.exeSuffix)'" result.check(diagnostic: .contains(msg), severity: .error) } } @@ -1243,7 +1243,7 @@ final class PluginInvocationTests: XCTestCase { ) throws -> [Command] { } } """) - + // Create a valid swift interface file that can be detected via `canImport()`. let fakeExtraModulesDir = tmpPath.appending("ExtraModules") try localFileSystem.createDirectory(fakeExtraModulesDir, recursive: true) @@ -1252,7 +1252,7 @@ final class PluginInvocationTests: XCTestCase { // swift-interface-format-version: 1.0 // swift-module-flags: -module-name ModuleFoundViaExtraSearchPaths """) - + ///////// // Load a workspace from the package. let observability = ObservabilitySystem.makeForTesting() @@ -1589,5 +1589,5 @@ extension BuildPlanResult { $0.module.name == target && $0.destination == destination } XCTAssertEqual(targets.count, 1, file: file, line: line) - } + } } diff --git a/Tests/FunctionalTests/PluginTests.swift b/Tests/FunctionalTests/PluginTests.swift index 3ab39d798fd..3fe4a712535 100644 --- a/Tests/FunctionalTests/PluginTests.swift +++ b/Tests/FunctionalTests/PluginTests.swift @@ -380,7 +380,6 @@ struct PluginTests { @Test( .issue("https://github.com/swiftlang/swift-package-manager/issues/9215", relationship: .verifies), .requiresSwiftConcurrencySupport, - .disabled("rdar://162053979"), arguments: [BuildSystemProvider.Kind.native, .swiftbuild] ) func testUseOfVendedBinaryTool(buildSystem: BuildSystemProvider.Kind) async throws {