Skip to content
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
3 changes: 2 additions & 1 deletion Sources/Commands/SwiftTestTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ public struct SwiftTestTool: SwiftCommand {

// validate XCTest available on darwin based systems
let toolchain = try swiftTool.getDestinationToolchain()
if toolchain.triple.isDarwin() && toolchain.xctestPath == nil {
let isHostTestingAvailable = try swiftTool.getHostToolchain().destination.supportsTesting
if toolchain.triple.isDarwin() && toolchain.xctestPath == nil || !isHostTestingAvailable {
throw TestError.xctestNotAvailable
}
} catch {
Expand Down
2 changes: 1 addition & 1 deletion Sources/CoreCommands/SwiftTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ public final class SwiftTool {
private lazy var _hostToolchain: Result<UserToolchain, Swift.Error> = {
return Result(catching: {
try UserToolchain(destination: Destination.hostDestination(
originalWorkingDirectory: self.originalWorkingDirectory))
originalWorkingDirectory: self.originalWorkingDirectory, observabilityScope: self.observabilityScope))
})
}()

Expand Down
32 changes: 24 additions & 8 deletions Sources/PackageModel/Destination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public struct Destination: Equatable {
/// The architectures to build for. We build for host architecture if this is empty.
public var architectures: [String]? = nil

/// Whether or not the receiver supports testing.
public let supportsTesting: Bool

/// Root directory path of the SDK used to compile for the destination.
@available(*, deprecated, message: "use `sdkRootDir` instead")
public var sdk: AbsolutePath? {
Expand Down Expand Up @@ -402,12 +405,14 @@ public struct Destination: Equatable {
hostTriple: Triple? = nil,
targetTriple: Triple? = nil,
toolset: Toolset,
pathsConfiguration: PathsConfiguration
pathsConfiguration: PathsConfiguration,
supportsTesting: Bool = true
) {
self.hostTriple = hostTriple
self.targetTriple = targetTriple
self.toolset = toolset
self.pathsConfiguration = pathsConfiguration
self.supportsTesting = supportsTesting
}

/// Returns the bin directory for the host.
Expand All @@ -428,7 +433,8 @@ public struct Destination: Equatable {
public static func hostDestination(
_ binDir: AbsolutePath? = nil,
originalWorkingDirectory: AbsolutePath? = nil,
environment: [String: String] = ProcessEnv.vars
environment: [String: String] = ProcessEnv.vars,
observabilityScope: ObservabilityScope? = nil
) throws -> Destination {
let originalWorkingDirectory = originalWorkingDirectory ?? localFileSystem.currentWorkingDirectory
// Select the correct binDir.
Expand Down Expand Up @@ -463,14 +469,23 @@ public struct Destination: Equatable {
#endif

// Compute common arguments for clang and swift.
let supportsTesting: Bool
var extraCCFlags: [String] = []
var extraSwiftCFlags: [String] = []
#if os(macOS)
let sdkPaths = try Destination.sdkPlatformFrameworkPaths(environment: environment)
extraCCFlags += ["-F", sdkPaths.fwk.pathString]
extraSwiftCFlags += ["-F", sdkPaths.fwk.pathString]
extraSwiftCFlags += ["-I", sdkPaths.lib.pathString]
extraSwiftCFlags += ["-L", sdkPaths.lib.pathString]
do {
let sdkPaths = try Destination.sdkPlatformFrameworkPaths(environment: environment)
extraCCFlags += ["-F", sdkPaths.fwk.pathString]
extraSwiftCFlags += ["-F", sdkPaths.fwk.pathString]
extraSwiftCFlags += ["-I", sdkPaths.lib.pathString]
extraSwiftCFlags += ["-L", sdkPaths.lib.pathString]
supportsTesting = true
} catch {
supportsTesting = false
observabilityScope?.emit(warning: "could not determine XCTest paths: \(error)")
}
#else
supportsTesting = true
#endif

#if !os(Windows)
Expand All @@ -485,7 +500,8 @@ public struct Destination: Equatable {
],
rootPaths: [binDir]
),
pathsConfiguration: .init(sdkRootPath: sdkPath)
pathsConfiguration: .init(sdkRootPath: sdkPath),
supportsTesting: supportsTesting
)
}

Expand Down