Skip to content

[PackageModel] Support swift-testing installed in a toolchain #7840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 5, 2024
Merged
7 changes: 5 additions & 2 deletions Sources/Commands/Utilities/TestingSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ enum TestingSupport {
}
#if !os(macOS)
#if os(Windows)
if let location = toolchain.xctestPath {
env.prependPath(key: .path, value: location.pathString)
if let xctestLocation = toolchain.xctestPath {
env.prependPath(key: .path, value: xctestLocation.pathString)
}
if let swiftTestingLocation = toolchain.swiftTestingPathOnWindows {
env.prependPath(key: .path, value: swiftTestingLocation.pathString)
}
#endif
return env
Expand Down
14 changes: 11 additions & 3 deletions Sources/PackageModel/Toolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,24 @@ extension Toolchain {

public var hostLibDir: AbsolutePath {
get throws {
return try toolchainLibDir.appending(components: ["swift", "host"])
try Self.toolchainLibDir(swiftCompilerPath: self.swiftCompilerPath).appending(
components: ["swift", "host"]
)
}
}

public var macosSwiftStdlib: AbsolutePath {
get throws {
return try AbsolutePath(validating: "../../lib/swift/macosx", relativeTo: resolveSymlinks(swiftCompilerPath))
try Self.toolchainLibDir(swiftCompilerPath: self.swiftCompilerPath).appending(
components: ["swift", "macosx"]
)
}
}

public var toolchainLibDir: AbsolutePath {
get throws {
// FIXME: Not sure if it's better to base this off of Swift compiler or our own binary.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// FIXME: Not sure if it's better to base this off of Swift compiler or our own binary.

return try AbsolutePath(validating: "../../lib", relativeTo: resolveSymlinks(swiftCompilerPath))
try Self.toolchainLibDir(swiftCompilerPath: self.swiftCompilerPath)
}
}

Expand All @@ -110,4 +114,8 @@ extension Toolchain {
public var extraSwiftCFlags: [String] {
extraFlags.swiftCompilerFlags
}

package static func toolchainLibDir(swiftCompilerPath: AbsolutePath) throws -> AbsolutePath {
try AbsolutePath(validating: "../../lib", relativeTo: resolveSymlinks(swiftCompilerPath))
}
}
8 changes: 7 additions & 1 deletion Sources/PackageModel/ToolchainConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public struct ToolchainConfiguration {
/// This is optional for example on macOS w/o Xcode.
public var xctestPath: AbsolutePath?

/// Path to the swift-testing utility.
/// Currently computed only for Windows.
public var swiftTestingPath: AbsolutePath?

/// Creates the set of manifest resources associated with a `swiftc` executable.
///
/// - Parameters:
Expand All @@ -59,7 +63,8 @@ public struct ToolchainConfiguration {
swiftCompilerEnvironment: Environment = .current,
swiftPMLibrariesLocation: SwiftPMLibrariesLocation? = nil,
sdkRootPath: AbsolutePath? = nil,
xctestPath: AbsolutePath? = nil
xctestPath: AbsolutePath? = nil,
swiftTestingPath: AbsolutePath? = nil
) {
let swiftPMLibrariesLocation = swiftPMLibrariesLocation ?? {
return .init(swiftCompilerPath: swiftCompilerPath)
Expand All @@ -72,6 +77,7 @@ public struct ToolchainConfiguration {
self.swiftPMLibrariesLocation = swiftPMLibrariesLocation
self.sdkRootPath = sdkRootPath
self.xctestPath = xctestPath
self.swiftTestingPath = swiftTestingPath
}
}

Expand Down
Loading