You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

version.cpp 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright (c) 2012 The Bitcoin developers
  2. // Distributed under the MIT/X11 software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. #include "version.h"
  5. #include "tinyformat.h"
  6. #include <string>
  7. #include <boost/algorithm/string/join.hpp>
  8. // Name of client reported in the 'version' message. Report the same name
  9. // for both bitcoind and bitcoin-qt, to make it harder for attackers to
  10. // target servers or GUI users specifically.
  11. const std::string CLIENT_NAME("Satoshi");
  12. // Client version number
  13. #define CLIENT_VERSION_SUFFIX ""
  14. // The following part of the code determines the CLIENT_BUILD variable.
  15. // Several mechanisms are used for this:
  16. // * first, if HAVE_BUILD_INFO is defined, include build.h, a file that is
  17. // generated by the build environment, possibly containing the output
  18. // of git-describe in a macro called BUILD_DESC
  19. // * secondly, if this is an exported version of the code, GIT_ARCHIVE will
  20. // be defined (automatically using the export-subst git attribute), and
  21. // GIT_COMMIT will contain the commit id.
  22. // * then, three options exist for determining CLIENT_BUILD:
  23. // * if BUILD_DESC is defined, use that literally (output of git-describe)
  24. // * if not, but GIT_COMMIT is defined, use v[maj].[min].[rev].[build]-g[commit]
  25. // * otherwise, use v[maj].[min].[rev].[build]-unk
  26. // finally CLIENT_VERSION_SUFFIX is added
  27. // First, include build.h if requested
  28. #ifdef HAVE_BUILD_INFO
  29. # include "build.h"
  30. #endif
  31. // git will put "#define GIT_ARCHIVE 1" on the next line inside archives. $Format:%n#define GIT_ARCHIVE 1$
  32. #ifdef GIT_ARCHIVE
  33. # define GIT_COMMIT_ID "$Format:%h$"
  34. # define GIT_COMMIT_DATE "$Format:%cD$"
  35. #endif
  36. #define BUILD_DESC_WITH_SUFFIX(maj,min,rev,build,suffix) \
  37. "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-" DO_STRINGIZE(suffix)
  38. #define BUILD_DESC_FROM_COMMIT(maj,min,rev,build,commit) \
  39. "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-g" commit
  40. #define BUILD_DESC_FROM_UNKNOWN(maj,min,rev,build) \
  41. "v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-unk"
  42. #ifndef BUILD_DESC
  43. # ifdef BUILD_SUFFIX
  44. # define BUILD_DESC BUILD_DESC_WITH_SUFFIX(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, BUILD_SUFFIX)
  45. # elif defined(GIT_COMMIT_ID)
  46. # define BUILD_DESC BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, GIT_COMMIT_ID)
  47. # else
  48. # define BUILD_DESC BUILD_DESC_FROM_UNKNOWN(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD)
  49. # endif
  50. #endif
  51. #ifndef BUILD_DATE
  52. # ifdef GIT_COMMIT_DATE
  53. # define BUILD_DATE GIT_COMMIT_DATE
  54. # else
  55. # define BUILD_DATE __DATE__ ", " __TIME__
  56. # endif
  57. #endif
  58. const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX);
  59. const std::string CLIENT_DATE(BUILD_DATE);
  60. static std::string FormatVersion(int nVersion)
  61. {
  62. if (nVersion%100 == 0)
  63. return strprintf("%d.%d.%d", nVersion/1000000, (nVersion/10000)%100, (nVersion/100)%100);
  64. else
  65. return strprintf("%d.%d.%d.%d", nVersion/1000000, (nVersion/10000)%100, (nVersion/100)%100, nVersion%100);
  66. }
  67. std::string FormatFullVersion()
  68. {
  69. return CLIENT_BUILD;
  70. }
  71. // Format the subversion field according to BIP 14 spec (https://en.bitcoin.it/wiki/BIP_0014)
  72. std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments)
  73. {
  74. std::ostringstream ss;
  75. ss << "/";
  76. ss << name << ":" << FormatVersion(nClientVersion);
  77. if (!comments.empty())
  78. ss << "(" << boost::algorithm::join(comments, "; ") << ")";
  79. ss << "/";
  80. return ss.str();
  81. }