Skip to content

Commit e7c1438

Browse files
committed
Testing: Find swiftpm-testing-helper based on SwiftSDK root paths
The `swiftpm-testing-helper` itself is merged separately by #7771
1 parent 01adca4 commit e7c1438

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

Sources/Commands/SwiftTestCommand.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -847,13 +847,8 @@ final class TestRunner {
847847
}
848848
args += [xctestPath.pathString]
849849
case .swiftTesting:
850-
// FIXME: better way to get path to self
851-
let toolPath = String(unsafeUninitializedCapacity: 2048) { buffer in
852-
var count = UInt32(buffer.count)
853-
_NSGetExecutablePath(buffer.baseAddress!, &count)
854-
return Int(count)
855-
}
856-
args += [toolPath, "--test-bundle-path", testPath.pathString]
850+
let helper = try self.toolchain.getSwiftTestingHelper()
851+
args += [helper.pathString, "--test-bundle-path", testPath.pathString]
857852
}
858853
args += additionalArguments
859854
args += [testPath.pathString]

Sources/PackageModel/UserToolchain.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,24 @@ public final class UserToolchain: Toolchain {
387387
)
388388
}
389389

390+
#if os(macOS)
391+
public func getSwiftTestingHelper() throws -> AbsolutePath {
392+
// The helper would be located in `.build/<config>` directory when
393+
// SwiftPM is built locally and `usr/libexec/swift/pm` directory in
394+
// an installed version.
395+
let binDirectories = self.swiftSDK.toolset.rootPaths +
396+
self.swiftSDK.toolset.rootPaths.map {
397+
$0.parentDirectory.appending(components: ["libexec", "swift", "pm"])
398+
}
399+
400+
return try UserToolchain.getTool(
401+
"swiftpm-testing-helper",
402+
binDirectories: binDirectories,
403+
fileSystem: self.fileSystem
404+
)
405+
}
406+
#endif
407+
390408
internal static func deriveSwiftCFlags(
391409
triple: Triple,
392410
swiftSDK: SwiftSDK,

0 commit comments

Comments
 (0)