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 "llvm/Support/raw_ostream.h"
17 #include "llvm/Config/config.h"
23 std::string getClangRepositoryPath() {
24 #if defined(CLANG_REPOSITORY_STRING)
25 return CLANG_REPOSITORY_STRING;
28 StringRef URL(SVN_REPOSITORY);
33 // If the SVN_REPOSITORY is empty, try to use the SVN keyword. This helps us
34 // pick up a tag in an SVN export, for example.
35 static StringRef SVNRepository("$URL: http://llvm.org/svn/llvm-project/cfe/tags/RELEASE_32/final/lib/Basic/Version.cpp $");
37 URL = SVNRepository.slice(SVNRepository.find(':'),
38 SVNRepository.find("/lib/Basic"));
41 // Strip off version from a build from an integration branch.
42 URL = URL.slice(0, URL.find("/src/tools/clang"));
44 // Trim path prefix off, assuming path came from standard cfe path.
45 size_t Start = URL.find("cfe/");
46 if (Start != StringRef::npos)
47 URL = URL.substr(Start + 4);
53 std::string getLLVMRepositoryPath() {
54 #ifdef LLVM_REPOSITORY
55 StringRef URL(LLVM_REPOSITORY);
60 // Trim path prefix off, assuming path came from standard llvm path.
61 // Leave "llvm/" prefix to distinguish the following llvm revision from the
63 size_t Start = URL.find("llvm/");
64 if (Start != StringRef::npos)
65 URL = URL.substr(Start);
70 std::string getClangRevision() {
78 std::string getLLVMRevision() {
86 std::string getClangFullRepositoryVersion() {
88 llvm::raw_string_ostream OS(buf);
89 std::string Path = getClangRepositoryPath();
90 std::string Revision = getClangRevision();
91 if (!Path.empty() || !Revision.empty()) {
95 if (!Revision.empty()) {
102 // Support LLVM in a separate repository.
103 std::string LLVMRev = getLLVMRevision();
104 if (!LLVMRev.empty() && LLVMRev != Revision) {
106 std::string LLVMRepo = getLLVMRepositoryPath();
107 if (!LLVMRepo.empty())
108 OS << LLVMRepo << ' ';
109 OS << LLVMRev << ')';
114 std::string getClangFullVersion() {
116 llvm::raw_string_ostream OS(buf);
120 OS << "clang version " CLANG_VERSION_STRING " "
121 << getClangFullRepositoryVersion();
123 #ifdef CLANG_VENDOR_SUFFIX
124 OS << CLANG_VENDOR_SUFFIX;
125 #elif defined(CLANG_VENDOR)
126 // If vendor supplied, include the base LLVM version as well.
127 OS << " (based on LLVM " << PACKAGE_VERSION << ")";
133 std::string getClangFullCPPVersion() {
134 // The version string we report in __VERSION__ is just a compacted version of
135 // the one we report on the command line.
137 llvm::raw_string_ostream OS(buf);
141 OS << "Clang " CLANG_VERSION_STRING " " << getClangFullRepositoryVersion();
145 } // end namespace clang