Skip to content

Commit 4fffbeb

Browse files
committed
Handle -version argument
1 parent 52eff70 commit 4fffbeb

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,17 @@ extension Driver {
566566
return
567567
}
568568

569+
if parsedOptions.hasArgument(.version) || parsedOptions.hasArgument(.version_) {
570+
// Follow gcc/clang behavior and use stdout for --version and stderr for -v.
571+
printVersion(outputStream: &stdoutStream)
572+
stdoutStream.flush()
573+
return
574+
}
575+
if parsedOptions.hasArgument(.v) {
576+
printVersion(outputStream: &stderrStream)
577+
// SuppressNoInputFilesError = true;
578+
}
579+
569580
// Plan the build.
570581
let jobs = try planBuild()
571582
if jobs.isEmpty { return }
@@ -634,6 +645,18 @@ extension Driver {
634645

635646
return try exec(path: tool, args: arguments)
636647
}
648+
649+
private func printVersion<S: TextOutputStream>(outputStream: inout S) {
650+
// OS << version::getSwiftFullVersion(version::Version::getCurrentLanguageVersion()) << '\n';
651+
// OS << "Target: " << TC.getTriple().str() << '\n';
652+
653+
// TODO: don't hardcode
654+
outputStream.write("Apple Swift version 5.1.2 (swiftlang-1100.0.278 clang-1100.0.33.9)")
655+
outputStream.write("\n")
656+
outputStream.write("Target: ")
657+
outputStream.write(targetTriple.triple)
658+
outputStream.write("\n")
659+
}
637660
}
638661

639662
extension Diagnostic.Message {

0 commit comments

Comments
 (0)