Skip to content

Commit a7654db

Browse files
authored
Merge pull request #17 from apple/update
Sync with SwiftPM trunk
2 parents c7f2fbe + e046e4b commit a7654db

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Sources/TSCBasic/Process.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public struct ProcessResult: CustomStringConvertible {
3939
/// The arguments with which the process was launched.
4040
public let arguments: [String]
4141

42+
/// The environment with which the process was launched.
43+
public let environment: [String: String]
44+
4245
/// The exit status of the process.
4346
public let exitStatus: ExitStatus
4447

@@ -55,6 +58,7 @@ public struct ProcessResult: CustomStringConvertible {
5558
/// See `waitpid(2)` for information on the exit status code.
5659
public init(
5760
arguments: [String],
61+
environment: [String: String],
5862
exitStatusCode: Int32,
5963
output: Result<[UInt8], AnyError>,
6064
stderrOutput: Result<[UInt8], AnyError>
@@ -70,18 +74,20 @@ public struct ProcessResult: CustomStringConvertible {
7074
exitStatus = .terminated(code: WEXITSTATUS(exitStatusCode))
7175
}
7276
#endif
73-
self.init(arguments: arguments, exitStatus: exitStatus, output: output,
77+
self.init(arguments: arguments, environment: environment, exitStatus: exitStatus, output: output,
7478
stderrOutput: stderrOutput)
7579
}
7680

7781
/// Create an instance using an exit status and output result.
7882
public init(
7983
arguments: [String],
84+
environment: [String: String],
8085
exitStatus: ExitStatus,
8186
output: Result<[UInt8], AnyError>,
8287
stderrOutput: Result<[UInt8], AnyError>
8388
) {
8489
self.arguments = arguments
90+
self.environment = environment
8591
self.output = output
8692
self.stderrOutput = stderrOutput
8793
self.exitStatus = exitStatus
@@ -474,6 +480,7 @@ public final class Process: ObjectIdentifierProtocol {
474480
// Construct the result.
475481
let executionResult = ProcessResult(
476482
arguments: arguments,
483+
environment: environment,
477484
exitStatusCode: exitStatusCode,
478485
output: stdout.result,
479486
stderrOutput: stderr.result
@@ -657,7 +664,10 @@ extension ProcessResult.Error: CustomStringConvertible {
657664
case .signalled(let signal):
658665
stream <<< "signalled(\(signal)): "
659666
}
660-
667+
668+
stream <<< result.environment.map({ "\($0)=\($1)" }).joined(separator: " ")
669+
stream <<< " "
670+
661671
// Strip sandbox information from arguments to keep things pretty.
662672
var args = result.arguments
663673
// This seems a little fragile.

0 commit comments

Comments
 (0)