Skip to content

Commit b7116db

Browse files
authored
Remove swiftpm-xctest-helper (#6667)
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
1 parent fc1fb1f commit b7116db

File tree

6 files changed

+26
-239
lines changed

6 files changed

+26
-239
lines changed

Package.swift

-7
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,6 @@ let package = Package(
491491
name: "swift-package-registry",
492492
dependencies: ["Commands", "PackageRegistryTool"]
493493
),
494-
.executableTarget(
495-
/** Shim tool to find test names on OS X */
496-
name: "swiftpm-xctest-helper",
497-
dependencies: [],
498-
linkerSettings: [
499-
.unsafeFlags(["-Xlinker", "-rpath", "-Xlinker", "@executable_path/../../../lib/swift/macosx"], .when(platforms: [.macOS])),
500-
]),
501494

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

Sources/Commands/Utilities/TestingSupport.swift

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

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

Sources/SPMTestSupport/SwiftPMProduct.swift

-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public enum SwiftPM {
2525
case Registry
2626
case Test
2727
case Run
28-
case XCTestHelper
2928
}
3029

3130
extension SwiftPM {
@@ -42,8 +41,6 @@ extension SwiftPM {
4241
return "swift-test"
4342
case .Run:
4443
return "swift-run"
45-
case .XCTestHelper:
46-
return "swiftpm-xctest-helper"
4744
}
4845
}
4946

Sources/swiftpm-xctest-helper/main.swift

-147
This file was deleted.

Tests/FunctionalTests/SwiftPMXCTestHelperTests.swift

-64
This file was deleted.

Utilities/bootstrap

-5
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,6 @@ def install_swiftpm(prefix, args):
445445
note("Creating tool symlink from %s to %s" % (src, dest))
446446
symlink_force(src, dest)
447447

448-
# On Darwin, also install the swiftpm-xctest-helper tool.
449-
if platform.system() == 'Darwin':
450-
dest = os.path.join(prefix, "libexec", "swift", "pm")
451-
install_binary(args, "swiftpm-xctest-helper", dest)
452-
453448
# Install the PackageDescription/CompilerPluginSupport libraries and associated modules.
454449
dest = os.path.join(prefix, "lib", "swift", "pm", "ManifestAPI")
455450
install_dylib(args, "PackageDescription", dest, ["PackageDescription", "CompilerPluginSupport"])

0 commit comments

Comments
 (0)