Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/SPMBuildCore/Plugins/PluginInvocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down
44 changes: 22 additions & 22 deletions Tests/BuildTests/PluginInvocationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -135,7 +135,7 @@ final class PluginInvocationTests: XCTestCase {
return try UserToolchain.default.targetTriple
}
}

func compilePluginScript(
sourceFiles: [AbsolutePath],
pluginName: String,
Expand All @@ -150,7 +150,7 @@ final class PluginInvocationTests: XCTestCase {
completion(.failure(StringError("unimplemented")))
}
}

func runPluginScript(
sourceFiles: [AbsolutePath],
pluginName: String,
Expand All @@ -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("""
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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: """
Expand All @@ -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(
Expand All @@ -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")
Expand All @@ -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?
Expand Down Expand Up @@ -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)
Expand All @@ -431,7 +431,7 @@ final class PluginInvocationTests: XCTestCase {
}
}
""")

// Try to compile the fixed plugin.
let firstExecModTime: Date
do {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -896,7 +896,7 @@ final class PluginInvocationTests: XCTestCase {
}
}
""")

let artifactVariants = [try UserToolchain.default.targetTriple].map {
"""
{ "path": "Y", "supportedTriples": ["\($0.tripleString)"] }
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -1589,5 +1589,5 @@ extension BuildPlanResult {
$0.module.name == target && $0.destination == destination
}
XCTAssertEqual(targets.count, 1, file: file, line: line)
}
}
}
1 change: 0 additions & 1 deletion Tests/FunctionalTests/PluginTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading