Skip to content

Commit

Permalink
Improve Destination.sdkPlatformFrameworkPaths()
Browse files Browse the repository at this point in the history
We should not ignore errors or an empty SDK platform path since that means XCTest imports and test execution might silently fail on macOS with no indication to what the problem is. I am speculating that this may be contributing to the recent surge of tests failing by not seeing the XCTest Swift library. I am also re-enabling the disabled tests here to see if this has any practical effect, but regardless it doesn't seem reasonable to silently ignore some failure states here.

rdar://101868275
  • Loading branch information
neonichu committed Nov 4, 2022
1 parent 3c692dc commit 6ccd668
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 44 deletions.
14 changes: 7 additions & 7 deletions Sources/Commands/Utilities/TestingSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,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 @@ -167,12 +167,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 @@ -190,26 +189,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.
private static var _sdkPlatformFrameworkPath: (fwk: AbsolutePath, lib: AbsolutePath)? = nil
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: 0 additions & 2 deletions Tests/CommandsTests/BuildToolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,6 @@ final class BuildToolTests: CommandsTestCase {
}

func testBuildCompleteMessage() throws {
throw XCTSkip("This test fails to match the 'Compiling' regex; rdar://101815761")

try fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in
do {
let result = try execute([], packagePath: fixturePath)
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
2 changes: 0 additions & 2 deletions Tests/WorkspaceTests/InitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ class InitTests: XCTestCase {
}

func testNonC99NameExecutablePackage() throws {
throw XCTSkip("This test fails to find XCTAssertEqual; rdar://101868275")

try withTemporaryDirectory(removeTreeOnDeinit: true) { tempDirPath in
XCTAssertDirectoryExists(tempDirPath)

Expand Down
2 changes: 0 additions & 2 deletions Tests/WorkspaceTests/WorkspaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4291,8 +4291,6 @@ final class WorkspaceTests: XCTestCase {

// This verifies that the simplest possible loading APIs are available for package clients.
func testSimpleAPI() throws {
throw XCTSkip("This test fails to find XCTAssertEqual; rdar://101868275")

try testWithTemporaryDirectory { path in
// Create a temporary package as a test case.
let packagePath = path.appending(component: "MyPkg")
Expand Down
2 changes: 2 additions & 0 deletions Utilities/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,8 @@ def build_swiftpm_with_swiftpm(args, integrated_swift_driver):
swiftpm_args += ["-Xswiftc", "-Xfrontend", "-Xswiftc", "-disable-implicit-concurrency-module-import"]
swiftpm_args += ["-Xswiftc", "-Xfrontend", "-Xswiftc", "-disable-implicit-string-processing-module-import"]

swiftpm_args.append("--very-verbose")

# Build SwiftPM, including libSwiftPM, all the command line tools, and the current variant of PackageDescription.
call_swiftpm(args, swiftpm_args)

Expand Down

0 comments on commit 6ccd668

Please sign in to comment.