Version.cpp revision 202879
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() { 24198092Srdivacky static const char *Path = 0; 25198092Srdivacky if (Path) 26198092Srdivacky return Path; 27198092Srdivacky 28198092Srdivacky static char URL[] = "$URL: http://llvm.org/svn/llvm-project/cfe/trunk/lib/Basic/Version.cpp $"; 29198092Srdivacky char *End = strstr(URL, "/lib/Basic"); 30198092Srdivacky if (End) 31198092Srdivacky *End = 0; 32198092Srdivacky 33199482Srdivacky End = strstr(URL, "/clang/tools/clang"); 34199482Srdivacky if (End) 35199482Srdivacky *End = 0; 36199482Srdivacky 37198092Srdivacky char *Begin = strstr(URL, "cfe/"); 38198092Srdivacky if (Begin) { 39198092Srdivacky Path = Begin + 4; 40198092Srdivacky return Path; 41198092Srdivacky } 42198092Srdivacky 43198092Srdivacky Path = URL; 44198092Srdivacky return Path; 45198092Srdivacky} 46198092Srdivacky 47198092Srdivacky 48202879Srdivackyllvm::StringRef getClangRevision() { 49198092Srdivacky#ifndef SVN_REVISION 50198092Srdivacky // Subversion was not available at build time? 51202879Srdivacky return llvm::StringRef(); 52198092Srdivacky#else 53202879Srdivacky static std::string revision; 54202879Srdivacky if (revision.empty()) { 55202879Srdivacky llvm::raw_string_ostream OS(revision); 56202879Srdivacky OS << strtol(SVN_REVISION, 0, 10); 57202879Srdivacky } 58202879Srdivacky return revision; 59198092Srdivacky#endif 60198092Srdivacky} 61198092Srdivacky 62202879Srdivackyllvm::StringRef getClangFullRepositoryVersion() { 63202879Srdivacky static std::string buf; 64202879Srdivacky if (buf.empty()) { 65202879Srdivacky llvm::raw_string_ostream OS(buf); 66202879Srdivacky OS << getClangRepositoryPath(); 67202879Srdivacky llvm::StringRef Revision = getClangRevision(); 68202879Srdivacky if (!Revision.empty()) 69202879Srdivacky OS << ' ' << Revision; 70202879Srdivacky } 71202879Srdivacky return buf; 72202879Srdivacky} 73202879Srdivacky 74202879Srdivackyconst char *getClangFullVersion() { 75202879Srdivacky static std::string buf; 76202879Srdivacky if (buf.empty()) { 77202879Srdivacky llvm::raw_string_ostream OS(buf); 78202879Srdivacky#ifdef CLANG_VENDOR 79202879Srdivacky OS << CLANG_VENDOR; 80202879Srdivacky#endif 81202879Srdivacky OS << "clang version " CLANG_VERSION_STRING " (" 82202879Srdivacky << getClangFullRepositoryVersion() << ')'; 83202879Srdivacky } 84202879Srdivacky return buf.c_str(); 85202879Srdivacky} 86202879Srdivacky 87198092Srdivacky} // end namespace clang 88