@@ -29,21 +29,34 @@ enum TestingSupport {
29
29
///
30
30
/// - Returns: Path to XCTestHelper tool.
31
31
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
+ }
39
43
}
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
+ }
45
50
}
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: " , " ) ) " )
47
60
}
48
61
49
62
static func getTestSuites( in testProducts: [ BuiltTestProduct ] , swiftTool: SwiftTool , enableCodeCoverage: Bool , sanitizers: [ Sanitizer ] ) throws -> [ AbsolutePath : [ TestSuite ] ] {
0 commit comments