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 "clang/Basic/LLVM.h"
16 #include "clang/Config/config.h"
17 #include "llvm/Support/raw_ostream.h"
21 #ifdef HAVE_SVN_VERSION_INC
22 # include "SVNVersion.inc"
27 std::string getClangRepositoryPath() {
28 #if defined(CLANG_REPOSITORY_STRING)
29 return CLANG_REPOSITORY_STRING;
32 StringRef URL(SVN_REPOSITORY);
37 // If the SVN_REPOSITORY is empty, try to use the SVN keyword. This helps us
38 // pick up a tag in an SVN export, for example.
39 StringRef SVNRepository("$URL: https://llvm.org/svn/llvm-project/cfe/tags/RELEASE_371/final/lib/Basic/Version.cpp $");
41 URL = SVNRepository.slice(SVNRepository.find(':'),
42 SVNRepository.find("/lib/Basic"));
45 // Strip off version from a build from an integration branch.
46 URL = URL.slice(0, URL.find("/src/tools/clang"));
48 // Trim path prefix off, assuming path came from standard cfe path.
49 size_t Start = URL.find("cfe/");
50 if (Start != StringRef::npos)
51 URL = URL.substr(Start + 4);
57 std::string getLLVMRepositoryPath() {
58 #ifdef LLVM_REPOSITORY
59 StringRef URL(LLVM_REPOSITORY);
64 // Trim path prefix off, assuming path came from standard llvm path.
65 // Leave "llvm/" prefix to distinguish the following llvm revision from the
67 size_t Start = URL.find("llvm/");
68 if (Start != StringRef::npos)
69 URL = URL.substr(Start);
74 std::string getClangRevision() {
82 std::string getLLVMRevision() {
90 std::string getClangFullRepositoryVersion() {
92 llvm::raw_string_ostream OS(buf);
93 std::string Path = getClangRepositoryPath();
94 std::string Revision = getClangRevision();
95 if (!Path.empty() || !Revision.empty()) {
99 if (!Revision.empty()) {
106 // Support LLVM in a separate repository.
107 std::string LLVMRev = getLLVMRevision();
108 if (!LLVMRev.empty() && LLVMRev != Revision) {
110 std::string LLVMRepo = getLLVMRepositoryPath();
111 if (!LLVMRepo.empty())
112 OS << LLVMRepo << ' ';
113 OS << LLVMRev << ')';
118 std::string getClangFullVersion() {
119 return getClangToolFullVersion("clang");
122 std::string getClangToolFullVersion(StringRef ToolName) {
124 llvm::raw_string_ostream OS(buf);
128 OS << ToolName << " version " CLANG_VERSION_STRING " "
129 << getClangFullRepositoryVersion();
131 #ifdef CLANG_VENDOR_SUFFIX
132 OS << CLANG_VENDOR_SUFFIX;
133 #elif defined(CLANG_VENDOR)
134 // If vendor supplied, include the base LLVM version as well.
135 OS << " (based on " << BACKEND_PACKAGE_STRING << ")";
141 std::string getClangFullCPPVersion() {
142 // The version string we report in __VERSION__ is just a compacted version of
143 // the one we report on the command line.
145 llvm::raw_string_ostream OS(buf);
149 OS << "Clang " CLANG_VERSION_STRING " " << getClangFullRepositoryVersion();
153 } // end namespace clang