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