Version.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //===- Version.cpp - Clang Version Number -----------------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines several version-related utility functions for Clang.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/Basic/Version.h"
  14. #include "llvm/Support/raw_ostream.h"
  15. #include "llvm/Config/config.h"
  16. #include <cstring>
  17. #include <cstdlib>
  18. using namespace std;
  19. namespace clang {
  20. std::string getClangRepositoryPath() {
  21. #ifdef SVN_REPOSITORY
  22. llvm::StringRef URL(SVN_REPOSITORY);
  23. #else
  24. llvm::StringRef URL("");
  25. #endif
  26. // If the SVN_REPOSITORY is empty, try to use the SVN keyword. This helps us
  27. // pick up a tag in an SVN export, for example.
  28. static llvm::StringRef SVNRepository("$URL$");
  29. if (URL.empty()) {
  30. URL = SVNRepository.slice(SVNRepository.find(':'),
  31. SVNRepository.find("/lib/Basic"));
  32. }
  33. // Strip off version from a build from an integration branch.
  34. URL = URL.slice(0, URL.find("/src/tools/clang"));
  35. // Trim path prefix off, assuming path came from standard cfe path.
  36. size_t Start = URL.find("cfe/");
  37. if (Start != llvm::StringRef::npos)
  38. URL = URL.substr(Start + 4);
  39. return URL;
  40. }
  41. std::string getClangRevision() {
  42. #ifdef SVN_REVISION
  43. return SVN_REVISION;
  44. #else
  45. return "";
  46. #endif
  47. }
  48. std::string getClangFullRepositoryVersion() {
  49. std::string buf;
  50. llvm::raw_string_ostream OS(buf);
  51. std::string Path = getClangRepositoryPath();
  52. std::string Revision = getClangRevision();
  53. if (!Path.empty())
  54. OS << Path;
  55. if (!Revision.empty()) {
  56. if (!Path.empty())
  57. OS << ' ';
  58. OS << Revision;
  59. }
  60. return OS.str();
  61. }
  62. std::string getClangFullVersion() {
  63. std::string buf;
  64. llvm::raw_string_ostream OS(buf);
  65. #ifdef CLANG_VENDOR
  66. OS << CLANG_VENDOR;
  67. #endif
  68. OS << "clang version " CLANG_VERSION_STRING " ("
  69. << getClangFullRepositoryVersion() << ')';
  70. // If vendor supplied, include the base LLVM version as well.
  71. #ifdef CLANG_VENDOR
  72. OS << " (based on LLVM " << PACKAGE_VERSION << ")";
  73. #endif
  74. return OS.str();
  75. }
  76. } // end namespace clang