Skip to content

Commit c459f1a

Browse files
xedingrynspan
authored andcommitted
Testing: Find swiftpm-testing-helper based on SwiftSDK root paths
The `swiftpm-testing-helper` itself is merged separately by #7771
1 parent 300f0f1 commit c459f1a

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
@@ -886,13 +886,8 @@ final class TestRunner {
886886
}
887887
args += [xctestPath.pathString]
888888
case .swiftTesting:
889-
// FIXME: better way to get path to self
890-
let toolPath = String(unsafeUninitializedCapacity: 2048) { buffer in
891-
var count = UInt32(buffer.count)
892-
_NSGetExecutablePath(buffer.baseAddress!, &count)
893-
return Int(count)
894-
}
895-
args += [toolPath, "--test-bundle-path", testPath.pathString]
889+
let helper = try self.toolchain.getSwiftTestingHelper()
890+
args += [helper.pathString, "--test-bundle-path", testPath.pathString]
896891
}
897892
args += additionalArguments
898893
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)