Skip to content

Commit fe90bef

Browse files
committed
Skip testLibraryUsedByExecutableTargetAndPackagePlugin if SwiftPM can’t handle modules for the target and host properly
This fixes a test failure in Xcode 15.4.
1 parent c4cf47f commit fe90bef

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,78 @@ public actor SkipUnless {
276276
throw NoSwiftInToolchain()
277277
}
278278

279-
let process = Process(args: swift.pathString, "build", "--help-hidden")
280-
try process.launch()
281-
let result = try await process.waitUntilExit()
279+
let result = try await Process.run(
280+
arguments: [swift.pathString, "build", "--help-hidden"],
281+
workingDirectory: nil
282+
)
282283
guard let output = String(bytes: try result.output.get(), encoding: .utf8) else {
283284
return false
284285
}
285286
return output.contains("--experimental-prepare-for-indexing")
286287
}
287288
}
288289

290+
public static func swiftPMStoresModulesForTargetAndHostInSeparateFolders(
291+
file: StaticString = #filePath,
292+
line: UInt = #line
293+
) async throws {
294+
struct NoSwiftInToolchain: Error {}
295+
296+
return try await shared.skipUnlessSupportedByToolchain(swiftVersion: SwiftVersion(6, 0), file: file, line: line) {
297+
guard let swift = await ToolchainRegistry.forTesting.default?.swift else {
298+
throw NoSwiftInToolchain()
299+
}
300+
301+
let project = try await SwiftPMTestProject(
302+
files: [
303+
"Lib/MyFile.swift": """
304+
public func foo() {}
305+
""",
306+
"MyExec/MyExec.swift": """
307+
import Lib
308+
func bar() {
309+
foo()
310+
}
311+
""",
312+
"Plugins/MyPlugin/MyPlugin.swift": "",
313+
],
314+
manifest: """
315+
let package = Package(
316+
name: "MyLibrary",
317+
targets: [
318+
.target(name: "Lib"),
319+
.executableTarget(name: "MyExec", dependencies: ["Lib"]),
320+
.plugin(
321+
name: "MyPlugin",
322+
capability: .command(
323+
intent: .sourceCodeFormatting(),
324+
permissions: []
325+
),
326+
dependencies: ["MyExec"]
327+
)
328+
]
329+
)
330+
"""
331+
)
332+
do {
333+
// In older version of SwiftPM building `MyPlugin` followed by `Lib` resulted in an error about a redefinition
334+
// of Lib when building Lib.
335+
for target in ["MyPlugin", "Lib"] {
336+
var arguments = [
337+
swift.pathString, "build", "--package-path", project.scratchDirectory.path, "--target", target,
338+
]
339+
if let globalModuleCache {
340+
arguments += ["-Xswiftc", "-module-cache-path", "-Xswiftc", globalModuleCache.path]
341+
}
342+
try await Process.run(arguments: arguments, workingDirectory: nil)
343+
}
344+
return true
345+
} catch {
346+
return false
347+
}
348+
}
349+
}
350+
289351
/// A long test is a test that takes longer than 1-2s to execute.
290352
public static func longTestsEnabled() throws {
291353
if let value = ProcessInfo.processInfo.environment["SKIP_LONG_TESTS"], value == "1" || value == "YES" {

Tests/SourceKitLSPTests/BackgroundIndexingTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,7 @@ final class BackgroundIndexingTests: XCTestCase {
10011001
}
10021002

10031003
func testLibraryUsedByExecutableTargetAndPackagePlugin() async throws {
1004+
try await SkipUnless.swiftPMStoresModulesForTargetAndHostInSeparateFolders()
10041005
let project = try await SwiftPMTestProject(
10051006
files: [
10061007
"Lib/MyFile.swift": """

0 commit comments

Comments
 (0)