Version.cpp revision 204643
1291717Sbdrewery//===- Version.cpp - Clang Version Number -----------------------*- C++ -*-===// 2291717Sbdrewery// 3291717Sbdrewery// The LLVM Compiler Infrastructure 4291717Sbdrewery// 5291717Sbdrewery// This file is distributed under the University of Illinois Open Source 6291717Sbdrewery// License. See LICENSE.TXT for details. 7291717Sbdrewery// 8291717Sbdrewery//===----------------------------------------------------------------------===// 9291717Sbdrewery// 10291717Sbdrewery// This file defines several version-related utility functions for Clang. 11291717Sbdrewery// 12291717Sbdrewery//===----------------------------------------------------------------------===// 13291717Sbdrewery 14291717Sbdrewery#include "clang/Basic/Version.h" 15291717Sbdrewery#include "llvm/Support/raw_ostream.h" 16291717Sbdrewery#include <cstring> 17291717Sbdrewery#include <cstdlib> 18291717Sbdrewery 19291717Sbdreweryusing namespace std; 20291717Sbdrewery 21291717Sbdrewerynamespace clang { 22291717Sbdrewery 23291717Sbdreweryllvm::StringRef getClangRepositoryPath() { 24291717Sbdrewery static const char URL[] = "$URL: http://llvm.org/svn/llvm-project/cfe/trunk/lib/Basic/Version.cpp $"; 25291717Sbdrewery 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 42std::string getClangRevision() { 43#ifdef SVN_REVISION 44 if (SVN_REVISION[0] != '\0') { 45 std::string revision; 46 llvm::raw_string_ostream OS(revision); 47 OS << strtol(SVN_REVISION, 0, 10); 48 return revision; 49 } 50#endif 51 return ""; 52} 53 54std::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 64std::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