Skip to content

Commit 86b0ff1

Browse files
authored
Include the path to the platform's PrivateFrameworks directory in DYLD_FRAMEWORK_PATH when launching test runners (#8199)
This modifies the logic which sets the value of the `DYLD_FRAMEWORK_PATH` environment variable when launching test runners on Darwin when Xcode is installed: currently it includes the path to the platform's developer "Frameworks" directory, and this change adds the sibling "PrivateFrameworks" directory as well. ### Motivation: XCTest includes some private support frameworks, and these frameworks must be aligned with the public framework for testing to work correctly. This ensures that if the path to the (public) frameworks directory is specified, the aligned private frameworks directory is also included. ### Modifications: - Add `$PLATFORM/Developer/Library/PrivateFrameworks` to the `DYLD_FRAMEWORK_PATH` env var. Resolves rdar://141564191
1 parent 0401a2a commit 86b0ff1

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

Sources/Commands/Utilities/TestingSupport.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,12 @@ enum TestingSupport {
219219
// Since XCTestHelper targets macOS, we need the macOS platform paths here.
220220
if let sdkPlatformPaths = try? SwiftSDK.sdkPlatformPaths(for: .macOS) {
221221
// appending since we prefer the user setting (if set) to the one we inject
222-
env.appendPath(key: "DYLD_FRAMEWORK_PATH", value: sdkPlatformPaths.frameworks.pathString)
223-
env.appendPath(key: "DYLD_LIBRARY_PATH", value: sdkPlatformPaths.libraries.pathString)
222+
for frameworkPath in sdkPlatformPaths.frameworks {
223+
env.appendPath(key: "DYLD_FRAMEWORK_PATH", value: frameworkPath.pathString)
224+
}
225+
for libraryPath in sdkPlatformPaths.libraries {
226+
env.appendPath(key: "DYLD_LIBRARY_PATH", value: libraryPath.pathString)
227+
}
224228
}
225229

226230
// We aren't using XCTest's harness logic to run Swift Testing tests.

Sources/PackageModel/SwiftSDKs/SwiftSDK.swift

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,10 @@ public struct SwiftSDK: Equatable {
582582
#if os(macOS)
583583
do {
584584
let sdkPaths = try SwiftSDK.sdkPlatformPaths(for: darwinPlatform, environment: environment)
585-
extraCCFlags += ["-F", sdkPaths.frameworks.pathString]
586-
extraSwiftCFlags += ["-F", sdkPaths.frameworks.pathString]
587-
extraSwiftCFlags += ["-I", sdkPaths.libraries.pathString]
588-
extraSwiftCFlags += ["-L", sdkPaths.libraries.pathString]
585+
extraCCFlags.append(contentsOf: sdkPaths.frameworks.flatMap { ["-F", $0.pathString] })
586+
extraSwiftCFlags.append(contentsOf: sdkPaths.frameworks.flatMap { ["-F", $0.pathString] })
587+
extraSwiftCFlags.append(contentsOf: sdkPaths.libraries.flatMap { ["-I", $0.pathString] })
588+
extraSwiftCFlags.append(contentsOf: sdkPaths.libraries.flatMap { ["-L", $0.pathString] })
589589
xctestSupport = .supported
590590
} catch {
591591
xctestSupport = .unsupported(reason: String(describing: error))
@@ -617,11 +617,11 @@ public struct SwiftSDK: Equatable {
617617
///
618618
/// - SeeAlso: ``sdkPlatformPaths(for:environment:)``
619619
public struct PlatformPaths {
620-
/// Path to the directory containing auxiliary platform frameworks.
621-
public var frameworks: AbsolutePath
620+
/// Paths of directories containing auxiliary platform frameworks.
621+
public var frameworks: [AbsolutePath]
622622

623-
/// Path to the directory containing auxiliary platform libraries.
624-
public var libraries: AbsolutePath
623+
/// Paths of directories containing auxiliary platform libraries.
624+
public var libraries: [AbsolutePath]
625625
}
626626

627627
/// Returns `macosx` sdk platform framework path.
@@ -630,7 +630,13 @@ public struct SwiftSDK: Equatable {
630630
environment: Environment = .current
631631
) throws -> (fwk: AbsolutePath, lib: AbsolutePath) {
632632
let paths = try sdkPlatformPaths(for: .macOS, environment: environment)
633-
return (fwk: paths.frameworks, lib: paths.libraries)
633+
guard let frameworkPath = paths.frameworks.first else {
634+
throw StringError("could not determine SDK platform framework path")
635+
}
636+
guard let libraryPath = paths.libraries.first else {
637+
throw StringError("could not determine SDK platform library path")
638+
}
639+
return (fwk: frameworkPath, lib: libraryPath)
634640
}
635641

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

655-
// For XCTest framework.
656-
let fwk = try AbsolutePath(validating: platformPath).appending(
661+
// For testing frameworks.
662+
let frameworksPath = try AbsolutePath(validating: platformPath).appending(
657663
components: "Developer", "Library", "Frameworks"
658664
)
665+
let privateFrameworksPath = try AbsolutePath(validating: platformPath).appending(
666+
components: "Developer", "Library", "PrivateFrameworks"
667+
)
659668

660-
// For XCTest Swift library.
661-
let lib = try AbsolutePath(validating: platformPath).appending(
669+
// For testing libraries.
670+
let librariesPath = try AbsolutePath(validating: platformPath).appending(
662671
components: "Developer", "usr", "lib"
663672
)
664673

665-
let sdkPlatformFrameworkPath = PlatformPaths(frameworks: fwk, libraries: lib)
674+
let sdkPlatformFrameworkPath = PlatformPaths(frameworks: [frameworksPath, privateFrameworksPath], libraries: [librariesPath])
666675
_sdkPlatformFrameworkPath[darwinPlatform] = sdkPlatformFrameworkPath
667676
return sdkPlatformFrameworkPath
668677
}

0 commit comments

Comments
 (0)