Skip to content

Commit 380b953

Browse files
authored
A fix for incorrectly overriding environment variables rdar://118814900 (#7144)
A fix for incorrectly overriding environment variables rdar://118814900 ### Motivation: In SwiftPMProduct.swift, the environment variables are overridden irrespective of the "env" variables provided. ### Modifications: Move the code snippet that fills the environment variable array to an appropriate place ### Result: Environment variables are correctly populated
1 parent bf7aa9d commit 380b953

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Sources/SPMTestSupport/SwiftPMProduct.swift

+8-6
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ extension SwiftPM {
101101
env: [String: String]? = nil
102102
) throws -> ProcessResult {
103103
var environment = ProcessInfo.processInfo.environment
104-
for (key, value) in env ?? [:] {
105-
environment[key] = value
106-
}
104+
#if !os(Windows)
105+
environment["SDKROOT"] = nil
106+
#endif
107+
107108
#if Xcode
108109
// Unset these variables which causes issues when running tests via Xcode.
109110
environment["XCTestConfigurationFilePath"] = nil
@@ -114,13 +115,14 @@ extension SwiftPM {
114115
// FIXME: We use this private environment variable hack to be able to
115116
// create special conditions in swift-build for swiftpm tests.
116117
environment["SWIFTPM_TESTS_MODULECACHE"] = xctestBinaryPath.parentDirectory.pathString
117-
#if !os(Windows)
118-
environment["SDKROOT"] = nil
119-
#endif
120118

121119
// Unset the internal env variable that allows skipping certain tests.
122120
environment["_SWIFTPM_SKIP_TESTS_LIST"] = nil
123121

122+
for (key, value) in env ?? [:] {
123+
environment[key] = value
124+
}
125+
124126
var completeArgs = [xctestBinaryPath.pathString]
125127
if let packagePath = packagePath {
126128
completeArgs += ["--package-path", packagePath.pathString]

0 commit comments

Comments
 (0)