Skip to content

Commit 2812780

Browse files
committed
Improve Destination.sdkPlatformFrameworkPaths()
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
1 parent 3c692dc commit 2812780

File tree

7 files changed

+28
-44
lines changed

7 files changed

+28
-44
lines changed

Sources/Commands/Utilities/TestingSupport.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ enum TestingSupport {
8181
),
8282
sanitizers: sanitizers
8383
)
84-
// Add the sdk platform path if we have it. If this is not present, we
85-
// might always end up failing.
86-
if let sdkPlatformFrameworksPath = try Destination.sdkPlatformFrameworkPaths() {
87-
// appending since we prefer the user setting (if set) to the one we inject
88-
env.appendPath("DYLD_FRAMEWORK_PATH", value: sdkPlatformFrameworksPath.fwk.pathString)
89-
env.appendPath("DYLD_LIBRARY_PATH", value: sdkPlatformFrameworksPath.lib.pathString)
90-
}
84+
85+
// Add the sdk platform path if we have it. If this is not present, we might always end up failing.
86+
let sdkPlatformFrameworksPath = try Destination.sdkPlatformFrameworkPaths()
87+
// appending since we prefer the user setting (if set) to the one we inject
88+
env.appendPath("DYLD_FRAMEWORK_PATH", value: sdkPlatformFrameworksPath.fwk.pathString)
89+
env.appendPath("DYLD_LIBRARY_PATH", value: sdkPlatformFrameworksPath.lib.pathString)
90+
9191
try TSCBasic.Process.checkNonZeroExit(arguments: args, environment: env)
9292
// Read the temporary file's content.
9393
return try swiftTool.fileSystem.readFileContents(tempFile.path)

Sources/PackageModel/Destination.swift

+20-18
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,11 @@ public struct Destination: Encodable, Equatable {
167167
var extraCCFlags: [String] = []
168168
var extraSwiftCFlags: [String] = []
169169
#if os(macOS)
170-
if let sdkPaths = try Destination.sdkPlatformFrameworkPaths(environment: environment) {
171-
extraCCFlags += ["-F", sdkPaths.fwk.pathString]
172-
extraSwiftCFlags += ["-F", sdkPaths.fwk.pathString]
173-
extraSwiftCFlags += ["-I", sdkPaths.lib.pathString]
174-
extraSwiftCFlags += ["-L", sdkPaths.lib.pathString]
175-
}
170+
let sdkPaths = try Destination.sdkPlatformFrameworkPaths(environment: environment)
171+
extraCCFlags += ["-F", sdkPaths.fwk.pathString]
172+
extraSwiftCFlags += ["-F", sdkPaths.fwk.pathString]
173+
extraSwiftCFlags += ["-I", sdkPaths.lib.pathString]
174+
extraSwiftCFlags += ["-L", sdkPaths.lib.pathString]
176175
#endif
177176

178177
#if !os(Windows)
@@ -190,26 +189,29 @@ public struct Destination: Encodable, Equatable {
190189
/// Returns macosx sdk platform framework path.
191190
public static func sdkPlatformFrameworkPaths(
192191
environment: EnvironmentVariables = .process()
193-
) throws -> (fwk: AbsolutePath, lib: AbsolutePath)? {
192+
) throws -> (fwk: AbsolutePath, lib: AbsolutePath) {
194193
if let path = _sdkPlatformFrameworkPath {
195194
return path
196195
}
197-
let platformPath = try? TSCBasic.Process.checkNonZeroExit(
196+
let platformPath = try TSCBasic.Process.checkNonZeroExit(
198197
arguments: ["/usr/bin/xcrun", "--sdk", "macosx", "--show-sdk-platform-path"],
199198
environment: environment).spm_chomp()
200199

201-
if let platformPath = platformPath, !platformPath.isEmpty {
202-
// For XCTest framework.
203-
let fwk = try AbsolutePath(validating: platformPath).appending(
204-
components: "Developer", "Library", "Frameworks")
200+
guard !platformPath.isEmpty else {
201+
throw StringError("could not determine SDK platform path")
202+
}
203+
204+
// For XCTest framework.
205+
let fwk = try AbsolutePath(validating: platformPath).appending(
206+
components: "Developer", "Library", "Frameworks")
205207

206-
// For XCTest Swift library.
207-
let lib = try AbsolutePath(validating: platformPath).appending(
208-
components: "Developer", "usr", "lib")
208+
// For XCTest Swift library.
209+
let lib = try AbsolutePath(validating: platformPath).appending(
210+
components: "Developer", "usr", "lib")
209211

210-
_sdkPlatformFrameworkPath = (fwk, lib)
211-
}
212-
return _sdkPlatformFrameworkPath
212+
let sdkPlatformFrameworkPath = (fwk, lib)
213+
_sdkPlatformFrameworkPath = sdkPlatformFrameworkPath
214+
return sdkPlatformFrameworkPath
213215
}
214216
/// Cache storage for sdk platform path.
215217
private static var _sdkPlatformFrameworkPath: (fwk: AbsolutePath, lib: AbsolutePath)? = nil

Sources/SPMTestSupport/Toolchain.swift

-12
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,6 @@ private func resolveBinDir() throws -> AbsolutePath {
3333
#endif
3434
}
3535

36-
extension UserToolchain {
37-
38-
#if os(macOS)
39-
public var sdkPlatformFrameworksPath: AbsolutePath {
40-
get throws {
41-
return try Destination.sdkPlatformFrameworkPaths()!.fwk
42-
}
43-
}
44-
#endif
45-
46-
}
47-
4836
extension Destination {
4937
public static var `default`: Self {
5038
get throws {

Tests/CommandsTests/BuildToolTests.swift

-2
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,6 @@ final class BuildToolTests: CommandsTestCase {
280280
}
281281

282282
func testBuildCompleteMessage() throws {
283-
throw XCTSkip("This test fails to match the 'Compiling' regex; rdar://101815761")
284-
285283
try fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in
286284
do {
287285
let result = try execute([], packagePath: fixturePath)

Tests/FunctionalTests/SwiftPMXCTestHelperTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class SwiftPMXCTestHelperTests: XCTestCase {
4949

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

Tests/WorkspaceTests/InitTests.swift

-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@ class InitTests: XCTestCase {
266266
}
267267

268268
func testNonC99NameExecutablePackage() throws {
269-
throw XCTSkip("This test fails to find XCTAssertEqual; rdar://101868275")
270-
271269
try withTemporaryDirectory(removeTreeOnDeinit: true) { tempDirPath in
272270
XCTAssertDirectoryExists(tempDirPath)
273271

Tests/WorkspaceTests/WorkspaceTests.swift

-2
Original file line numberDiff line numberDiff line change
@@ -4291,8 +4291,6 @@ final class WorkspaceTests: XCTestCase {
42914291

42924292
// This verifies that the simplest possible loading APIs are available for package clients.
42934293
func testSimpleAPI() throws {
4294-
throw XCTSkip("This test fails to find XCTAssertEqual; rdar://101868275")
4295-
42964294
try testWithTemporaryDirectory { path in
42974295
// Create a temporary package as a test case.
42984296
let packagePath = path.appending(component: "MyPkg")

0 commit comments

Comments
 (0)