Version.cpp revision 204793
1198092Srdivacky//===- Version.cpp - Clang Version Number -----------------------*- C++ -*-===// 2198092Srdivacky// 3198092Srdivacky// The LLVM Compiler Infrastructure 4198092Srdivacky// 5198092Srdivacky// This file is distributed under the University of Illinois Open Source 6198092Srdivacky// License. See LICENSE.TXT for details. 7198092Srdivacky// 8198092Srdivacky//===----------------------------------------------------------------------===// 9198092Srdivacky// 10198092Srdivacky// This file defines several version-related utility functions for Clang. 11198092Srdivacky// 12198092Srdivacky//===----------------------------------------------------------------------===// 13202879Srdivacky 14202879Srdivacky#include "clang/Basic/Version.h" 15202879Srdivacky#include "llvm/Support/raw_ostream.h" 16198092Srdivacky#include <cstring> 17198092Srdivacky#include <cstdlib> 18202879Srdivacky 19198092Srdivackyusing namespace std; 20198092Srdivacky 21198092Srdivackynamespace clang { 22198092Srdivacky 23202879Srdivackyllvm::StringRef getClangRepositoryPath() { 24203955Srdivacky static const char URL[] = "$URL: http://llvm.org/svn/llvm-project/cfe/trunk/lib/Basic/Version.cpp $"; 25203955Srdivacky const char *URLEnd = URL + strlen(URL); 26203955Srdivacky 27203955Srdivacky const char *End = strstr(URL, "/lib/Basic"); 28198092Srdivacky if (End) 29203955Srdivacky URLEnd = End; 30203955Srdivacky 31199482Srdivacky End = strstr(URL, "/clang/tools/clang"); 32199482Srdivacky if (End) 33203955Srdivacky URLEnd = End; 34203955Srdivacky 35203955Srdivacky const char *Begin = strstr(URL, "cfe/"); 36203955Srdivacky if (Begin) 37203955Srdivacky return llvm::StringRef(Begin + 4, URLEnd - Begin - 4); 38203955Srdivacky 39203955Srdivacky return llvm::StringRef(URL, URLEnd - URL); 40198092Srdivacky} 41198092Srdivacky 42203955Srdivackystd::string getClangRevision() { 43204643Srdivacky#ifdef SVN_REVISION 44204643Srdivacky if (SVN_REVISION[0] != '\0') { 45204643Srdivacky std::string revision; 46204643Srdivacky llvm::raw_string_ostream OS(revision); 47204643Srdivacky OS << strtol(SVN_REVISION, 0, 10); 48204793Srdivacky return OS.str(); 49204643Srdivacky } 50204643Srdivacky#endif 51203955Srdivacky return ""; 52198092Srdivacky} 53198092Srdivacky 54203955Srdivackystd::string getClangFullRepositoryVersion() { 55203955Srdivacky std::string buf; 56203955Srdivacky llvm::raw_string_ostream OS(buf); 57203955Srdivacky OS << getClangRepositoryPath(); 58203955Srdivacky const std::string &Revision = getClangRevision(); 59203955Srdivacky if (!Revision.empty()) 60203955Srdivacky OS << ' ' << Revision; 61204793Srdivacky return OS.str(); 62202879Srdivacky} 63202879Srdivacky 64203955Srdivackystd::string getClangFullVersion() { 65203955Srdivacky std::string buf; 66203955Srdivacky llvm::raw_string_ostream OS(buf); 67202879Srdivacky#ifdef CLANG_VENDOR 68203955Srdivacky OS << CLANG_VENDOR; 69202879Srdivacky#endif 70203955Srdivacky OS << "clang version " CLANG_VERSION_STRING " (" 71203955Srdivacky << getClangFullRepositoryVersion() << ')'; 72204793Srdivacky return OS.str(); 73202879Srdivacky} 74203955Srdivacky 75198092Srdivacky} // end namespace clang 76