Version.cpp revision 218893
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" 16218893Sdim#include "llvm/Config/config.h" 17198092Srdivacky#include <cstring> 18198092Srdivacky#include <cstdlib> 19202879Srdivacky 20198092Srdivackyusing namespace std; 21198092Srdivacky 22198092Srdivackynamespace clang { 23198092Srdivacky 24218893Sdimstd::string getClangRepositoryPath() { 25218893Sdim#ifdef SVN_REPOSITORY 26218893Sdim llvm::StringRef URL(SVN_REPOSITORY); 27218893Sdim#else 28218893Sdim llvm::StringRef URL(""); 29218893Sdim#endif 30203955Srdivacky 31218893Sdim // If the SVN_REPOSITORY is empty, try to use the SVN keyword. This helps us 32218893Sdim // pick up a tag in an SVN export, for example. 33218893Sdim static llvm::StringRef SVNRepository("$URL: http://llvm.org/svn/llvm-project/cfe/trunk/lib/Basic/Version.cpp $"); 34218893Sdim if (URL.empty()) { 35218893Sdim URL = SVNRepository.slice(SVNRepository.find(':'), 36218893Sdim SVNRepository.find("/lib/Basic")); 37218893Sdim } 38203955Srdivacky 39208600Srdivacky // Strip off version from a build from an integration branch. 40218893Sdim URL = URL.slice(0, URL.find("/src/tools/clang")); 41203955Srdivacky 42218893Sdim // Trim path prefix off, assuming path came from standard cfe path. 43218893Sdim size_t Start = URL.find("cfe/"); 44218893Sdim if (Start != llvm::StringRef::npos) 45218893Sdim URL = URL.substr(Start + 4); 46203955Srdivacky 47218893Sdim return URL; 48198092Srdivacky} 49198092Srdivacky 50203955Srdivackystd::string getClangRevision() { 51204643Srdivacky#ifdef SVN_REVISION 52218893Sdim return SVN_REVISION; 53218893Sdim#else 54218893Sdim return ""; 55204643Srdivacky#endif 56198092Srdivacky} 57198092Srdivacky 58203955Srdivackystd::string getClangFullRepositoryVersion() { 59203955Srdivacky std::string buf; 60203955Srdivacky llvm::raw_string_ostream OS(buf); 61218893Sdim std::string Path = getClangRepositoryPath(); 62218893Sdim std::string Revision = getClangRevision(); 63218893Sdim if (!Path.empty()) 64218893Sdim OS << Path; 65218893Sdim if (!Revision.empty()) { 66218893Sdim if (!Path.empty()) 67218893Sdim OS << ' '; 68218893Sdim OS << Revision; 69218893Sdim } 70204793Srdivacky return OS.str(); 71202879Srdivacky} 72202879Srdivacky 73203955Srdivackystd::string getClangFullVersion() { 74203955Srdivacky std::string buf; 75203955Srdivacky llvm::raw_string_ostream OS(buf); 76202879Srdivacky#ifdef CLANG_VENDOR 77203955Srdivacky OS << CLANG_VENDOR; 78202879Srdivacky#endif 79203955Srdivacky OS << "clang version " CLANG_VERSION_STRING " (" 80203955Srdivacky << getClangFullRepositoryVersion() << ')'; 81218893Sdim 82209107Sed#ifdef CLANG_VENDOR_SUFFIX 83209107Sed OS << CLANG_VENDOR_SUFFIX; 84218893Sdim#elif defined(CLANG_VENDOR) 85218893Sdim // If vendor supplied, include the base LLVM version as well. 86218893Sdim OS << " (based on LLVM " << PACKAGE_VERSION << ")"; 87209107Sed#endif 88218893Sdim 89204793Srdivacky return OS.str(); 90202879Srdivacky} 91203955Srdivacky 92198092Srdivacky} // end namespace clang 93