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 std::string getClangRevision() { 43 #ifndef SVN_REVISION 44 // Subversion was not available at build time? 45 return ""; 46 #else 47 std::string revision; 48 llvm::raw_string_ostream OS(revision); 49 OS << strtol(SVN_REVISION, 0, 10); 50 return revision; 51 #endif 52 } 53 54 std::string getClangFullRepositoryVersion() { 55 std::string buf; 56 llvm::raw_string_ostream OS(buf); 57 OS << getClangRepositoryPath(); 58 const std::string &Revision = getClangRevision(); 59 if (!Revision.empty()) 60 OS << ' ' << Revision; 61 return buf; 62 } 63 64 std::string getClangFullVersion() { 65 std::string buf; 66 llvm::raw_string_ostream OS(buf); 67 #ifdef CLANG_VENDOR 68 OS << CLANG_VENDOR; 69 #endif 70 OS << "clang version " CLANG_VERSION_STRING " (" 71 << getClangFullRepositoryVersion() << ')'; 72 return buf; 73 } 74 75 } // end namespace clang 76