Skip to content

Commit a161ff6

Browse files
committed
Properly handle swift-testing installations in toolchain/SDK.
On macOS SwiftPM should prefer swift-testing installed into a custom toolchain when used. On Windows we need special logic to discover swift-testing location. - Add special swift compiler "extra" flags to favor swift-testing installed in a toolchain. - Inject `-I`, `-L` on Windows that point to where swift-testing is installed in SDKROOT. - Inject a path to testing on `PATH` environment variable on Windows to make sure that the library is always discoverable. Resolves: rdar://132828246
1 parent 5b27e1a commit a161ff6

File tree

5 files changed

+241
-45
lines changed

5 files changed

+241
-45
lines changed

Sources/Commands/Utilities/TestingSupport.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,11 @@ enum TestingSupport {
176176
}
177177
#if !os(macOS)
178178
#if os(Windows)
179-
if let location = toolchain.xctestPath {
180-
env.prependPath(key: .path, value: location.pathString)
179+
if let xctestLocation = toolchain.xctestPath {
180+
env.prependPath(key: .path, value: xctestLocation.pathString)
181+
}
182+
if let swiftTestingLocation = toolchain.swiftTestingPathOnWindows {
183+
env.prependPath(key: .path, value: swiftTestingLocation.pathString)
181184
}
182185
#endif
183186
return env

Sources/PackageModel/Toolchain.swift

+11-3
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,24 @@ extension Toolchain {
7171

7272
public var hostLibDir: AbsolutePath {
7373
get throws {
74-
return try toolchainLibDir.appending(components: ["swift", "host"])
74+
try Self.toolchainLibDir(swiftCompilerPath: self.swiftCompilerPath).appending(
75+
components: ["swift", "host"]
76+
)
7577
}
7678
}
7779

7880
public var macosSwiftStdlib: AbsolutePath {
7981
get throws {
80-
return try AbsolutePath(validating: "../../lib/swift/macosx", relativeTo: resolveSymlinks(swiftCompilerPath))
82+
try Self.toolchainLibDir(swiftCompilerPath: self.swiftCompilerPath).appending(
83+
components: ["swift", "macosx"]
84+
)
8185
}
8286
}
8387

8488
public var toolchainLibDir: AbsolutePath {
8589
get throws {
8690
// FIXME: Not sure if it's better to base this off of Swift compiler or our own binary.
87-
return try AbsolutePath(validating: "../../lib", relativeTo: resolveSymlinks(swiftCompilerPath))
91+
try Self.toolchainLibDir(swiftCompilerPath: self.swiftCompilerPath)
8892
}
8993
}
9094

@@ -107,4 +111,8 @@ extension Toolchain {
107111
public var extraSwiftCFlags: [String] {
108112
extraFlags.swiftCompilerFlags
109113
}
114+
115+
package static func toolchainLibDir(swiftCompilerPath: AbsolutePath) throws -> AbsolutePath {
116+
try AbsolutePath(validating: "../../lib", relativeTo: resolveSymlinks(swiftCompilerPath))
117+
}
110118
}

Sources/PackageModel/ToolchainConfiguration.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public struct ToolchainConfiguration {
4242
/// This is optional for example on macOS w/o Xcode.
4343
public var xctestPath: AbsolutePath?
4444

45+
/// Path to the swift-testing utility.
46+
/// Currently computed only for Windows.
47+
public var swiftTestingPath: AbsolutePath?
48+
4549
/// Creates the set of manifest resources associated with a `swiftc` executable.
4650
///
4751
/// - Parameters:
@@ -59,7 +63,8 @@ public struct ToolchainConfiguration {
5963
swiftCompilerEnvironment: Environment = .current,
6064
swiftPMLibrariesLocation: SwiftPMLibrariesLocation? = nil,
6165
sdkRootPath: AbsolutePath? = nil,
62-
xctestPath: AbsolutePath? = nil
66+
xctestPath: AbsolutePath? = nil,
67+
swiftTestingPath: AbsolutePath? = nil
6368
) {
6469
let swiftPMLibrariesLocation = swiftPMLibrariesLocation ?? {
6570
return .init(swiftCompilerPath: swiftCompilerPath)
@@ -72,6 +77,7 @@ public struct ToolchainConfiguration {
7277
self.swiftPMLibrariesLocation = swiftPMLibrariesLocation
7378
self.sdkRootPath = sdkRootPath
7479
self.xctestPath = xctestPath
80+
self.swiftTestingPath = swiftTestingPath
7581
}
7682
}
7783

0 commit comments

Comments
 (0)