Skip to content

Commit 376d7ed

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 376d7ed

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

Sources/SKTestSupport/IndexedSingleSwiftFileTestProject.swift

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,41 @@ import SwiftExtensions
2020
import TSCBasic
2121
import ToolchainRegistry
2222

23+
package struct WindowsPlatformInfo {
24+
package struct DefaultProperties {
25+
/// XCTEST_VERSION
26+
/// specifies the version string of the bundled XCTest.
27+
public let xctestVersion: String
28+
29+
/// SWIFT_TESTING_VERSION
30+
/// specifies the version string of the bundled swift-testing.
31+
public let swiftTestingVersion: String?
32+
33+
/// SWIFTC_FLAGS
34+
/// Specifies extra flags to pass to swiftc from Swift Package Manager.
35+
public let extraSwiftCFlags: [String]?
36+
}
37+
38+
public let defaults: DefaultProperties
39+
}
40+
extension WindowsPlatformInfo.DefaultProperties: Decodable {
41+
enum CodingKeys: String, CodingKey {
42+
case xctestVersion = "XCTEST_VERSION"
43+
case swiftTestingVersion = "SWIFT_TESTING_VERSION"
44+
case extraSwiftCFlags = "SWIFTC_FLAGS"
45+
}
46+
}
47+
extension WindowsPlatformInfo: Decodable {
48+
enum CodingKeys: String, CodingKey {
49+
case defaults = "DefaultProperties"
50+
}
51+
}
52+
extension WindowsPlatformInfo {
53+
package init(reading path: URL) throws {
54+
let data: Data = try Data(contentsOf: path)
55+
self = try PropertyListDecoder().decode(WindowsPlatformInfo.self, from: data)
56+
}
57+
}
2358
package struct IndexedSingleSwiftFileTestProject {
2459
enum Error: Swift.Error {
2560
case swiftcNotFound
@@ -79,12 +114,13 @@ package struct IndexedSingleSwiftFileTestProject {
79114
// The following are needed so we can import XCTest
80115
let sdkUrl = URL(fileURLWithPath: sdk)
81116
#if os(Windows)
117+
let platform = sdkUrl.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()
118+
let info = try WindowsPlatformInfo(reading: platform.appendingPathComponent("Info.plist"))
82119
let xctestModuleDir =
83-
sdkUrl
84-
.deletingLastPathComponent()
85-
.deletingLastPathComponent()
120+
platform
121+
.appendingPathComponent("Developer")
86122
.appendingPathComponent("Library")
87-
.appendingPathComponent("XCTest-development")
123+
.appendingPathComponent("XCTest-\(info.defaults.xctestVersion)")
88124
.appendingPathComponent("usr")
89125
.appendingPathComponent("lib")
90126
.appendingPathComponent("swift")

0 commit comments

Comments
 (0)