From 5da990661a4b50b9f53a39ff28c292933fdf6772 Mon Sep 17 00:00:00 2001 From: Richard Holland Date: Tue, 7 Feb 2023 16:15:57 +0000 Subject: [PATCH] version string generation --- src/ripple/protocol/BuildInfo.h | 2 +- src/ripple/protocol/impl/BuildInfo.cpp | 76 +++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/src/ripple/protocol/BuildInfo.h b/src/ripple/protocol/BuildInfo.h index cfe35d338..cc87c862c 100644 --- a/src/ripple/protocol/BuildInfo.h +++ b/src/ripple/protocol/BuildInfo.h @@ -69,7 +69,7 @@ getFullVersionString(); @return the encoded version in a 64-bit integer */ std::uint64_t -encodeSoftwareVersion(char const* const versionStr); +encodeSoftwareVersion(char const* versionStr); /** Returns this server's version packed in a 64-bit integer. */ std::uint64_t diff --git a/src/ripple/protocol/impl/BuildInfo.cpp b/src/ripple/protocol/impl/BuildInfo.cpp index 3745a9c21..6c49455d3 100644 --- a/src/ripple/protocol/impl/BuildInfo.cpp +++ b/src/ripple/protocol/impl/BuildInfo.cpp @@ -48,8 +48,77 @@ char const* const versionString = "0.0.0" std::string const& getVersionString() { - static std::string const value = [] { - std::string const s = versionString; + // if the external build engine fails to populate the version string, + // then we will do it ourselves. + static std::string generatedVersionString; + if (generatedVersionString == "" && + (versionString == std::string("0.0.0") || versionString == std::string("0.0.0+DEBUG"))) + { + std::string y = std::string(__DATE__ + 7); + std::string d = std::string(__DATE__ + 4 + + (__DATE__[4] == ' ' ? 1 : 0), + __DATE__[4] == ' ' ? 1 : 2 ); + std::string m; + switch (__DATE__[0]) + { + case 'J': + { + m = __DATE__[1] == 'a' ? "1" : + __DATE__[2] == 'n' ? "6" : "7"; + break; + } + case 'F': + { + m = "2"; + break; + } + case 'M': + { + m = __DATE__[2] == 'r' ? "3" : "5"; + break; + } + case 'A': + { + m = __DATE__[1] == 'p' ? "4" : "8"; + break; + } + case 'S': + { + m = "9"; + break; + } + case 'O': + { + m = "10"; + break; + } + case 'N': + { + m = "11"; + break; + } + case 'D': + { + m = "12"; + break; + } + default: + { + m = "13"; + break; + } + } + generatedVersionString = y + "." + m + "." + d; + generatedVersionString += "-CustomBuild"; + #ifdef DEBUG + generatedVersionString += "+DEBUG"; + #endif + } + + + static std::string const value = [&] { + std::string const s = + generatedVersionString != "" ? generatedVersionString : versionString; beast::SemanticVersion v; if (!v.parse(s) || v.print() != s) LogicError(s + ": Bad server version string"); @@ -71,8 +140,9 @@ static constexpr std::uint64_t implementationVersionIdentifierMask = 0xFFFF'0000'0000'0000LLU; std::uint64_t -encodeSoftwareVersion(char const* const versionStr) +encodeSoftwareVersion(char const* versionStr) { + std::uint64_t c = implementationVersionIdentifier; beast::SemanticVersion v;