1 //===- Version.cpp - Clang Version Number -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines several version-related utility functions for Clang.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Basic/Version.h"
15 #include "llvm/Support/raw_ostream.h"
16 #include "llvm/Config/config.h"
22 std::string getClangRepositoryPath() {
23 #if defined(CLANG_REPOSITORY_STRING)
24 return CLANG_REPOSITORY_STRING;
27 llvm::StringRef URL(SVN_REPOSITORY);
29 llvm::StringRef URL("");
32 // If the SVN_REPOSITORY is empty, try to use the SVN keyword. This helps us
33 // pick up a tag in an SVN export, for example.
34 static llvm::StringRef SVNRepository("$URL: http://llvm.org/svn/llvm-project/cfe/trunk/lib/Basic/Version.cpp $");
36 URL = SVNRepository.slice(SVNRepository.find(':'),
37 SVNRepository.find("/lib/Basic"));
40 // Strip off version from a build from an integration branch.
41 URL = URL.slice(0, URL.find("/src/tools/clang"));
43 // Trim path prefix off, assuming path came from standard cfe path.
44 size_t Start = URL.find("cfe/");
45 if (Start != llvm::StringRef::npos)
46 URL = URL.substr(Start + 4);
52 std::string getClangRevision() {
60 std::string getClangFullRepositoryVersion() {
62 llvm::raw_string_ostream OS(buf);
63 std::string Path = getClangRepositoryPath();
64 std::string Revision = getClangRevision();
67 if (!Revision.empty()) {
75 std::string getClangFullVersion() {
77 llvm::raw_string_ostream OS(buf);
81 OS << "clang version " CLANG_VERSION_STRING " ("
82 << getClangFullRepositoryVersion() << ')';
84 #ifdef CLANG_VENDOR_SUFFIX
85 OS << CLANG_VENDOR_SUFFIX;
86 #elif defined(CLANG_VENDOR)
87 // If vendor supplied, include the base LLVM version as well.
88 OS << " (based on LLVM " << PACKAGE_VERSION << ")";
94 std::string getClangFullCPPVersion() {
95 // The version string we report in __VERSION__ is just a compacted version of
96 // the one we report on the command line.
98 llvm::raw_string_ostream OS(buf);
102 OS << "Clang " CLANG_VERSION_STRING " ("
103 << getClangFullRepositoryVersion() << ')';
107 } // end namespace clang