Skip to content

Commit 9e0a63f

Browse files
authored
Merge pull request #2934 from compnerd/xctest
Commands: make `swift test` work on Windows
2 parents b53aead + 3079d89 commit 9e0a63f

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

Sources/Commands/SwiftTestTool.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,11 @@ fileprivate func constructTestEnvironment(
10171017
}
10181018

10191019
#if !os(macOS)
1020+
#if os(Windows)
1021+
if let location = toolchain.manifestResources.xctestLocation {
1022+
env["Path"] = "\(location.pathString);\(env["Path"] ?? "")"
1023+
}
1024+
#endif
10201025
return env
10211026
#else
10221027
// Fast path when no sanitizers are enabled.

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public protocol ManifestResourceProvider {
4343

4444
/// Extra flags to pass the Swift compiler.
4545
var swiftCompilerFlags: [String] { get }
46+
47+
/// XCTest Location
48+
var xctestLocation: AbsolutePath? { get }
4649
}
4750

4851
/// Default implemention for the resource provider.
@@ -55,6 +58,10 @@ public extension ManifestResourceProvider {
5558
var binDir: AbsolutePath? {
5659
return nil
5760
}
61+
62+
var xctestLocation: AbsolutePath? {
63+
return nil
64+
}
5865
}
5966

6067
/// Protocol for the manifest loader interface.

Sources/PackageLoading/UserManifestResources.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,22 @@ public struct UserManifestResources: ManifestResourceProvider {
1616
public let swiftCompilerFlags: [String]
1717
public let libDir: AbsolutePath
1818
public let sdkRoot: AbsolutePath?
19+
public let xctestLocation: AbsolutePath?
1920
public let binDir: AbsolutePath?
2021

2122
public init(
2223
swiftCompiler: AbsolutePath,
2324
swiftCompilerFlags: [String],
2425
libDir: AbsolutePath,
2526
sdkRoot: AbsolutePath? = nil,
27+
xctestLocation: AbsolutePath? = nil,
2628
binDir: AbsolutePath? = nil
2729
) {
2830
self.swiftCompiler = swiftCompiler
2931
self.swiftCompilerFlags = swiftCompilerFlags
3032
self.libDir = libDir
3133
self.sdkRoot = sdkRoot
34+
self.xctestLocation = xctestLocation
3235
self.binDir = binDir
3336
}
3437

Sources/Workspace/UserToolchain.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,29 @@ public final class UserToolchain: Toolchain {
339339
}
340340
}
341341

342+
var xctestLocation: AbsolutePath?
343+
#if os(Windows)
344+
if let DEVELOPER_DIR = ProcessEnv.vars["DEVELOPER_DIR"],
345+
let root = try? AbsolutePath(validating: DEVELOPER_DIR)
346+
.appending(component: "Platforms")
347+
.appending(component: "Windows.platform") {
348+
if let info = WindowsPlatformInfo(reading: root.appending(component: "Info.plist"),
349+
diagnostics: nil, filesystem: localFileSystem) {
350+
xctestLocation = root.appending(component: "Developer")
351+
.appending(component: "Library")
352+
.appending(component: "XCTest-\(info.defaults.xctestVersion)")
353+
.appending(component: "usr")
354+
.appending(component: "bin")
355+
}
356+
}
357+
#endif
358+
342359
manifestResources = UserManifestResources(
343360
swiftCompiler: swiftCompilers.manifest,
344361
swiftCompilerFlags: self.extraSwiftCFlags,
345362
libDir: pdLibDir,
346363
sdkRoot: self.destination.sdk,
364+
xctestLocation: xctestLocation,
347365
// Set the bin directory if we don't have a lib dir.
348366
binDir: localFileSystem.exists(pdLibDir) ? nil : binDir
349367
)

0 commit comments

Comments
 (0)