Skip to content

[6.1] Include the path to the platform's PrivateFrameworks directory in DYLD_FRAMEWORK_PATH when launching test runners #8204

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
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
8 changes: 6 additions & 2 deletions Sources/Commands/Utilities/TestingSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,12 @@ enum TestingSupport {
// Since XCTestHelper targets macOS, we need the macOS platform paths here.
if let sdkPlatformPaths = try? SwiftSDK.sdkPlatformPaths(for: .macOS) {
// appending since we prefer the user setting (if set) to the one we inject
env.appendPath(key: "DYLD_FRAMEWORK_PATH", value: sdkPlatformPaths.frameworks.pathString)
env.appendPath(key: "DYLD_LIBRARY_PATH", value: sdkPlatformPaths.libraries.pathString)
for frameworkPath in sdkPlatformPaths.frameworks {
env.appendPath(key: "DYLD_FRAMEWORK_PATH", value: frameworkPath.pathString)
}
for libraryPath in sdkPlatformPaths.libraries {
env.appendPath(key: "DYLD_LIBRARY_PATH", value: libraryPath.pathString)
}
}

// We aren't using XCTest's harness logic to run Swift Testing tests.
Expand Down
37 changes: 23 additions & 14 deletions Sources/PackageModel/SwiftSDKs/SwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -582,10 +582,10 @@ public struct SwiftSDK: Equatable {
#if os(macOS)
do {
let sdkPaths = try SwiftSDK.sdkPlatformPaths(for: darwinPlatform, environment: environment)
extraCCFlags += ["-F", sdkPaths.frameworks.pathString]
extraSwiftCFlags += ["-F", sdkPaths.frameworks.pathString]
extraSwiftCFlags += ["-I", sdkPaths.libraries.pathString]
extraSwiftCFlags += ["-L", sdkPaths.libraries.pathString]
extraCCFlags.append(contentsOf: sdkPaths.frameworks.flatMap { ["-F", $0.pathString] })
extraSwiftCFlags.append(contentsOf: sdkPaths.frameworks.flatMap { ["-F", $0.pathString] })
extraSwiftCFlags.append(contentsOf: sdkPaths.libraries.flatMap { ["-I", $0.pathString] })
extraSwiftCFlags.append(contentsOf: sdkPaths.libraries.flatMap { ["-L", $0.pathString] })
xctestSupport = .supported
} catch {
xctestSupport = .unsupported(reason: String(describing: error))
Expand Down Expand Up @@ -617,11 +617,11 @@ public struct SwiftSDK: Equatable {
///
/// - SeeAlso: ``sdkPlatformPaths(for:environment:)``
public struct PlatformPaths {
/// Path to the directory containing auxiliary platform frameworks.
public var frameworks: AbsolutePath
/// Paths of directories containing auxiliary platform frameworks.
public var frameworks: [AbsolutePath]

/// Path to the directory containing auxiliary platform libraries.
public var libraries: AbsolutePath
/// Paths of directories containing auxiliary platform libraries.
public var libraries: [AbsolutePath]
}

/// Returns `macosx` sdk platform framework path.
Expand All @@ -630,7 +630,13 @@ public struct SwiftSDK: Equatable {
environment: Environment = .current
) throws -> (fwk: AbsolutePath, lib: AbsolutePath) {
let paths = try sdkPlatformPaths(for: .macOS, environment: environment)
return (fwk: paths.frameworks, lib: paths.libraries)
guard let frameworkPath = paths.frameworks.first else {
throw StringError("could not determine SDK platform framework path")
}
guard let libraryPath = paths.libraries.first else {
throw StringError("could not determine SDK platform library path")
}
return (fwk: frameworkPath, lib: libraryPath)
}

/// Returns ``SwiftSDK/PlatformPaths`` for the provided Darwin platform.
Expand All @@ -652,17 +658,20 @@ public struct SwiftSDK: Equatable {
throw StringError("could not determine SDK platform path")
}

// For XCTest framework.
let fwk = try AbsolutePath(validating: platformPath).appending(
// For testing frameworks.
let frameworksPath = try AbsolutePath(validating: platformPath).appending(
components: "Developer", "Library", "Frameworks"
)
let privateFrameworksPath = try AbsolutePath(validating: platformPath).appending(
components: "Developer", "Library", "PrivateFrameworks"
)

// For XCTest Swift library.
let lib = try AbsolutePath(validating: platformPath).appending(
// For testing libraries.
let librariesPath = try AbsolutePath(validating: platformPath).appending(
components: "Developer", "usr", "lib"
)

let sdkPlatformFrameworkPath = PlatformPaths(frameworks: fwk, libraries: lib)
let sdkPlatformFrameworkPath = PlatformPaths(frameworks: [frameworksPath, privateFrameworksPath], libraries: [librariesPath])
_sdkPlatformFrameworkPath[darwinPlatform] = sdkPlatformFrameworkPath
return sdkPlatformFrameworkPath
}
Expand Down