Version.cpp revision 208600
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 31208600Srdivacky // Strip off version from a build from an integration branch. 32208600Srdivacky End = strstr(URL, "/src/tools/clang"); 33199482Srdivacky if (End) 34203955Srdivacky URLEnd = End; 35203955Srdivacky 36203955Srdivacky const char *Begin = strstr(URL, "cfe/"); 37203955Srdivacky if (Begin) 38203955Srdivacky return llvm::StringRef(Begin + 4, URLEnd - Begin - 4); 39203955Srdivacky 40203955Srdivacky return llvm::StringRef(URL, URLEnd - URL); 41198092Srdivacky} 42198092Srdivacky 43203955Srdivackystd::string getClangRevision() { 44204643Srdivacky#ifdef SVN_REVISION 45204643Srdivacky if (SVN_REVISION[0] != '\0') { 46204643Srdivacky std::string revision; 47204643Srdivacky llvm::raw_string_ostream OS(revision); 48204643Srdivacky OS << strtol(SVN_REVISION, 0, 10); 49204793Srdivacky return OS.str(); 50204643Srdivacky } 51204643Srdivacky#endif 52203955Srdivacky return ""; 53198092Srdivacky} 54198092Srdivacky 55203955Srdivackystd::string getClangFullRepositoryVersion() { 56203955Srdivacky std::string buf; 57203955Srdivacky llvm::raw_string_ostream OS(buf); 58203955Srdivacky OS << getClangRepositoryPath(); 59203955Srdivacky const std::string &Revision = getClangRevision(); 60203955Srdivacky if (!Revision.empty()) 61203955Srdivacky OS << ' ' << Revision; 62204793Srdivacky return OS.str(); 63202879Srdivacky} 64202879Srdivacky 65203955Srdivackystd::string getClangFullVersion() { 66203955Srdivacky std::string buf; 67203955Srdivacky llvm::raw_string_ostream OS(buf); 68202879Srdivacky#ifdef CLANG_VENDOR 69203955Srdivacky OS << CLANG_VENDOR; 70202879Srdivacky#endif 71203955Srdivacky OS << "clang version " CLANG_VERSION_STRING " (" 72203955Srdivacky << getClangFullRepositoryVersion() << ')'; 73204793Srdivacky return OS.str(); 74202879Srdivacky} 75203955Srdivacky 76198092Srdivacky} // end namespace clang 77