@@ -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 " {
0 commit comments