Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in Process.checkRun of CartonDriver #463

Merged
merged 1 commit into from
May 20, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import CartonHelpers
import Foundation
import SwiftToolchain

struct CartonCommandError: Error & CustomStringConvertible {
struct CartonDriverError: Error & CustomStringConvertible {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

driverと呼ぶことに決まったので、
ソースファイル名とエラーの名前を変えました

init(_ description: String) {
self.description = description
}
Expand All @@ -45,9 +45,10 @@ extension Foundation.Process {
internal static func checkRun(
_ executableURL: URL, arguments: [String], forwardExit: Bool = false
) throws {
fputs(
"Running \(([executableURL.path] + arguments).map { "\"\($0)\"" }.joined(separator: " "))\n",
stderr)
let commandLine: String = ([executableURL.path] + arguments)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

後でエラー出力にも使いたいので変数に出しました

.map { "\"\($0)\"" }.joined(separator: " ")

fputs("Running \(commandLine)\n", stderr)
fflush(stderr)

let process = Foundation.Process()
Expand All @@ -67,18 +68,19 @@ extension Foundation.Process {
setSignalForwarding(SIGINT)
setSignalForwarding(SIGTERM)

if forwardExit {
process.terminationHandler = {
// Exit plugin process itself when child process exited
exit($0.terminationStatus)
}
}
try process.run()
process.waitUntilExit()

if process.terminationStatus != 0 {
if forwardExit {
exit(process.terminationStatus)
}

if process.terminationStatus != 0 {
throw CartonDriverError(
"Process failed with status \(process.terminationStatus).\n" +
"Command line: \(commandLine)"
)
}
}
}

Expand Down Expand Up @@ -156,7 +158,7 @@ func makeTemporaryFile(prefix: String, in directory: URL? = nil) throws -> URL {
copy[template.count] = 0
guard mkstemp(copy.baseAddress!) != -1 else {
let error = errnoString
throw CartonCommandError("Failed to make a temporary file at \(template): \(error)")
throw CartonDriverError("Failed to make a temporary file at \(template): \(error)")
}
return String(cString: copy.baseAddress!)
}
Expand Down