build_version.cc.in 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  2. #include <memory>
  3. #include "rocksdb/version.h"
  4. #include "rocksdb/utilities/object_registry.h"
  5. #include "util/string_util.h"
  6. // The build script may replace these values with real values based
  7. // on whether or not GIT is available and the platform settings
  8. static const std::string rocksdb_build_git_sha = "rocksdb_build_git_sha:@GIT_SHA@";
  9. static const std::string rocksdb_build_git_tag = "rocksdb_build_git_tag:@GIT_TAG@";
  10. #define HAS_GIT_CHANGES @GIT_MOD@
  11. #if HAS_GIT_CHANGES == 0
  12. // If HAS_GIT_CHANGES is 0, the GIT date is used.
  13. // Use the time the branch/tag was last modified
  14. static const std::string rocksdb_build_date = "rocksdb_build_date:@GIT_DATE@";
  15. #else
  16. // If HAS_GIT_CHANGES is > 0, the branch/tag has modifications.
  17. // Use the time the build was created.
  18. static const std::string rocksdb_build_date = "rocksdb_build_date:@BUILD_DATE@";
  19. #endif
  20. extern "C" {
  21. @ROCKSDB_PLUGIN_EXTERNS@
  22. } // extern "C"
  23. std::unordered_map<std::string, ROCKSDB_NAMESPACE::RegistrarFunc> ROCKSDB_NAMESPACE::ObjectRegistry::builtins_ = {
  24. @ROCKSDB_PLUGIN_BUILTINS@
  25. };
  26. namespace ROCKSDB_NAMESPACE {
  27. static void AddProperty(std::unordered_map<std::string, std::string> *props, const std::string& name) {
  28. size_t colon = name.find(":");
  29. if (colon != std::string::npos && colon > 0 && colon < name.length() - 1) {
  30. // If we found a "@:", then this property was a build-time substitution that failed. Skip it
  31. size_t at = name.find("@", colon);
  32. if (at != colon + 1) {
  33. // Everything before the colon is the name, after is the value
  34. (*props)[name.substr(0, colon)] = name.substr(colon + 1);
  35. }
  36. }
  37. }
  38. static std::unordered_map<std::string, std::string>* LoadPropertiesSet() {
  39. auto * properties = new std::unordered_map<std::string, std::string>();
  40. AddProperty(properties, rocksdb_build_git_sha);
  41. AddProperty(properties, rocksdb_build_git_tag);
  42. AddProperty(properties, rocksdb_build_date);
  43. return properties;
  44. }
  45. const std::unordered_map<std::string, std::string>& GetRocksBuildProperties() {
  46. static std::unique_ptr<std::unordered_map<std::string, std::string>> props(LoadPropertiesSet());
  47. return *props;
  48. }
  49. std::string GetRocksVersionAsString(bool with_patch) {
  50. std::string version = std::to_string(ROCKSDB_MAJOR) + "." + std::to_string(ROCKSDB_MINOR);
  51. if (with_patch) {
  52. return version + "." + std::to_string(ROCKSDB_PATCH);
  53. } else {
  54. return version;
  55. }
  56. }
  57. std::string GetRocksBuildInfoAsString(const std::string& program, bool verbose) {
  58. std::string info = program + " (RocksDB) " + GetRocksVersionAsString(true);
  59. if (verbose) {
  60. for (const auto& it : GetRocksBuildProperties()) {
  61. info.append("\n ");
  62. info.append(it.first);
  63. info.append(": ");
  64. info.append(it.second);
  65. }
  66. }
  67. return info;
  68. }
  69. } // namespace ROCKSDB_NAMESPACE