1 //===- Version.cpp - Clang Version Number -----------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines several version-related utility functions for Clang. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "clang/Basic/Version.h" 15 #include "llvm/Support/raw_ostream.h" 16 #include <cstring> 17 #include <cstdlib> 18 19 using namespace std; 20 21 namespace clang { 22 23 llvm::StringRef getClangRepositoryPath() { 24 static const char URL[] = "$URL$"; 25 const char *URLEnd = URL + strlen(URL); 26 27 const char *End = strstr(URL, "/lib/Basic"); 28 if (End) 29 URLEnd = End; 30 31 End = strstr(URL, "/clang/tools/clang"); 32 if (End) 33 URLEnd = End; 34 35 const char *Begin = strstr(URL, "cfe/"); 36 if (Begin) 37 return llvm::StringRef(Begin + 4, URLEnd - Begin - 4); 38 39 return llvm::StringRef(URL, URLEnd - URL); 40 } 41 42 43 llvm::StringRef getClangRevision() { 44 #ifndef SVN_REVISION 45 // Subversion was not available at build time? 46 return llvm::StringRef(); 47 #else 48 static std::string revision; 49 if (revision.empty()) { 50 llvm::raw_string_ostream OS(revision); 51 OS << strtol(SVN_REVISION, 0, 10); 52 } 53 return revision; 54 #endif 55 } 56 57 llvm::StringRef getClangFullRepositoryVersion() { 58 static std::string buf; 59 if (buf.empty()) { 60 llvm::raw_string_ostream OS(buf); 61 OS << getClangRepositoryPath(); 62 llvm::StringRef Revision = getClangRevision(); 63 if (!Revision.empty()) 64 OS << ' ' << Revision; 65 } 66 return buf; 67 } 68 69 const char *getClangFullVersion() { 70 static std::string buf; 71 if (buf.empty()) { 72 llvm::raw_string_ostream OS(buf); 73 #ifdef CLANG_VENDOR 74 OS << CLANG_VENDOR; 75 #endif 76 OS << "clang version " CLANG_VERSION_STRING " (" 77 << getClangFullRepositoryVersion() << ')'; 78 } 79 return buf.c_str(); 80 } 81 82 } // end namespace clang 83