Skip to content

[6.0] Properly handle swift-testing installations in toolchain/SDK #7856

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 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -71,20 +71,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.
return try AbsolutePath(validating: "../../lib", relativeTo: resolveSymlinks(swiftCompilerPath))
try Self.toolchainLibDir(swiftCompilerPath: self.swiftCompilerPath)
}
}

Expand All @@ -107,4 +111,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