diff options
Diffstat (limited to 'src/mongo/util')
-rw-r--r-- | src/mongo/util/version.cpp | 25 | ||||
-rw-r--r-- | src/mongo/util/version.h | 27 | ||||
-rw-r--r-- | src/mongo/util/version_constants.h.in | 29 | ||||
-rw-r--r-- | src/mongo/util/version_impl.cpp | 14 |
4 files changed, 44 insertions, 51 deletions
diff --git a/src/mongo/util/version.cpp b/src/mongo/util/version.cpp index 5a4c3d96250..a2c17c5e93c 100644 --- a/src/mongo/util/version.cpp +++ b/src/mongo/util/version.cpp @@ -96,7 +96,7 @@ public: return "unknown"; } - std::vector<BuildInfoTuple> buildInfo() const final { + std::vector<BuildInfoField> buildInfo() const final { return {}; } }; @@ -175,13 +175,12 @@ void VersionInfoInterface::appendBuildInfo(BSONObjBuilder* result) const { #endif opensslInfo.done(); - BSONObjBuilder buildvarsInfo(result->subobjStart("buildEnvironment")); - for (auto&& envDataEntry : buildInfo()) { - if (std::get<2>(envDataEntry)) { - buildvarsInfo << std::get<0>(envDataEntry) << std::get<1>(envDataEntry); - } + { + BSONObjBuilder env(result->subobjStart("buildEnvironment")); + for (auto&& e : buildInfo()) + if (e.inBuildInfo) + env.append(e.key, e.value); } - buildvarsInfo.done(); *result << "bits" << (int)sizeof(void*) * 8; result->appendBool("debug", kDebugBuild); @@ -218,20 +217,12 @@ void VersionInfoInterface::logBuildInfo() const { auto build = buildInfo(); - auto envFilter = [](const BuildInfoTuple& bi) -> bool { - if (std::get<3>(bi)) - return std::get<1>(bi).size() != 0; - return false; - }; + auto envFilter = [](auto&& bi) { return bi.inBuildInfo && !bi.value.empty(); }; auto filtered_begin = boost::make_filter_iterator(envFilter, build.begin(), build.end()); auto filtered_end = boost::make_filter_iterator(envFilter, build.end(), build.end()); - auto envFormatter = [](const BuildInfoTuple& bi) { - BSONObjBuilder builder; - builder.append(std::get<0>(bi), std::get<1>(bi)); - return builder.obj(); - }; + auto envFormatter = [](auto&& bi) { return BSONObjBuilder{}.append(bi.key, bi.value).obj(); }; auto begin = boost::make_transform_iterator(filtered_begin, envFormatter); auto end = boost::make_transform_iterator(filtered_end, envFormatter); diff --git a/src/mongo/util/version.h b/src/mongo/util/version.h index e6726132ced..a9a2f0084cd 100644 --- a/src/mongo/util/version.h +++ b/src/mongo/util/version.h @@ -31,7 +31,6 @@ #define UTIL_VERSION_HEADER #include <string> -#include <tuple> #include <vector> #include "mongo/base/string_data.h" @@ -46,12 +45,21 @@ class BSONObjBuilder; * able to access version information. */ class VersionInfoInterface { - VersionInfoInterface(const VersionInfoInterface&) = delete; - VersionInfoInterface& operator=(const VersionInfoInterface&) = delete; - public: - using BuildInfoTuple = std::tuple<StringData, StringData, bool, bool>; + struct BuildInfoField { + StringData key; + StringData value; + bool inBuildInfo; // included in buildInfo BSON + bool inVersion; // included in --version output + }; + + enum class NotEnabledAction { + kAbortProcess, + kFallback, + }; + VersionInfoInterface(const VersionInfoInterface&) = delete; + VersionInfoInterface& operator=(const VersionInfoInterface&) = delete; virtual ~VersionInfoInterface() = default; /** @@ -60,11 +68,6 @@ public: */ static void enable(const VersionInfoInterface* handler); - enum class NotEnabledAction { - kAbortProcess, - kFallback, - }; - /** * Obtain the currently configured instance of the VersionInfoInterface. By default, if this * method is called and no implementation has been configured with the 'enable' method above, @@ -126,9 +129,9 @@ public: virtual StringData targetMinOS() const noexcept = 0; /** - * Returns a vector of tuples describing build information (e.g. LINKFLAGS, compiler, etc.). + * Returns build information (e.g. LINKFLAGS, compiler, etc.). */ - virtual std::vector<BuildInfoTuple> buildInfo() const = 0; + virtual std::vector<BuildInfoField> buildInfo() const = 0; /** * Returns the version of OpenSSL in use, if any, adorned with the provided prefix and suffix. diff --git a/src/mongo/util/version_constants.h.in b/src/mongo/util/version_constants.h.in index 88497eebf68..b0521bfacc6 100644 --- a/src/mongo/util/version_constants.h.in +++ b/src/mongo/util/version_constants.h.in @@ -27,21 +27,14 @@ * it in the license file. */ -#include <initializer_list> +#include <vector> #include "mongo/base/string_data.h" -// NOTE: You almost certainly don't want to include this file directly. Instead, access this -// information via the VersionInfoInterface singleton. To enforce this restriction we only allow -// inclusion of this file from files that have explicitly whitelisted it. Additionally, since this -// file is only ever included in .cpp files, it makes some sense to use an unnamed namespace here. - -#ifndef MONGO_UTIL_VERSION_CONSTANTS_H_WHITELISTED -#error "Cannot include mongo/util/version_constants.h" -#endif +// This file is expanded by a Scons generator as a detail of version_impl.cpp. +// Access this information via the VersionInfoInterface singleton. namespace mongo::version { -namespace { constexpr auto kVersion = "@mongo_version@"_sd; constexpr int kMajorVersion = @mongo_version_major@; @@ -53,10 +46,16 @@ constexpr auto kGitVersion = "@mongo_git_hash@"_sd; constexpr auto kAllocator = "@buildinfo_allocator@"_sd; constexpr auto kJsEngine = "@buildinfo_js_engine@"_sd; -// TODO: Consider making these constexpr too. -const std::initializer_list<StringData> kModulesList = @buildinfo_modules@; -const std::initializer_list<VersionInfoInterface::BuildInfoTuple> kBuildEnvironment = - @buildinfo_environment_data@; +inline std::vector<StringData> modulesList() { + return { +@buildinfo_modules@ + }; +} + +inline std::vector<VersionInfoInterface::BuildInfoField> buildEnvironment() { + return { +@buildinfo_environment_data@ + }; +} -} // namespace } // namespace mongo::version diff --git a/src/mongo/util/version_impl.cpp b/src/mongo/util/version_impl.cpp index 27ae1706caf..9273da65b47 100644 --- a/src/mongo/util/version_impl.cpp +++ b/src/mongo/util/version_impl.cpp @@ -37,13 +37,12 @@ #include "mongo/logv2/log.h" #include "mongo/util/assert_util.h" -#define MONGO_UTIL_VERSION_CONSTANTS_H_WHITELISTED #include "mongo/util/version_constants.h" namespace mongo { namespace { -const class : public VersionInfoInterface { +class InterpolatedVersionInfo : public VersionInfoInterface { public: int majorVersion() const noexcept final { return version::kMajorVersion; @@ -70,7 +69,7 @@ public: } std::vector<StringData> modules() const final { - return version::kModulesList; + return version::modulesList(); } StringData allocator() const noexcept final { @@ -94,17 +93,18 @@ public: #endif } - std::vector<BuildInfoTuple> buildInfo() const final { - return version::kBuildEnvironment; + std::vector<BuildInfoField> buildInfo() const final { + return version::buildEnvironment(); } +}; -} kInterpolatedVersionInfo{}; +const InterpolatedVersionInfo interpolatedVersionInfo; MONGO_INITIALIZER_GENERAL(EnableVersionInfo, MONGO_NO_PREREQUISITES, ("BeginStartupOptionRegistration", "GlobalLogManager")) (InitializerContext*) { - VersionInfoInterface::enable(&kInterpolatedVersionInfo); + VersionInfoInterface::enable(&interpolatedVersionInfo); return Status::OK(); } |