Skip to content

Commit 7e553fa

Browse files
committed
Fix compile errors with the new Subprocess version
1 parent 9579809 commit 7e553fa

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

Sources/SwiftlyCore/Platform+Process.swift

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,23 @@ extension Platform {
103103
public func runProgram(_ args: [String], quiet: Bool = false, env: [String: String]? = nil)
104104
async throws
105105
{
106+
let environment: Subprocess.Environment = if let env {
107+
.inherit.updating(
108+
.init(
109+
uniqueKeysWithValues: env.map {
110+
(Subprocess.Environment.Key(stringLiteral: $0.key), Optional($0.value))
111+
}
112+
)
113+
)
114+
} else {
115+
.inherit
116+
}
117+
106118
if !quiet {
107119
let result = try await run(
108120
.path("/usr/bin/env"),
109121
arguments: .init(args),
110-
environment: env != nil ? .inherit.updating(env ?? [:]) : .inherit,
122+
environment: environment,
111123
input: .fileDescriptor(.standardInput, closeAfterSpawningProcess: false),
112124
output: .fileDescriptor(.standardOutput, closeAfterSpawningProcess: false),
113125
error: .fileDescriptor(.standardError, closeAfterSpawningProcess: false),
@@ -120,7 +132,7 @@ extension Platform {
120132
let result = try await run(
121133
.path("/usr/bin/env"),
122134
arguments: .init(args),
123-
environment: env != nil ? .inherit.updating(env ?? [:]) : .inherit,
135+
environment: environment,
124136
output: .discarded,
125137
error: .discarded,
126138
)
@@ -152,10 +164,22 @@ extension Platform {
152164
public func runProgramOutput(_ program: String, _ args: [String], env: [String: String]? = nil)
153165
async throws -> String?
154166
{
167+
let environment: Subprocess.Environment = if let env {
168+
.inherit.updating(
169+
.init(
170+
uniqueKeysWithValues: env.map {
171+
(Subprocess.Environment.Key(stringLiteral: $0.key), Optional($0.value))
172+
}
173+
)
174+
)
175+
} else {
176+
.inherit
177+
}
178+
155179
let result = try await run(
156180
.path("/usr/bin/env"),
157181
arguments: .init([program] + args),
158-
environment: env != nil ? .inherit.updating(env ?? [:]) : .inherit,
182+
environment: environment,
159183
output: .string(limit: 10 * 1024 * 1024, encoding: UTF8.self),
160184
error: .fileDescriptor(.standardError, closeAfterSpawningProcess: false)
161185
)

0 commit comments

Comments
 (0)