Version.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.split(':').second;
  31. // Strip off version from a build from an integration branch.
  32. URL = URL.slice(0, URL.find("/src/tools/clang"));
  33. // Trim path prefix off, assuming path came from standard cfe path.
  34. size_t Start = URL.find("cfe/");
  35. if (Start != llvm::StringRef::npos)
  36. URL = URL.substr(Start + 4);
  37. return URL;
  38. }
  39. std::string getClangRevision() {
  40. #ifdef SVN_REVISION
  41. return SVN_REVISION;
  42. #else
  43. return "";
  44. #endif
  45. }
  46. std::string getClangFullRepositoryVersion() {
  47. std::string buf;
  48. llvm::raw_string_ostream OS(buf);
  49. std::string Path = getClangRepositoryPath();
  50. std::string Revision = getClangRevision();
  51. if (!Path.empty())
  52. OS << Path;
  53. if (!Revision.empty()) {
  54. if (!Path.empty())
  55. OS << ' ';
  56. OS << Revision;
  57. }
  58. return OS.str();
  59. }
  60. std::string getClangFullVersion() {
  61. std::string buf;
  62. llvm::raw_string_ostream OS(buf);
  63. #ifdef CLANG_VENDOR
  64. OS << CLANG_VENDOR;
  65. #endif
  66. OS << "clang version " CLANG_VERSION_STRING " ("
  67. << getClangFullRepositoryVersion() << ')';
  68. // If vendor supplied, include the base LLVM version as well.
  69. #ifdef CLANG_VENDOR
  70. OS << " (based on LLVM " << PACKAGE_VERSION << ")";
  71. #endif
  72. return OS.str();
  73. }
  74. } // end namespace clang