Skip to content
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

Improve Destination.sdkPlatformFrameworkPaths() #5876

Merged
merged 1 commit into from
Dec 8, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions Sources/Commands/Utilities/TestingSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ enum TestingSupport {
),
sanitizers: sanitizers
)
// Add the sdk platform path if we have it. If this is not present, we
// might always end up failing.
if let sdkPlatformFrameworksPath = try Destination.sdkPlatformFrameworkPaths() {
// appending since we prefer the user setting (if set) to the one we inject
env.appendPath("DYLD_FRAMEWORK_PATH", value: sdkPlatformFrameworksPath.fwk.pathString)
env.appendPath("DYLD_LIBRARY_PATH", value: sdkPlatformFrameworksPath.lib.pathString)
}

// Add the sdk platform path if we have it. If this is not present, we might always end up failing.
let sdkPlatformFrameworksPath = try Destination.sdkPlatformFrameworkPaths()
// appending since we prefer the user setting (if set) to the one we inject
env.appendPath("DYLD_FRAMEWORK_PATH", value: sdkPlatformFrameworksPath.fwk.pathString)
env.appendPath("DYLD_LIBRARY_PATH", value: sdkPlatformFrameworksPath.lib.pathString)

try TSCBasic.Process.checkNonZeroExit(arguments: args, environment: env)
// Read the temporary file's content.
return try swiftTool.fileSystem.readFileContents(tempFile.path)
Expand Down
38 changes: 20 additions & 18 deletions Sources/PackageModel/Destination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,11 @@ public struct Destination: Encodable, Equatable {
var extraCCFlags: [String] = []
var extraSwiftCFlags: [String] = []
#if os(macOS)
if 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]
}
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]
#endif

#if !os(Windows)
Expand All @@ -217,26 +216,29 @@ public struct Destination: Encodable, Equatable {
/// Returns macosx sdk platform framework path.
public static func sdkPlatformFrameworkPaths(
environment: EnvironmentVariables = .process()
) throws -> (fwk: AbsolutePath, lib: AbsolutePath)? {
) throws -> (fwk: AbsolutePath, lib: AbsolutePath) {
if let path = _sdkPlatformFrameworkPath {
return path
}
let platformPath = try? TSCBasic.Process.checkNonZeroExit(
let platformPath = try TSCBasic.Process.checkNonZeroExit(
arguments: ["/usr/bin/xcrun", "--sdk", "macosx", "--show-sdk-platform-path"],
environment: environment).spm_chomp()

if let platformPath = platformPath, !platformPath.isEmpty {
// For XCTest framework.
let fwk = try AbsolutePath(validating: platformPath).appending(
components: "Developer", "Library", "Frameworks")
guard !platformPath.isEmpty else {
throw StringError("could not determine SDK platform path")
}

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

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

_sdkPlatformFrameworkPath = (fwk, lib)
}
return _sdkPlatformFrameworkPath
let sdkPlatformFrameworkPath = (fwk, lib)
_sdkPlatformFrameworkPath = sdkPlatformFrameworkPath
return sdkPlatformFrameworkPath
}

/// Cache storage for sdk platform path.
Expand Down
12 changes: 0 additions & 12 deletions Sources/SPMTestSupport/Toolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,6 @@ private func resolveBinDir() throws -> AbsolutePath {
#endif
}

extension UserToolchain {

#if os(macOS)
public var sdkPlatformFrameworksPath: AbsolutePath {
get throws {
return try Destination.sdkPlatformFrameworkPaths()!.fwk
}
}
#endif

}

extension Destination {
public static var `default`: Self {
get throws {
Expand Down
2 changes: 1 addition & 1 deletion Tests/FunctionalTests/SwiftPMXCTestHelperTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SwiftPMXCTestHelperTests: XCTestCase {

func XCTAssertXCTestHelper(_ bundlePath: AbsolutePath, testCases: NSDictionary) throws {
#if os(macOS)
let env = ["DYLD_FRAMEWORK_PATH": try UserToolchain.default.sdkPlatformFrameworksPath.pathString]
let env = ["DYLD_FRAMEWORK_PATH": try Destination.sdkPlatformFrameworkPaths().fwk.pathString]
let outputFile = bundlePath.parentDirectory.appending(component: "tests.txt")
let _ = try SwiftPMProduct.XCTestHelper.execute([bundlePath.pathString, outputFile.pathString], env: env)
guard let data = NSData(contentsOfFile: outputFile.pathString) else {
Expand Down