Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Sources/Basics/Concurrency/AsyncProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,12 @@ package final class AsyncProcess {
environment: Environment = .current,
outputRedirection: OutputRedirection = .collect,
startNewProcessGroup: Bool = true,
loggingHandler: LoggingHandler? = .none
loggingHandler: LoggingHandler? = .none,
workingDirectory: AbsolutePath? = nil
) {
self.arguments = arguments
self.environment = environment
self.workingDirectory = nil
self.workingDirectory = workingDirectory
self.outputRedirection = outputRedirection
self.startNewProcessGroup = startNewProcessGroup
self.loggingHandler = loggingHandler ?? AsyncProcess.loggingHandler
Expand Down Expand Up @@ -1126,13 +1127,15 @@ extension AsyncProcess {
package static func popen(
arguments: [String],
environment: Environment = .current,
loggingHandler: LoggingHandler? = .none
loggingHandler: LoggingHandler? = .none,
workingDirectory: AbsolutePath? = nil
) throws -> AsyncProcessResult {
let process = AsyncProcess(
arguments: arguments,
environment: environment,
outputRedirection: .collect,
loggingHandler: loggingHandler
loggingHandler: loggingHandler,
workingDirectory: workingDirectory
)
try process.launch()
return try process.waitUntilExit()
Expand Down
6 changes: 4 additions & 2 deletions Sources/_IntegrationTestSupport/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ public let xcodebuild: AbsolutePath = {
package func sh(
_ arguments: CustomStringConvertible...,
env: [String: String] = [:],
workingDirectory: AbsolutePath? = nil,
sourceLocation: SourceLocation = #_sourceLocation,
) throws -> ShReturnType {
let result = try _sh(arguments, env: env)
let result = try _sh(arguments, env: env, workingDirectory: workingDirectory)
let stdout = try result.utf8Output()
let stderr = try result.utf8stderrOutput()

Expand All @@ -97,6 +98,7 @@ package func sh(
package func _sh(
_ arguments: [CustomStringConvertible],
env: [String: String] = [:],
workingDirectory: AbsolutePath? = nil
) throws -> AsyncProcessResult {
var environment = Environment()

Expand All @@ -109,7 +111,7 @@ package func _sh(
}

let result = try AsyncProcess.popen(
arguments: arguments.map(\.description), environment: environment
arguments: arguments.map(\.description), environment: environment, workingDirectory: workingDirectory
)
return result
}
Expand Down
3 changes: 1 addition & 2 deletions Tests/IntegrationTests/BasicTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ private struct BasicTests {
#expect(dealerOutput.filter(\.isPlayingCardSuit).count == 10)

// Verify that the 'git status' is clean after a build.
try localFileSystem.changeCurrentWorkingDirectory(to: packagePath)
let gitOutput = try sh("git\(ProcessInfo.exeSuffix)", "status").stdout
let gitOutput = try sh("git\(ProcessInfo.exeSuffix)", "status", workingDirectory: packagePath).stdout
#expect(gitOutput.contains("nothing to commit, working tree clean"))

// Verify that another 'swift build' does nothing.
Expand Down
Loading