Skip to content

Handle macOS CLT --show-sdk-platform-path issues #6977

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
Oct 11, 2023
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 @@ -195,7 +195,8 @@ public struct SwiftTestTool: SwiftCommand {

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

Expand Down
32 changes: 24 additions & 8 deletions Sources/PackageModel/SwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ public struct SwiftSDK: 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 target triple.
@available(*, deprecated, message: "use `pathsConfiguration.sdkRootPath` instead")
public var sdk: AbsolutePath? {
Expand Down Expand Up @@ -411,12 +414,14 @@ public struct SwiftSDK: 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 Down Expand Up @@ -447,7 +452,8 @@ public struct SwiftSDK: Equatable {
public static func hostSwiftSDK(
_ binDir: AbsolutePath? = nil,
originalWorkingDirectory: AbsolutePath? = nil,
environment: [String: String] = ProcessEnv.vars
environment: [String: String] = ProcessEnv.vars,
observabilityScope: ObservabilityScope? = nil
) throws -> SwiftSDK {
let originalWorkingDirectory = originalWorkingDirectory ?? localFileSystem.currentWorkingDirectory
// Select the correct binDir.
Expand Down Expand Up @@ -482,14 +488,23 @@ public struct SwiftSDK: Equatable {
#endif

// Compute common arguments for clang and swift.
let supportsTesting: Bool
var extraCCFlags: [String] = []
var extraSwiftCFlags: [String] = []
#if os(macOS)
let sdkPaths = try SwiftSDK.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 SwiftSDK.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 @@ -504,7 +519,8 @@ public struct SwiftSDK: Equatable {
],
rootPaths: [binDir]
),
pathsConfiguration: .init(sdkRootPath: sdkPath)
pathsConfiguration: .init(sdkRootPath: sdkPath),
supportsTesting: supportsTesting
)
}

Expand Down