Skip to content

Commit fc8d089

Browse files
committed
Don’t override environment variables when spawning
1 parent b738d79 commit fc8d089

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Sources/POSIX/system.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,16 @@ public func system() {}
4545

4646
/// Convenience wrapper for posix_spawn.
4747
func posix_spawnp(path: String, args: [String], environment: [String: String] = [:], fileActions: posix_spawn_file_actions_t? = nil) throws -> pid_t {
48-
var environment = environment
4948
let argv = args.map{ $0.withCString(strdup) }
5049
defer { for arg in argv { free(arg) } }
5150

51+
var environment = environment
5252
for key in ["PATH", "SDKROOT", "TOOLCHAINS", "HOME", "SWIFT_EXEC",
5353
// FIXME these
5454
"SPM_INSTALL_PATH", "SWIFT_BUILD_TOOL"] {
55-
environment[key] = POSIX.getenv(key)
55+
if environment[key] == nil {
56+
environment[key] = POSIX.getenv(key)
57+
}
5658
}
5759

5860
let env = environment.map{ "\($0.0)=\($0.1)".withCString(strdup) }

0 commit comments

Comments
 (0)