Skip to content

Commit d64bdd1

Browse files
committed
Fix plugin with custom task invocation using swiftbuild on windows
- need to add .exe prefix to .builtTool binary so swiftbuild/llbuild file inputs are correct. closes: #9189 rdar://161337478
1 parent deac56d commit d64bdd1

3 files changed

Lines changed: 24 additions & 24 deletions

File tree

Sources/SPMBuildCore/Plugins/PluginInvocation.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,8 @@ fileprivate func collectAccessibleTools(
697697
}
698698
// For an executable target we create a `builtTool`.
699699
else if executableOrBinaryModule.type == .executable {
700-
return try [.builtTool(name: builtToolName, path: RelativePath(validating: executableOrBinaryModule.name))]
700+
let exeName = executableOrBinaryModule.name + hostTriple.executableExtension
701+
return try [.builtTool(name: builtToolName, path: RelativePath(validating: exeName))]
701702
}
702703
else {
703704
return []

Tests/BuildTests/PluginInvocationTests.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ final class PluginInvocationTests: XCTestCase {
120120
buildPlanResult.checkTargetsCount(5) // Note: plugins are not included here.
121121

122122
buildPlanResult.check(destination: .target, for: "Foo")
123-
123+
124124
buildPlanResult.check(destination: .host, for: "FooTool")
125125
buildPlanResult.check(destination: .target, for: "FooTool")
126-
126+
127127
buildPlanResult.check(destination: .host, for: "FooToolLib")
128128
buildPlanResult.check(destination: .target, for: "FooToolLib")
129129
}
@@ -135,7 +135,7 @@ final class PluginInvocationTests: XCTestCase {
135135
return try UserToolchain.default.targetTriple
136136
}
137137
}
138-
138+
139139
func compilePluginScript(
140140
sourceFiles: [AbsolutePath],
141141
pluginName: String,
@@ -149,7 +149,7 @@ final class PluginInvocationTests: XCTestCase {
149149
completion(.failure(StringError("unimplemented")))
150150
}
151151
}
152-
152+
153153
func runPluginScript(
154154
sourceFiles: [AbsolutePath],
155155
pluginName: String,
@@ -173,7 +173,7 @@ final class PluginInvocationTests: XCTestCase {
173173
callbackQueue.sync {
174174
delegate.handleOutput(data: Data("Hello Plugin!".utf8))
175175
}
176-
176+
177177
// Pretend it emitted a warning.
178178
try callbackQueue.sync {
179179
let message = Data("""
@@ -262,7 +262,7 @@ final class PluginInvocationTests: XCTestCase {
262262
XCTAssertEqual(evalFirstCommand.configuration.arguments, ["-c", "/Foo/Sources/Foo/SomeFile.abc"])
263263
XCTAssertEqual(evalFirstCommand.configuration.environment, ["X": "Y"])
264264
XCTAssertEqual(evalFirstCommand.configuration.workingDirectory, AbsolutePath("/Foo/Sources/Foo"))
265-
XCTAssertEqual(evalFirstCommand.inputFiles, [builtToolsDir.appending("FooTool")])
265+
XCTAssertEqual(evalFirstCommand.inputFiles, [builtToolsDir.appending("FooTool" + ProcessInfo.exeSuffix)])
266266
XCTAssertEqual(evalFirstCommand.outputFiles, [])
267267

268268
XCTAssertEqual(evalFirstResult.diagnostics.count, 1)
@@ -273,7 +273,7 @@ final class PluginInvocationTests: XCTestCase {
273273

274274
XCTAssertEqual(evalFirstResult.textOutput, "Hello Plugin!")
275275
}
276-
276+
277277
func testCompilationDiagnostics() async throws {
278278
try await testWithTemporaryDirectory { tmpPath in
279279
// Create a sample package with a library target and a plugin.
@@ -298,13 +298,13 @@ final class PluginInvocationTests: XCTestCase {
298298
]
299299
)
300300
""")
301-
301+
302302
let myLibraryTargetDir = packageDir.appending(components: "Sources", "MyLibrary")
303303
try localFileSystem.createDirectory(myLibraryTargetDir, recursive: true)
304304
try localFileSystem.writeFileContents(myLibraryTargetDir.appending("library.swift"), string: """
305305
public func Foo() { }
306306
""")
307-
307+
308308
let myPluginTargetDir = packageDir.appending(components: "Plugins", "MyPlugin")
309309
try localFileSystem.createDirectory(myPluginTargetDir, recursive: true)
310310
try localFileSystem.writeFileContents(myPluginTargetDir.appending("plugin.swift"), string: """
@@ -327,7 +327,7 @@ final class PluginInvocationTests: XCTestCase {
327327
customManifestLoader: ManifestLoader(toolchain: UserToolchain.default),
328328
delegate: MockWorkspaceDelegate()
329329
)
330-
330+
331331
// Load the root manifest.
332332
let rootInput = PackageGraphRootInput(packages: [packageDir], dependencies: [])
333333
let rootManifests = try await workspace.loadRootManifests(
@@ -343,7 +343,7 @@ final class PluginInvocationTests: XCTestCase {
343343
)
344344
XCTAssertNoDiagnostics(observability.diagnostics)
345345
XCTAssert(packageGraph.packages.count == 1, "\(packageGraph.packages)")
346-
346+
347347
// Find the build tool plugin.
348348
let buildToolPlugin = try XCTUnwrap(packageGraph.packages.first?.modules.map(\.underlying).first{ $0.name == "MyPlugin" } as? PluginModule)
349349
XCTAssertEqual(buildToolPlugin.name, "MyPlugin")
@@ -356,10 +356,10 @@ final class PluginInvocationTests: XCTestCase {
356356
cacheDir: pluginCacheDir,
357357
toolchain: try UserToolchain.default
358358
)
359-
359+
360360
// Define a plugin compilation delegate that just captures the passed information.
361361
class Delegate: PluginScriptCompilerDelegate {
362-
var commandLine: [String]?
362+
var commandLine: [String]?
363363
var environment: Environment?
364364
var compiledResult: PluginCompilationResult?
365365
var cachedResult: PluginCompilationResult?
@@ -402,7 +402,7 @@ final class PluginInvocationTests: XCTestCase {
402402
XCTAssertNotNil(delegate.environment)
403403
XCTAssertEqual(delegate.compiledResult, result)
404404
XCTAssertNil(delegate.cachedResult)
405-
405+
406406
// Check the serialized diagnostics. We should have an error.
407407
let diaFileContents = try localFileSystem.readFileContents(result.diagnosticsFile)
408408
let diagnosticsSet = try SerializedDiagnostics(bytes: diaFileContents)
@@ -427,7 +427,7 @@ final class PluginInvocationTests: XCTestCase {
427427
}
428428
}
429429
""")
430-
430+
431431
// Try to compile the fixed plugin.
432432
let firstExecModTime: Date
433433
do {
@@ -566,7 +566,7 @@ final class PluginInvocationTests: XCTestCase {
566566
XCTAssertNotNil(delegate.environment)
567567
XCTAssertEqual(delegate.compiledResult, result)
568568
XCTAssertNil(delegate.cachedResult)
569-
569+
570570
// Check that the diagnostics no longer have a warning.
571571
let diaFileContents = try localFileSystem.readFileContents(result.diagnosticsFile)
572572
let diagnosticsSet = try SerializedDiagnostics(bytes: diaFileContents)
@@ -619,7 +619,7 @@ final class PluginInvocationTests: XCTestCase {
619619
XCTAssertNotNil(delegate.environment)
620620
XCTAssertEqual(delegate.compiledResult, result)
621621
XCTAssertNil(delegate.cachedResult)
622-
622+
623623
// Check the diagnostics. We should have a different error than the original one.
624624
let diaFileContents = try localFileSystem.readFileContents(result.diagnosticsFile)
625625
let diagnosticsSet = try SerializedDiagnostics(bytes: diaFileContents)
@@ -888,7 +888,7 @@ final class PluginInvocationTests: XCTestCase {
888888
}
889889
}
890890
""")
891-
891+
892892
let artifactVariants = [try UserToolchain.default.targetTriple].map {
893893
"""
894894
{ "path": "Y", "supportedTriples": ["\($0.tripleString)"] }
@@ -1116,7 +1116,7 @@ final class PluginInvocationTests: XCTestCase {
11161116

11171117
let diags = result.flatMap(\.value.results).flatMap(\.diagnostics)
11181118
testDiagnostics(diags) { result in
1119-
let msg = "a prebuild command cannot use executables built from source, including executable target 'Y'"
1119+
let msg = "a prebuild command cannot use executables built from source, including executable target '\("Y" + ProcessInfo.exeSuffix)'"
11201120
result.check(diagnostic: .contains(msg), severity: .error)
11211121
}
11221122
}
@@ -1235,7 +1235,7 @@ final class PluginInvocationTests: XCTestCase {
12351235
) throws -> [Command] { }
12361236
}
12371237
""")
1238-
1238+
12391239
// Create a valid swift interface file that can be detected via `canImport()`.
12401240
let fakeExtraModulesDir = tmpPath.appending("ExtraModules")
12411241
try localFileSystem.createDirectory(fakeExtraModulesDir, recursive: true)
@@ -1244,7 +1244,7 @@ final class PluginInvocationTests: XCTestCase {
12441244
// swift-interface-format-version: 1.0
12451245
// swift-module-flags: -module-name ModuleFoundViaExtraSearchPaths
12461246
""")
1247-
1247+
12481248
/////////
12491249
// Load a workspace from the package.
12501250
let observability = ObservabilitySystem.makeForTesting()
@@ -1581,5 +1581,5 @@ extension BuildPlanResult {
15811581
$0.module.name == target && $0.destination == destination
15821582
}
15831583
XCTAssertEqual(targets.count, 1, file: file, line: line)
1584-
}
1584+
}
15851585
}

Tests/FunctionalTests/PluginTests.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ struct PluginTests {
380380
@Test(
381381
.issue("https://github.com/swiftlang/swift-package-manager/issues/9215", relationship: .verifies),
382382
.requiresSwiftConcurrencySupport,
383-
.disabled("rdar://162053979"),
384383
arguments: [BuildSystemProvider.Kind.native, .swiftbuild]
385384
)
386385
func testUseOfVendedBinaryTool(buildSystem: BuildSystemProvider.Kind) async throws {

0 commit comments

Comments
 (0)