move version specifier to Build.h

This commit is contained in:
Nathan Nichols
2022-05-25 16:05:09 -05:00
committed by Michael Legleux
parent af575b1bcf
commit 458fac776c
12 changed files with 142 additions and 6 deletions

16
src/main/Build.h Normal file
View File

@@ -0,0 +1,16 @@
#ifndef CLIO_BUILD_INFO_H
#define CLIO_BUILD_INFO_H
#include <string>
namespace Build {
std::string const&
getClioVersionString();
std::string const&
getClioFullVersionString();
} // namespace Build
#endif // CLIO_BUILD_INFO_H

57
src/main/impl/Build.cpp Normal file
View File

@@ -0,0 +1,57 @@
#include <ripple/beast/core/SemanticVersion.h>
#include <boost/preprocessor/stringize.hpp>
#include <algorithm>
#include <main/Build.h>
namespace Build {
//--------------------------------------------------------------------------
// The build version number. You must edit this for each release
// and follow the format described at http://semver.org/
//------------------------------------------------------------------------------
// clang-format off
char const* const versionString = "0.2.0"
// clang-format on
#if defined(DEBUG) || defined(SANITIZER)
"+"
#ifdef CLIO_GIT_COMMIT_HASH
CLIO_GIT_COMMIT_HASH
"."
#endif
#ifdef DEBUG
"DEBUG"
#ifdef SANITIZER
"."
#endif
#endif
#ifdef SANITIZER
BOOST_PP_STRINGIZE(SANITIZER)
#endif
#endif
//--------------------------------------------------------------------------
;
std::string const&
getClioVersionString()
{
static std::string const value = [] {
std::string const s = versionString;
beast::SemanticVersion v;
if (!v.parse(s) || v.print() != s)
throw std::runtime_error(s + ": Bad server version string");
return s;
}();
return value;
}
std::string const&
getClioFullVersionString()
{
static std::string const value = "clio-" + getClioVersionString();
return value;
}
} // namespace Build

View File

@@ -28,6 +28,7 @@
#include <fstream>
#include <functional>
#include <iostream>
#include <main/Build.h>
#include <memory>
#include <sstream>
#include <string>
@@ -170,6 +171,12 @@ main(int argc, char* argv[])
return EXIT_FAILURE;
}
if (std::string{argv[1]} == "-v" || std::string{argv[1]} == "--version")
{
std::cout << Build::getClioFullVersionString() << std::endl;
return EXIT_SUCCESS;
}
auto const config = parse_config(argv[1]);
if (!config)
{
@@ -179,6 +186,10 @@ main(int argc, char* argv[])
initLogging(*config);
// Announce Clio version
BOOST_LOG_TRIVIAL(info)
<< "Clio version: " << Build::getClioFullVersionString();
auto ctx = parse_certs(*config);
auto ctxRef = ctx
? std::optional<std::reference_wrapper<ssl::context>>{ctx.value()}

View File

@@ -106,6 +106,14 @@ make_error(Error err)
boost::json::object
make_error(Status const& status)
{
if (status.error == ripple::rpcUNKNOWN)
{
return {
{"error", status.message},
{"type", "response"},
{"status", "error"}};
}
boost::json::object json;
ripple::RPC::ErrorInfo const& info(
ripple::RPC::get_error_info(status.error));

View File

@@ -103,6 +103,14 @@ struct Status
Status(Error error_) : error(error_){};
// HACK. Some rippled handlers explicitly specify errors.
// This means that we have to be able to duplicate this
// functionality.
Status(std::string const& message_)
: error(ripple::rpcUNKNOWN), message(message_)
{
}
Status(Error error_, std::string message_)
: error(error_), message(message_)
{

View File

@@ -357,7 +357,7 @@ doLedgerEntry(Context const& context)
auto end = std::chrono::system_clock::now();
if (!dbResponse or dbResponse->size() == 0)
return Status{Error::rpcOBJECT_NOT_FOUND, "entryNotFound"};
return Status{"entryNotFound"};
response[JS(index)] = ripple::strHex(key);
response[JS(ledger_hash)] = ripple::strHex(lgrInfo.hash);

View File

@@ -2,6 +2,7 @@
#include <backend/BackendInterface.h>
#include <etl/ETLSource.h>
#include <etl/ReportingETL.h>
#include <main/Build.h>
#include <rpc/RPCHelpers.h>
namespace RPC {
@@ -49,6 +50,7 @@ doServerInfo(Context const& context)
{{"counters", "server_info"}}, context.clientIp, context.yield);
info[JS(load_factor)] = 1;
info["clio_version"] = Build::getClioVersionString();
if (serverInfoRippled && !serverInfoRippled->contains(JS(error)))
{
try
@@ -57,6 +59,7 @@ doServerInfo(Context const& context)
auto& rippledInfo = rippledResult.at(JS(info)).as_object();
info[JS(load_factor)] = rippledInfo[JS(load_factor)];
info[JS(validation_quorum)] = rippledInfo[JS(validation_quorum)];
info["rippled_version"] = rippledInfo[JS(build_version)];
}
catch (std::exception const&)
{