@@ -32,21 +32,34 @@ enum TestingSupport {
32
32
///
33
33
/// - Returns: Path to XCTestHelper tool.
34
34
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
+ }
42
46
}
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
+ }
48
53
}
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: " , " ) ) " )
50
63
}
51
64
52
65
static func getTestSuites( in testProducts: [ BuiltTestProduct ] , swiftTool: SwiftTool , enableCodeCoverage: Bool , sanitizers: [ Sanitizer ] ) throws -> [ AbsolutePath : [ TestSuite ] ] {
0 commit comments