Skip to content

Commit b083659

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

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
@@ -705,7 +705,8 @@ fileprivate func collectAccessibleTools(
705705
}
706706
// For an executable target we create a `builtTool`.
707707
else if executableOrBinaryModule.type == .executable {
708-
return try [.builtTool(name: builtToolName, path: RelativePath(validating: executableOrBinaryModule.name))]
708+
let exeName = executableOrBinaryModule.name + hostTriple.executableExtension
709+
return try [.builtTool(name: builtToolName, path: RelativePath(validating: exeName))]
709710
}
710711
else {
711712
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,
@@ -150,7 +150,7 @@ final class PluginInvocationTests: XCTestCase {
150150
completion(.failure(StringError("unimplemented")))
151151
}
152152
}
153-
153+
154154
func runPluginScript(
155155
sourceFiles: [AbsolutePath],
156156
pluginName: String,
@@ -175,7 +175,7 @@ final class PluginInvocationTests: XCTestCase {
175175
callbackQueue.sync {
176176
delegate.handleOutput(data: Data("Hello Plugin!".utf8))
177177
}
178-
178+
179179
// Pretend it emitted a warning.
180180
try callbackQueue.sync {
181181
let message = Data("""
@@ -264,7 +264,7 @@ final class PluginInvocationTests: XCTestCase {
264264
XCTAssertEqual(evalFirstCommand.configuration.arguments, ["-c", "/Foo/Sources/Foo/SomeFile.abc"])
265265
XCTAssertEqual(evalFirstCommand.configuration.environment, ["X": "Y"])
266266
XCTAssertEqual(evalFirstCommand.configuration.workingDirectory, AbsolutePath("/Foo/Sources/Foo"))
267-
XCTAssertEqual(evalFirstCommand.inputFiles, [builtToolsDir.appending("FooTool")])
267+
XCTAssertEqual(evalFirstCommand.inputFiles, [builtToolsDir.appending("FooTool" + ProcessInfo.exeSuffix)])
268268
XCTAssertEqual(evalFirstCommand.outputFiles, [])
269269

270270
XCTAssertEqual(evalFirstResult.diagnostics.count, 1)
@@ -275,7 +275,7 @@ final class PluginInvocationTests: XCTestCase {
275275

276276
XCTAssertEqual(evalFirstResult.textOutput, "Hello Plugin!")
277277
}
278-
278+
279279
func testCompilationDiagnostics() async throws {
280280
try await testWithTemporaryDirectory { tmpPath in
281281
// Create a sample package with a library target and a plugin.
@@ -300,13 +300,13 @@ final class PluginInvocationTests: XCTestCase {
300300
]
301301
)
302302
""")
303-
303+
304304
let myLibraryTargetDir = packageDir.appending(components: "Sources", "MyLibrary")
305305
try localFileSystem.createDirectory(myLibraryTargetDir, recursive: true)
306306
try localFileSystem.writeFileContents(myLibraryTargetDir.appending("library.swift"), string: """
307307
public func Foo() { }
308308
""")
309-
309+
310310
let myPluginTargetDir = packageDir.appending(components: "Plugins", "MyPlugin")
311311
try localFileSystem.createDirectory(myPluginTargetDir, recursive: true)
312312
try localFileSystem.writeFileContents(myPluginTargetDir.appending("plugin.swift"), string: """
@@ -329,7 +329,7 @@ final class PluginInvocationTests: XCTestCase {
329329
customManifestLoader: ManifestLoader(toolchain: UserToolchain.default),
330330
delegate: MockWorkspaceDelegate()
331331
)
332-
332+
333333
// Load the root manifest.
334334
let rootInput = PackageGraphRootInput(packages: [packageDir], dependencies: [])
335335
let rootManifests = try await workspace.loadRootManifests(
@@ -345,7 +345,7 @@ final class PluginInvocationTests: XCTestCase {
345345
)
346346
XCTAssertNoDiagnostics(observability.diagnostics)
347347
XCTAssert(packageGraph.packages.count == 1, "\(packageGraph.packages)")
348-
348+
349349
// Find the build tool plugin.
350350
let buildToolPlugin = try XCTUnwrap(packageGraph.packages.first?.modules.map(\.underlying).first{ $0.name == "MyPlugin" } as? PluginModule)
351351
XCTAssertEqual(buildToolPlugin.name, "MyPlugin")
@@ -358,10 +358,10 @@ final class PluginInvocationTests: XCTestCase {
358358
cacheDir: pluginCacheDir,
359359
toolchain: try UserToolchain.default
360360
)
361-
361+
362362
// Define a plugin compilation delegate that just captures the passed information.
363363
class Delegate: PluginScriptCompilerDelegate {
364-
var commandLine: [String]?
364+
var commandLine: [String]?
365365
var environment: Environment?
366366
var compiledResult: PluginCompilationResult?
367367
var cachedResult: PluginCompilationResult?
@@ -406,7 +406,7 @@ final class PluginInvocationTests: XCTestCase {
406406
XCTAssertNotNil(delegate.environment)
407407
XCTAssertEqual(delegate.compiledResult, result)
408408
XCTAssertNil(delegate.cachedResult)
409-
409+
410410
// Check the serialized diagnostics. We should have an error.
411411
let diaFileContents = try localFileSystem.readFileContents(result.diagnosticsFile)
412412
let diagnosticsSet = try SerializedDiagnostics(bytes: diaFileContents)
@@ -431,7 +431,7 @@ final class PluginInvocationTests: XCTestCase {
431431
}
432432
}
433433
""")
434-
434+
435435
// Try to compile the fixed plugin.
436436
let firstExecModTime: Date
437437
do {
@@ -573,7 +573,7 @@ final class PluginInvocationTests: XCTestCase {
573573
XCTAssertNotNil(delegate.environment)
574574
XCTAssertEqual(delegate.compiledResult, result)
575575
XCTAssertNil(delegate.cachedResult)
576-
576+
577577
// Check that the diagnostics no longer have a warning.
578578
let diaFileContents = try localFileSystem.readFileContents(result.diagnosticsFile)
579579
let diagnosticsSet = try SerializedDiagnostics(bytes: diaFileContents)
@@ -627,7 +627,7 @@ final class PluginInvocationTests: XCTestCase {
627627
XCTAssertNotNil(delegate.environment)
628628
XCTAssertEqual(delegate.compiledResult, result)
629629
XCTAssertNil(delegate.cachedResult)
630-
630+
631631
// Check the diagnostics. We should have a different error than the original one.
632632
let diaFileContents = try localFileSystem.readFileContents(result.diagnosticsFile)
633633
let diagnosticsSet = try SerializedDiagnostics(bytes: diaFileContents)
@@ -896,7 +896,7 @@ final class PluginInvocationTests: XCTestCase {
896896
}
897897
}
898898
""")
899-
899+
900900
let artifactVariants = [try UserToolchain.default.targetTriple].map {
901901
"""
902902
{ "path": "Y", "supportedTriples": ["\($0.tripleString)"] }
@@ -1124,7 +1124,7 @@ final class PluginInvocationTests: XCTestCase {
11241124

11251125
let diags = result.flatMap(\.value.results).flatMap(\.diagnostics)
11261126
testDiagnostics(diags) { result in
1127-
let msg = "a prebuild command cannot use executables built from source, including executable target 'Y'"
1127+
let msg = "a prebuild command cannot use executables built from source, including executable target '\("Y" + ProcessInfo.exeSuffix)'"
11281128
result.check(diagnostic: .contains(msg), severity: .error)
11291129
}
11301130
}
@@ -1243,7 +1243,7 @@ final class PluginInvocationTests: XCTestCase {
12431243
) throws -> [Command] { }
12441244
}
12451245
""")
1246-
1246+
12471247
// Create a valid swift interface file that can be detected via `canImport()`.
12481248
let fakeExtraModulesDir = tmpPath.appending("ExtraModules")
12491249
try localFileSystem.createDirectory(fakeExtraModulesDir, recursive: true)
@@ -1252,7 +1252,7 @@ final class PluginInvocationTests: XCTestCase {
12521252
// swift-interface-format-version: 1.0
12531253
// swift-module-flags: -module-name ModuleFoundViaExtraSearchPaths
12541254
""")
1255-
1255+
12561256
/////////
12571257
// Load a workspace from the package.
12581258
let observability = ObservabilitySystem.makeForTesting()
@@ -1589,5 +1589,5 @@ extension BuildPlanResult {
15891589
$0.module.name == target && $0.destination == destination
15901590
}
15911591
XCTAssertEqual(targets.count, 1, file: file, line: line)
1592-
}
1592+
}
15931593
}

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)