Skip to content

Commit c50f753

Browse files
authored
Remove swiftpm-xctest-helper (#6869)
A while ago, the canonical version of the helper tool was moved to Xcode itself, but in OSS toolchains and local builds, we were still using the prior version of the tool. This removes the previous tool and adjusts the code for finding the correct tool in the user's Xcode installation. rdar://74658052 (cherry picked from commit b7116db)
1 parent 3969e1e commit c50f753

File tree

6 files changed

+26
-239
lines changed

6 files changed

+26
-239
lines changed

Package.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,6 @@ let package = Package(
519519
name: "swift-package-registry",
520520
dependencies: ["Commands", "PackageRegistryTool"]
521521
),
522-
.executableTarget(
523-
/** Shim tool to find test names on OS X */
524-
name: "swiftpm-xctest-helper",
525-
dependencies: [],
526-
linkerSettings: [
527-
.unsafeFlags(["-Xlinker", "-rpath", "-Xlinker", "@executable_path/../../../lib/swift/macosx"], .when(platforms: [.macOS])),
528-
]),
529522

530523
// MARK: Support for Swift macros, should eventually move to a plugin-based solution
531524

Sources/Commands/Utilities/TestingSupport.swift

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,34 @@ enum TestingSupport {
2929
///
3030
/// - Returns: Path to XCTestHelper tool.
3131
static func xctestHelperPath(swiftTool: SwiftTool) throws -> AbsolutePath {
32-
let xctestHelperBin = "swiftpm-xctest-helper"
33-
let binDirectory = try AbsolutePath(validating: CommandLine.arguments.first!,
34-
relativeTo: swiftTool.originalWorkingDirectory).parentDirectory
35-
// XCTestHelper tool is installed in libexec.
36-
let maybePath = binDirectory.parentDirectory.appending(components: "libexec", "swift", "pm", xctestHelperBin)
37-
if swiftTool.fileSystem.isFile(maybePath) {
38-
return maybePath
32+
var triedPaths = [AbsolutePath]()
33+
34+
func findXCTestHelper(swiftBuildPath: AbsolutePath) -> AbsolutePath? {
35+
// XCTestHelper tool is installed in libexec.
36+
let maybePath = swiftBuildPath.parentDirectory.parentDirectory.appending(components: "libexec", "swift", "pm", "swiftpm-xctest-helper")
37+
if swiftTool.fileSystem.isFile(maybePath) {
38+
return maybePath
39+
} else {
40+
triedPaths.append(maybePath)
41+
return nil
42+
}
3943
}
40-
// This will be true during swiftpm development.
41-
// FIXME: Factor all of the development-time resource location stuff into a common place.
42-
let path = binDirectory.appending(component: xctestHelperBin)
43-
if swiftTool.fileSystem.isFile(path) {
44-
return path
44+
45+
if let firstCLIArgument = CommandLine.arguments.first {
46+
let runningSwiftBuildPath = try AbsolutePath(validating: firstCLIArgument, relativeTo: swiftTool.originalWorkingDirectory)
47+
if let xctestHelperPath = findXCTestHelper(swiftBuildPath: runningSwiftBuildPath) {
48+
return xctestHelperPath
49+
}
4550
}
46-
throw InternalError("XCTestHelper binary not found.")
51+
52+
// This will be true during swiftpm development or when using swift.org toolchains.
53+
let xcodePath = try TSCBasic.Process.checkNonZeroExit(args: "/usr/bin/xcode-select", "--print-path").spm_chomp()
54+
let installedSwiftBuildPath = try TSCBasic.Process.checkNonZeroExit(args: "/usr/bin/xcrun", "--find", "swift-build", environment: ["DEVELOPER_DIR": xcodePath]).spm_chomp()
55+
if let xctestHelperPath = findXCTestHelper(swiftBuildPath: try AbsolutePath(validating: installedSwiftBuildPath)) {
56+
return xctestHelperPath
57+
}
58+
59+
throw InternalError("XCTestHelper binary not found, tried \(triedPaths.map { $0.pathString }.joined(separator: ", "))")
4760
}
4861

4962
static func getTestSuites(in testProducts: [BuiltTestProduct], swiftTool: SwiftTool, enableCodeCoverage: Bool, sanitizers: [Sanitizer]) throws -> [AbsolutePath: [TestSuite]] {

Sources/SPMTestSupport/SwiftPMProduct.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public enum SwiftPMProduct: Product {
2020
case SwiftPackageRegistry
2121
case SwiftTest
2222
case SwiftRun
23-
case XCTestHelper
2423

2524
/// Executable name.
2625
public var exec: RelativePath {
@@ -35,8 +34,6 @@ public enum SwiftPMProduct: Product {
3534
return RelativePath("swift-test")
3635
case .SwiftRun:
3736
return RelativePath("swift-run")
38-
case .XCTestHelper:
39-
return RelativePath("swiftpm-xctest-helper")
4037
}
4138
}
4239
}

Sources/swiftpm-xctest-helper/main.swift

Lines changed: 0 additions & 147 deletions
This file was deleted.

Tests/FunctionalTests/SwiftPMXCTestHelperTests.swift

Lines changed: 0 additions & 64 deletions
This file was deleted.

Utilities/bootstrap

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,6 @@ def install_swiftpm(prefix, args):
430430
note("Creating tool symlink from %s to %s" % (src, dest))
431431
symlink_force(src, dest)
432432

433-
# On Darwin, also install the swiftpm-xctest-helper tool.
434-
if platform.system() == 'Darwin':
435-
dest = os.path.join(prefix, "libexec", "swift", "pm")
436-
install_binary(args, "swiftpm-xctest-helper", dest)
437-
438433
# Install the PackageDescription/CompilerPluginSupport libraries and associated modules.
439434
dest = os.path.join(prefix, "lib", "swift", "pm", "ManifestAPI")
440435
install_dylib(args, "PackageDescription", dest, ["PackageDescription", "CompilerPluginSupport"])

0 commit comments

Comments
 (0)