Skip to content

Commit 94d3a69

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 94d3a69

File tree

1 file changed

+56
-11
lines changed

1 file changed

+56
-11
lines changed

Sources/SKTestSupport/IndexedSingleSwiftFileTestProject.swift

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,49 @@ 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+
41+
extension WindowsPlatformInfo.DefaultProperties: Decodable {
42+
enum CodingKeys: String, CodingKey {
43+
case xctestVersion = "XCTEST_VERSION"
44+
case swiftTestingVersion = "SWIFT_TESTING_VERSION"
45+
case extraSwiftCFlags = "SWIFTC_FLAGS"
46+
}
47+
}
48+
49+
extension WindowsPlatformInfo: Decodable {
50+
enum CodingKeys: String, CodingKey {
51+
case defaults = "DefaultProperties"
52+
}
53+
}
54+
55+
extension WindowsPlatformInfo {
56+
package init?(reading path: URL) {
57+
do {
58+
let data: Data = try Data(contentsOf: path)
59+
self = try PropertyListDecoder().decode(WindowsPlatformInfo.self, from: data)
60+
} catch {
61+
return nil
62+
}
63+
}
64+
}
65+
2366
package struct IndexedSingleSwiftFileTestProject {
2467
enum Error: Swift.Error {
2568
case swiftcNotFound
@@ -79,17 +122,19 @@ package struct IndexedSingleSwiftFileTestProject {
79122
// The following are needed so we can import XCTest
80123
let sdkUrl = URL(fileURLWithPath: sdk)
81124
#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]
125+
let platform = sdkUrl.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()
126+
if let info = WindowsPlatformInfo(reading: platform.appendingPathComponent("Info.plist")) {
127+
let xctestModuleDir =
128+
platform
129+
.appendingPathComponent("Developer")
130+
.appendingPathComponent("Library")
131+
.appendingPathComponent("XCTest-\(info.defaults.xctestVersion)")
132+
.appendingPathComponent("usr")
133+
.appendingPathComponent("lib")
134+
.appendingPathComponent("swift")
135+
.appendingPathComponent("windows")
136+
compilerArguments += ["-I", try xctestModuleDir.filePath]
137+
}
93138
#else
94139
let usrLibDir =
95140
sdkUrl

0 commit comments

Comments
 (0)