2019-04-18 17:51:19 +00:00
|
|
|
// Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
|
2021-01-29 01:40:24 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "rocksdb/version.h"
|
2022-04-11 20:44:09 +00:00
|
|
|
#include "rocksdb/utilities/object_registry.h"
|
2021-01-29 01:40:24 +00:00
|
|
|
#include "util/string_util.h"
|
|
|
|
|
|
|
|
// The build script may replace these values with real values based
|
|
|
|
// on whether or not GIT is available and the platform settings
|
|
|
|
static const std::string rocksdb_build_git_sha = "rocksdb_build_git_sha:@GIT_SHA@";
|
|
|
|
static const std::string rocksdb_build_git_tag = "rocksdb_build_git_tag:@GIT_TAG@";
|
|
|
|
#define HAS_GIT_CHANGES @GIT_MOD@
|
|
|
|
#if HAS_GIT_CHANGES == 0
|
|
|
|
// If HAS_GIT_CHANGES is 0, the GIT date is used.
|
|
|
|
// Use the time the branch/tag was last modified
|
|
|
|
static const std::string rocksdb_build_date = "rocksdb_build_date:@GIT_DATE@";
|
|
|
|
#else
|
|
|
|
// If HAS_GIT_CHANGES is > 0, the branch/tag has modifications.
|
|
|
|
// Use the time the build was created.
|
|
|
|
static const std::string rocksdb_build_date = "rocksdb_build_date:@BUILD_DATE@";
|
|
|
|
#endif
|
|
|
|
|
2022-04-11 20:44:09 +00:00
|
|
|
extern "C" {
|
|
|
|
@ROCKSDB_PLUGIN_EXTERNS@
|
|
|
|
} // extern "C"
|
|
|
|
|
|
|
|
std::unordered_map<std::string, ROCKSDB_NAMESPACE::RegistrarFunc> ROCKSDB_NAMESPACE::ObjectRegistry::builtins_ = {
|
2022-05-06 20:03:58 +00:00
|
|
|
@ROCKSDB_PLUGIN_BUILTINS@
|
2022-04-11 20:44:09 +00:00
|
|
|
};
|
|
|
|
|
2021-01-29 01:40:24 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
|
|
|
static void AddProperty(std::unordered_map<std::string, std::string> *props, const std::string& name) {
|
|
|
|
size_t colon = name.find(":");
|
|
|
|
if (colon != std::string::npos && colon > 0 && colon < name.length() - 1) {
|
|
|
|
// If we found a "@:", then this property was a build-time substitution that failed. Skip it
|
|
|
|
size_t at = name.find("@", colon);
|
|
|
|
if (at != colon + 1) {
|
|
|
|
// Everything before the colon is the name, after is the value
|
|
|
|
(*props)[name.substr(0, colon)] = name.substr(colon + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-06 20:03:58 +00:00
|
|
|
|
2021-01-29 01:40:24 +00:00
|
|
|
static std::unordered_map<std::string, std::string>* LoadPropertiesSet() {
|
|
|
|
auto * properties = new std::unordered_map<std::string, std::string>();
|
|
|
|
AddProperty(properties, rocksdb_build_git_sha);
|
|
|
|
AddProperty(properties, rocksdb_build_git_tag);
|
|
|
|
AddProperty(properties, rocksdb_build_date);
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::unordered_map<std::string, std::string>& GetRocksBuildProperties() {
|
|
|
|
static std::unique_ptr<std::unordered_map<std::string, std::string>> props(LoadPropertiesSet());
|
|
|
|
return *props;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GetRocksVersionAsString(bool with_patch) {
|
2022-05-06 20:03:58 +00:00
|
|
|
std::string version = std::to_string(ROCKSDB_MAJOR) + "." + std::to_string(ROCKSDB_MINOR);
|
2021-01-29 01:40:24 +00:00
|
|
|
if (with_patch) {
|
2022-05-06 20:03:58 +00:00
|
|
|
return version + "." + std::to_string(ROCKSDB_PATCH);
|
2021-01-29 01:40:24 +00:00
|
|
|
} else {
|
|
|
|
return version;
|
2022-04-11 20:44:09 +00:00
|
|
|
}
|
2021-01-29 01:40:24 +00:00
|
|
|
}
|
2022-05-06 20:03:58 +00:00
|
|
|
|
2021-01-29 01:40:24 +00:00
|
|
|
std::string GetRocksBuildInfoAsString(const std::string& program, bool verbose) {
|
|
|
|
std::string info = program + " (RocksDB) " + GetRocksVersionAsString(true);
|
|
|
|
if (verbose) {
|
|
|
|
for (const auto& it : GetRocksBuildProperties()) {
|
|
|
|
info.append("\n ");
|
|
|
|
info.append(it.first);
|
|
|
|
info.append(": ");
|
|
|
|
info.append(it.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|