Skip to content

Commit 8f4dc74

Browse files
committed
Handle -version argument
1 parent 8e534b3 commit 8f4dc74

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,15 @@ extension Driver {
570570
return
571571
}
572572

573+
if parsedOptions.hasArgument(.version) || parsedOptions.hasArgument(.version_) {
574+
// Follow gcc/clang behavior and use stdout for --version and stderr for -v.
575+
try printVersion(outputStream: &stdoutStream)
576+
return
577+
}
578+
if parsedOptions.hasArgument(.v) {
579+
try printVersion(outputStream: &stderrStream)
580+
}
581+
573582
// Plan the build.
574583
let jobs = try planBuild()
575584
if jobs.isEmpty { return }
@@ -632,6 +641,11 @@ extension Driver {
632641

633642
return try exec(path: tool, args: arguments)
634643
}
644+
645+
private func printVersion<S: OutputByteStream>(outputStream: inout S) throws {
646+
outputStream.write(try Process.checkNonZeroExit(args: swiftCompiler.pathString, "--version"))
647+
outputStream.flush()
648+
}
635649
}
636650

637651
extension Diagnostic.Message {

0 commit comments

Comments
 (0)