Skip to content

Commit 103d275

Browse files
authored
Ensure Xcode SDK paths are set when running test targets. (#7093)
Currently, some of our code paths that run test targets don't correctly set the `DYLD_FRAMEWORK_PATH` and `DYLD_LIBRARY_PATH` arguments on macOS. This hasn't been a problem in practice because the XCTest helper tool is able to sort it out for us, but my plan with swift-testing is to run an executable directly (like we do for corelibs-xctest.) That means we'll have a code path that could potentially rely on XCTest or other Apple SDK bits, but which is not calling through the XCTest helper tool. This change hoists our setting of those arguments to a position where they are always set (on macOS only!) before we run a test target, regardless of build style. This change was previously landed as #7040 but was reverted (#7054) while we investigated a toolchain regression. We do not believe #7040 is the root cause of that issue, so this PR reapplies it.
1 parent 9c290df commit 103d275

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Sources/Commands/Utilities/TestingSupport.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ enum TestingSupport {
108108
#if os(macOS)
109109
let data: String = try withTemporaryFile { tempFile in
110110
args = [try Self.xctestHelperPath(swiftTool: swiftTool).pathString, path.pathString, tempFile.path.pathString]
111-
var env = try Self.constructTestEnvironment(
111+
let env = try Self.constructTestEnvironment(
112112
toolchain: try swiftTool.getTargetToolchain(),
113113
buildParameters: swiftTool.buildParametersForTest(
114114
enableCodeCoverage: enableCodeCoverage,
@@ -118,12 +118,6 @@ enum TestingSupport {
118118
sanitizers: sanitizers
119119
)
120120

121-
// Add the sdk platform path if we have it. If this is not present, we might always end up failing.
122-
let sdkPlatformFrameworksPath = try SwiftSDK.sdkPlatformFrameworkPaths()
123-
// appending since we prefer the user setting (if set) to the one we inject
124-
env.appendPath("DYLD_FRAMEWORK_PATH", value: sdkPlatformFrameworksPath.fwk.pathString)
125-
env.appendPath("DYLD_LIBRARY_PATH", value: sdkPlatformFrameworksPath.lib.pathString)
126-
127121
try TSCBasic.Process.checkNonZeroExit(arguments: args, environment: env)
128122
// Read the temporary file's content.
129123
return try swiftTool.fileSystem.readFileContents(AbsolutePath(tempFile.path))
@@ -180,6 +174,12 @@ enum TestingSupport {
180174
#endif
181175
return env
182176
#else
177+
// Add the sdk platform path if we have it. If this is not present, we might always end up failing.
178+
let sdkPlatformFrameworksPath = try SwiftSDK.sdkPlatformFrameworkPaths()
179+
// appending since we prefer the user setting (if set) to the one we inject
180+
env.appendPath("DYLD_FRAMEWORK_PATH", value: sdkPlatformFrameworksPath.fwk.pathString)
181+
env.appendPath("DYLD_LIBRARY_PATH", value: sdkPlatformFrameworksPath.lib.pathString)
182+
183183
// Fast path when no sanitizers are enabled.
184184
if sanitizers.isEmpty {
185185
return env

0 commit comments

Comments
 (0)