Skip to content

Commit deea25d

Browse files
committed
SKTestSupport: remove hardcoded version for XCTest
The XCTest and Testing version information is encoded into the `PlatformInfo.plist` that is at the root of the platform. Use this to determine the path for XCTest. This allows us to migrate the XCTest location into an appropriate versioned directory.
1 parent 909c0a9 commit deea25d

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

Sources/SKTestSupport/IndexedSingleSwiftFileTestProject.swift

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import SourceKitLSP
1919
import SwiftExtensions
2020
import TSCBasic
2121
import ToolchainRegistry
22+
import Basics
23+
import PackageModel
2224

2325
package struct IndexedSingleSwiftFileTestProject {
2426
enum Error: Swift.Error {
@@ -79,17 +81,23 @@ package struct IndexedSingleSwiftFileTestProject {
7981
// The following are needed so we can import XCTest
8082
let sdkUrl = URL(fileURLWithPath: sdk)
8183
#if os(Windows)
82-
let xctestModuleDir =
83-
sdkUrl
84-
.deletingLastPathComponent()
85-
.deletingLastPathComponent()
86-
.appendingPathComponent("Library")
87-
.appendingPathComponent("XCTest-development")
88-
.appendingPathComponent("usr")
89-
.appendingPathComponent("lib")
90-
.appendingPathComponent("swift")
91-
.appendingPathComponent("windows")
92-
compilerArguments += ["-I", try xctestModuleDir.filePath]
84+
let platform = sdkUrl.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()
85+
if let info = try? WindowsPlatformInfo(
86+
reading: AbsolutePath(validating: platform.appendingPathComponent("Info.plist").path),
87+
observabilityScope: nil,
88+
filesystem: Basics.localFileSystem
89+
) {
90+
let xctestModuleDir =
91+
platform
92+
.appendingPathComponent("Developer")
93+
.appendingPathComponent("Library")
94+
.appendingPathComponent("XCTest-\(info.defaults.xctestVersion)")
95+
.appendingPathComponent("usr")
96+
.appendingPathComponent("lib")
97+
.appendingPathComponent("swift")
98+
.appendingPathComponent("windows")
99+
compilerArguments += ["-I", try xctestModuleDir.filePath]
100+
}
93101
#else
94102
let usrLibDir =
95103
sdkUrl

0 commit comments

Comments
 (0)