aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNico Weber <nicolasweber@gmx.de>2014-01-07 16:27:35 +0000
committerNico Weber <nicolasweber@gmx.de>2014-01-07 16:27:35 +0000
commitb00d66e6ac9bd12b6988fcbc1c287b0490ec97c5 (patch)
tree44c3825c005fee602e05387f46e01e70f93d57d7
parente0756452a3126d93768cc8179d3835974bb769b4 (diff)
downloadllvm-b00d66e6ac9bd12b6988fcbc1c287b0490ec97c5.zip
llvm-b00d66e6ac9bd12b6988fcbc1c287b0490ec97c5.tar.gz
llvm-b00d66e6ac9bd12b6988fcbc1c287b0490ec97c5.tar.bz2
Shorten the output of `clang-format --version`, include revision number.
Before: $ clang-format --version LLVM (http://llvm.org/): LLVM version 3.5svn Optimized build with assertions. Built Jan 3 2014 (14:28:46). Default target: x86_64-apple-darwin13.0.0 Host CPU: core-avx-i Now: $ bin/clang-format --version clang-format version 3.5 (198452) llvm-svn: 198694
-rw-r--r--clang/include/clang/Basic/Version.h3
-rw-r--r--clang/lib/Basic/Version.cpp6
-rw-r--r--clang/tools/clang-format/ClangFormat.cpp7
3 files changed, 15 insertions, 1 deletions
diff --git a/clang/include/clang/Basic/Version.h b/clang/include/clang/Basic/Version.h
index 7db8a2e..02da432 100644
--- a/clang/include/clang/Basic/Version.h
+++ b/clang/include/clang/Basic/Version.h
@@ -70,6 +70,9 @@ namespace clang {
/// and the vendor tag.
std::string getClangFullVersion();
+ /// \brief Like getClangFullVersion(), but with a custom tool name.
+ std::string getClangToolFullVersion(llvm::StringRef ToolName);
+
/// \brief Retrieves a string representing the complete clang version suitable
/// for use in the CPP __VERSION__ macro, which includes the clang version
/// number, the repository version, and the vendor tag.
diff --git a/clang/lib/Basic/Version.cpp b/clang/lib/Basic/Version.cpp
index 88b827d..bad53b1 100644
--- a/clang/lib/Basic/Version.cpp
+++ b/clang/lib/Basic/Version.cpp
@@ -116,12 +116,16 @@ std::string getClangFullRepositoryVersion() {
}
std::string getClangFullVersion() {
+ return getClangToolFullVersion("clang");
+}
+
+std::string getClangToolFullVersion(StringRef ToolName) {
std::string buf;
llvm::raw_string_ostream OS(buf);
#ifdef CLANG_VENDOR
OS << CLANG_VENDOR;
#endif
- OS << "clang version " CLANG_VERSION_STRING " "
+ OS << ToolName << " version " CLANG_VERSION_STRING " "
<< getClangFullRepositoryVersion();
// If vendor supplied, include the base LLVM version as well.
diff --git a/clang/tools/clang-format/ClangFormat.cpp b/clang/tools/clang-format/ClangFormat.cpp
index 28ff5c1..9744609 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -17,6 +17,7 @@
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/Basic/Version.h"
#include "clang/Format/Format.h"
#include "clang/Lex/Lexer.h"
#include "clang/Rewrite/Core/Rewriter.h"
@@ -255,6 +256,11 @@ static bool format(StringRef FileName) {
} // namespace format
} // namespace clang
+static void PrintVersion() {
+ raw_ostream &OS = outs();
+ OS << clang::getClangToolFullVersion("clang-format") << '\n';
+}
+
int main(int argc, const char **argv) {
llvm::sys::PrintStackTraceOnErrorSignal();
@@ -268,6 +274,7 @@ int main(int argc, const char **argv) {
I->second->setHiddenFlag(cl::ReallyHidden);
}
+ cl::SetVersionPrinter(PrintVersion);
cl::ParseCommandLineOptions(
argc, argv,
"A tool to format C/C++/Obj-C code.\n\n"