xrpld
Loading...
Searching...
No Matches
BuildInfo.cpp
1#include <xrpl/protocol/BuildInfo.h>
2
3#include <xrpl/basics/contract.h>
4#include <xrpl/beast/core/LexicalCast.h>
5#include <xrpl/beast/core/SemanticVersion.h>
6#include <xrpl/git/Git.h> // IWYU pragma: keep
7#include <xrpl/protocol/SystemParameters.h>
8
9#include <boost/preprocessor/stringize.hpp> // IWYU pragma: keep
10
11#include <algorithm>
12#include <cstdint>
13#include <string>
14#include <string_view>
15
16namespace xrpl::BuildInfo {
17
18namespace {
19
20//--------------------------------------------------------------------------
21// The build version number. You must edit this for each release
22// and follow the format described at http://semver.org/
23//------------------------------------------------------------------------------
24// clang-format off
25// NOLINTNEXTLINE(readability-identifier-naming)
26char const* const versionString = "3.3.0-b0"
27 // clang-format on
28 ;
29
30//
31// Don't touch anything below this line
32//
33
34std::string
35buildVersionString()
36{
37 std::string version = versionString;
38
39#if defined(DEBUG) || defined(SANITIZERS)
40 std::string metadata;
41
42 std::string const& commitHash = xrpl::git::getCommitHash();
43 if (!commitHash.empty())
44 metadata += commitHash + ".";
45
46#ifdef DEBUG
47 metadata += "DEBUG";
48#endif
49
50#if defined(DEBUG) && defined(SANITIZERS)
51 metadata += ".";
52#endif
53
54#ifdef SANITIZERS
55 metadata += BOOST_PP_STRINGIZE(SANITIZERS); // cspell: disable-line
56#endif
57
58 if (!metadata.empty())
59 version += "+" + metadata;
60#endif
61
62 return version;
63}
64
65} // namespace
66
67std::string const&
69{
70 static std::string const kValue = [] {
71 std::string const s = buildVersionString();
72
74 if (!v.parse(s) || v.print() != s)
75 logicError(s + ": Bad server version string");
76 return s;
77 }();
78 return kValue;
79}
80
81std::string const&
83{
84 static std::string const kValue = systemName() + "-" + getVersionString();
85 return kValue;
86}
87
88static constexpr std::uint64_t kImplementationVersionIdentifier = 0x183B'0000'0000'0000LLU;
89static constexpr std::uint64_t kImplementationVersionIdentifierMask = 0xFFFF'0000'0000'0000LLU;
90
93{
95
97
98 if (v.parse(versionStr))
99 {
100 if (v.majorVersion >= 0 && v.majorVersion <= 255)
101 c |= static_cast<std::uint64_t>(v.majorVersion) << 40;
102
103 if (v.minorVersion >= 0 && v.minorVersion <= 255)
104 c |= static_cast<std::uint64_t>(v.minorVersion) << 32;
105
106 if (v.patchVersion >= 0 && v.patchVersion <= 255)
107 c |= static_cast<std::uint64_t>(v.patchVersion) << 24;
108
109 if (!v.isPreRelease())
110 c |= static_cast<std::uint64_t>(0xC00000);
111
112 if (v.isPreRelease())
113 {
114 std::uint8_t x = 0;
115
116 for (auto const& id : v.preReleaseIdentifiers)
117 {
118 auto parsePreRelease = [](std::string_view identifier,
119 std::string_view prefix,
120 std::uint8_t key,
121 std::uint8_t lok,
122 std::uint8_t hik) -> std::uint8_t {
123 std::uint8_t ret = 0;
124
125 if (!identifier.starts_with(prefix))
126 return 0;
127
129 ret, std::string(identifier.substr(prefix.length()))))
130 return 0;
131
132 if (std::clamp(ret, lok, hik) != ret)
133 return 0;
134
135 return ret + key;
136 };
137
138 x = parsePreRelease(id, "rc", 0x80, 0, 63);
139
140 if (x == 0)
141 x = parsePreRelease(id, "b", 0x40, 0, 63);
142
143 if ((x & 0xC0) != 0)
144 {
145 c |= static_cast<std::uint64_t>(x) << 16;
146 break;
147 }
148 }
149 }
150 }
151
152 return c;
153}
154
157{
158 static std::uint64_t const kCookie = {encodeSoftwareVersion(getVersionString())};
159 return kCookie;
160}
161
162bool
167
168bool
170{
171 if (isXrpldVersion(version))
172 return version > getEncodedVersion();
173 return false;
174}
175
176} // namespace xrpl::BuildInfo
T clamp(T... args)
A Semantic Version number.
identifier_list preReleaseIdentifiers
bool isPreRelease() const noexcept
bool parse(std::string_view input)
Parse a semantic version string.
std::string print() const
Produce a string from semantic version components.
T empty(T... args)
bool lexicalCastChecked(Out &out, In in)
Intelligently convert from one type to another.
Versioning information for this build.
Definition BuildInfo.h:8
std::string const & getFullVersionString()
Full server version string.
Definition BuildInfo.cpp:82
static constexpr std::uint64_t kImplementationVersionIdentifierMask
Definition BuildInfo.cpp:89
static constexpr std::uint64_t kImplementationVersionIdentifier
Definition BuildInfo.cpp:88
std::uint64_t getEncodedVersion()
Returns this server's version packed in a 64-bit integer.
bool isNewerVersion(std::uint64_t version)
Check if the version is newer than the local node's xrpld software version.
bool isXrpldVersion(std::uint64_t version)
Check if the encoded software version is an xrpld software version.
std::uint64_t encodeSoftwareVersion(std::string_view versionStr)
Encode an arbitrary server software version in a 64-bit integer.
Definition BuildInfo.cpp:92
std::string const & getVersionString()
Server version.
Definition BuildInfo.cpp:68
std::string const & getCommitHash()
Definition Git.cpp:18
void logicError(std::string const &how) noexcept
Called when faulty logic causes a broken invariant.
static std::string const & systemName()
T starts_with(T... args)
T substr(T... args)