Version.cpp 2.0 KB

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