diff --git a/src/clientversion.cpp b/src/clientversion.cpp index 9d2d539dc4e..fb4f8d8811e 100644 --- a/src/clientversion.cpp +++ b/src/clientversion.cpp @@ -27,9 +27,13 @@ const std::string CLIENT_NAME("DeFiChain"); * * first, if HAVE_BUILD_INFO is defined, include build.h, a file that is * generated by the build environment, possibly containing the output * of git-describe in a macro called BUILD_DESC - * * then, two options exist for determining CLIENT_BUILD: + * * secondly, if this is an exported version of the code, GIT_ARCHIVE will + * be defined (automatically using the export-subst git attribute), and + * GIT_COMMIT will contain the commit id. + * * then, three options exist for determining CLIENT_BUILD: * * if BUILD_DESC is defined, use that literally (output of git-describe) - * * otherwise, use v[maj].[min].[rev].[build]-unknown + * * if not, but GIT_COMMIT is defined, use v[maj].[min].[rev].[build]-g[commit] + * * otherwise, use v[maj].[min].[rev].[build]-unk * finally CLIENT_VERSION_SUFFIX is added */ @@ -42,25 +46,32 @@ const std::string CLIENT_NAME("DeFiChain"); #define BUILD_SUFFIX release #endif +//! git will put "#define GIT_ARCHIVE 1" on the next line inside archives. $Format:%n#define GIT_ARCHIVE 1$ +#ifdef GIT_ARCHIVE +#define GIT_COMMIT_ID "$Format:%H$" +#define GIT_COMMIT_DATE "$Format:%cD$" +#endif + #define BUILD_DESC_WITH_SUFFIX(maj, min, rev, build, suffix) \ "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-" DO_STRINGIZE(suffix) + +#define BUILD_DESC_FROM_COMMIT(maj, min, rev, build, commit) \ + "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-g" commit + #define BUILD_DESC_FROM_UNKNOWN(maj, min, rev, build) \ - "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-unknown" -#define BUILD_SUFFIX_TAIL(suffix) \ - DO_STRINGIZE(suffix) + "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-unk" #ifndef BUILD_DESC #ifdef BUILD_SUFFIX #define BUILD_DESC BUILD_DESC_WITH_SUFFIX(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, BUILD_SUFFIX) -#define BUILD_DESC_SUFFIX BUILD_SUFFIX_TAIL(BUILD_SUFFIX) +#elif defined(GIT_COMMIT_ID) +#define BUILD_DESC BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, GIT_COMMIT_ID) #else #define BUILD_DESC BUILD_DESC_FROM_UNKNOWN(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD) -#define BUILD_DESC_SUFFIX "unknown" #endif #endif const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX); -const std::string CLIENT_BUILD_SUFFIX(BUILD_DESC_SUFFIX CLIENT_VERSION_SUFFIX); std::string FormatVersion(int nVersion) { @@ -75,11 +86,6 @@ std::string FormatVersionAndSuffix() return CLIENT_BUILD; } -std::string FormatVersionSuffixTail() -{ - return CLIENT_BUILD_SUFFIX; -} - /** * Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip-0014.mediawiki) */ diff --git a/src/clientversion.h b/src/clientversion.h index 504aeac4dd9..ebc296b911b 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -46,7 +46,6 @@ extern const std::string CLIENT_BUILD; std::string FormatVersion(int nVersion); std::string FormatVersionAndSuffix(); -std::string FormatVersionSuffixTail(); std::string FormatUserAgentString(const std::string& name, int nClientVersion, const std::vector& comments); #endif // WINDRES_PREPROC diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 73d6e365f14..0889e6d161d 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -518,16 +518,15 @@ static UniValue getversioninfo(const JSONRPCRequest& request){ {}, RPCResult{ "{\n" - " \"name\": DeFiChain (string) Node name\n" - " \"version\": \"xxxxx\", (string) Node version string\n" - " \"versionSuffix\": \"xxxxx\", (string) Version suffix\n" - " \"numericVersion\": xxxxx, (number) Node numeric version\n" - " \"fullVersion\": \"DefiChain:x.x.x-suffix\", (string) Full node version string including name and full version including suffix\n" - " \"userAgent\": \"/DefiChain:x.x.x/\", (string) P2P user agent string (subversion string conforming to BIP-14)\n" - " \"protoVersion\": \"xxxxx\", (number) Operating protocol version\n" - " \"protoVersionMin\": \"xxxxx\", (number) Minimum protocol that's supported by the node\n" - " \"rpcVersion\": \"xxxxx\", (string) RPC version\n" - " \"rpcVersionMin\": \"xxxxx\", (string) Minimum RPC version supported\n" + " \"name\": DeFiChain (string) Node name\n" + " \"version\": \"xxxxx\", (string) Node version string\n" + " \"numericVersion\": xxxxx, (number) Node numeric version\n" + " \"fullVersion\": \"DefiChain:x.x.x\", (string) Full node version string including name and version\n" + " \"userAgent\": \"/DefiChain:x.x.x/\", (string) P2P user agent string (subversion string conforming to BIP-14)\n" + " \"protoVersion\": \"xxxxx\", (number) Operating protocol version\n" + " \"protoVersionMin\": \"xxxxx\", (number) Minimum protocol that's supported by the node\n" + " \"rpcVersion\": \"xxxxx\", (string) RPC version\n" + " \"rpcVersionMin\": \"xxxxx\", (string) Minimum RPC version supported\n" " \"spv\":\n" " \"{\n" " \"btc\":\n" @@ -547,6 +546,8 @@ static UniValue getversioninfo(const JSONRPCRequest& request){ UniValue nodeInfoObj(UniValue::VOBJ); + + UniValue btcInfoObj(UniValue::VOBJ); btcInfoObj.pushKV("version", BR_PROTOCOL_VERSION); btcInfoObj.pushKV("min", BR_MIN_PROTO_VERSION); @@ -556,11 +557,10 @@ static UniValue getversioninfo(const JSONRPCRequest& request){ spvInfoObj.pushKV("btc", btcInfoObj); std::ostringstream strFullVersion; - strFullVersion << CLIENT_NAME << ":" << FormatVersionAndSuffix(); + strFullVersion << CLIENT_NAME << ":" << FormatVersion(CLIENT_VERSION); nodeInfoObj.pushKV("name", CLIENT_NAME); nodeInfoObj.pushKV("version", FormatVersion(CLIENT_VERSION)); - nodeInfoObj.pushKV("versionSuffix", FormatVersionSuffixTail()); nodeInfoObj.pushKV("numericVersion", CLIENT_VERSION); nodeInfoObj.pushKV("fullVersion",strFullVersion.str()); nodeInfoObj.pushKV("userAgent",strSubVersion);