Skip to content

Commit 240ce80

Browse files
MarcoFalkeknst
authored andcommitted
Merge bitcoin#24409: Always output license/copyright info with -version
BACKPORT NOTE: Please, notice, that there are added a new exception for clientversion.cpp It is temporary measure so far as it will be removed anyway by bitcoin-31174 5a89bed contrib: address gen-manpages feedback from bitcoin#24263 (fanquake) 2618fb8 Output license info when binaries are passed -version (fanquake) 4c3e3c5 refactor: shift CopyrightHolders() and LicenseInfo() to clientversion.cpp (fanquake) Pull request description: Addresses a review comment from bitcoin#24263, and addresses the [comment](bitcoin#24263 (comment)) where it was pointed out that we are inconsistent with emitting our copyright. After this change, the copyright is always emitted with `-version`, rather than `-help`, i.e: ```bash bitcoind -version Bitcoin Core version v22.99.0-fc1f355913f6-dirty Copyright (C) 2009-2022 The Bitcoin Core developers Please contribute if you find Bitcoin Core useful. Visit <https://bitcoincore.org/> for further information about the software. The source code is available from <https://github.com/bitcoin/bitcoin>. This is experimental software. Distributed under the MIT software license, see the accompanying file COPYING or <https://opensource.org/licenses/MIT> ``` The info is also added to binaries other than `bitcoind`/`bitcoin-qt`. This change also prevents duplicate copyright info appearing in the `bitcoind` man page. ACKs for top commit: laanwj: Tested ACK 5a89bed Tree-SHA512: 0ac2a1adf9e9de0c3206f35837008e3f93eaf15b193736203d71609273f0887cca20b8a90972cb9f941ebd62b330d61a0cbb5fb1b7a7f2dbc715ed8a0c1569d9
1 parent ff8c39d commit 240ce80

File tree

12 files changed

+68
-59
lines changed

12 files changed

+68
-59
lines changed

contrib/devtools/gen-manpages.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232

3333
# Verify that all the required binaries are usable, and extract copyright
3434
# message in a first pass.
35-
copyright = None
3635
versions = []
3736
for relpath in BINARIES:
3837
abspath = os.path.join(builddir, relpath)
@@ -42,32 +41,31 @@
4241
print(f'{abspath} not found or not an executable', file=sys.stderr)
4342
sys.exit(1)
4443
# take first line (which must contain version)
45-
verstr = r.stdout.split('\n')[0]
44+
verstr = r.stdout.splitlines()[0]
4645
# last word of line is the actual version e.g. v22.99.0-5c6b3d5b3508
4746
verstr = verstr.split()[-1]
4847
assert verstr.startswith('v')
48+
# remaining lines are copyright
49+
copyright = r.stdout.split('\n')[1:]
50+
assert copyright[0].startswith('Copyright (C)')
4951

50-
# Only dash-qt prints the copyright message on --version, so store it specifically.
51-
if relpath == 'src/qt/dash-qt':
52-
copyright = r.stdout.split('\n')[1:]
52+
versions.append((abspath, verstr, copyright))
5353

54-
versions.append((abspath, verstr))
55-
56-
if any(verstr.endswith('-dirty') for (_, verstr) in versions):
54+
if any(verstr.endswith('-dirty') for (_, verstr, _) in versions):
5755
print("WARNING: Binaries were built from a dirty tree.")
5856
print('man pages generated from dirty binaries should NOT be committed.')
5957
print('To properly generate man pages, please commit your changes (or discard them), rebuild, then run this script again.')
6058
print()
6159

6260
with tempfile.NamedTemporaryFile('w', suffix='.h2m') as footer:
6361
# Create copyright footer, and write it to a temporary include file.
64-
assert copyright
62+
# Copyright is the same for all binaries, so just use the first.
6563
footer.write('[COPYRIGHT]\n')
66-
footer.write('\n'.join(copyright).strip())
64+
footer.write('\n'.join(versions[0][2]).strip())
6765
footer.flush()
6866

6967
# Call the binaries through help2man to produce a manual page for each of them.
70-
for (abspath, verstr) in versions:
68+
for (abspath, verstr, _) in versions:
7169
outname = os.path.join(mandir, os.path.basename(abspath) + '.1')
7270
print(f'Generating {outname}…')
7371
subprocess.run([help2man, '-N', '--version-string=' + verstr, '--include=' + footer.name, '-o', outname, abspath], check=True)

src/bitcoin-cli.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,10 @@ static int AppInitRPC(int argc, char* argv[])
158158

159159
if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
160160
std::string strUsage = PACKAGE_NAME " RPC client version " + FormatFullVersion() + "\n";
161-
if (!gArgs.IsArgSet("-version")) {
161+
162+
if (gArgs.IsArgSet("-version")) {
163+
strUsage += FormatParagraph(LicenseInfo());
164+
} else {
162165
strUsage += "\n"
163166
"Usage: dash-cli [options] <command> [params] Send command to " PACKAGE_NAME "\n"
164167
"or: dash-cli [options] -named <command> [name=value]... Send command to " PACKAGE_NAME " (with named arguments)\n"

src/bitcoin-tx.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ static int AppInitRawTx(int argc, char* argv[])
106106
if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
107107
// First part of help message is specific to this utility
108108
std::string strUsage = PACKAGE_NAME " dash-tx utility version " + FormatFullVersion() + "\n";
109-
if (!gArgs.IsArgSet("-version")) {
109+
110+
if (gArgs.IsArgSet("-version")) {
111+
strUsage += FormatParagraph(LicenseInfo());
112+
} else {
110113
strUsage += "\n"
111114
"Usage: dash-tx [options] <hex-tx> [commands] Update hex-encoded dash transaction\n"
112115
"or: dash-tx [options] -create [commands] Create hex-encoded dash transaction\n"

src/bitcoin-wallet.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ static bool WalletAppInit(ArgsManager& args, int argc, char* argv[])
5959
}
6060
if (argc < 2 || HelpRequested(args) || args.IsArgSet("-version")) {
6161
std::string strUsage = strprintf("%s dash-wallet version", PACKAGE_NAME) + " " + FormatFullVersion() + "\n";
62-
if (!args.IsArgSet("-version")) {
62+
63+
if (args.IsArgSet("-version")) {
64+
strUsage += FormatParagraph(LicenseInfo());
65+
} else {
6366
strUsage += "\n"
6467
"dash-wallet is an offline tool for creating and interacting with " PACKAGE_NAME " wallet files.\n"
6568
"By default dash-wallet will act on wallets in the default mainnet wallet directory in the datadir.\n"

src/bitcoind.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
136136
if (HelpRequested(args) || args.IsArgSet("-version")) {
137137
std::string strUsage = PACKAGE_NAME " version " + FormatFullVersion() + "\n";
138138

139-
if (!args.IsArgSet("-version")) {
140-
strUsage += FormatParagraph(LicenseInfo()) + "\n"
141-
"\nUsage: dashd [options] Start " PACKAGE_NAME "\n"
139+
if (args.IsArgSet("-version")) {
140+
strUsage += FormatParagraph(LicenseInfo());
141+
} else {
142+
strUsage += "\nUsage: dashd [options] Start " PACKAGE_NAME "\n"
142143
"\n";
143144
strUsage += args.GetHelpMessage();
144145
}

src/clientversion.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <clientversion.h>
6+
#include <util/translation.h>
67

78
#include <tinyformat.h>
89

10+
#include <sstream>
11+
#include <string>
12+
#include <vector>
913

1014
/**
1115
* Name of client reported in the 'version' message. Report the same name
@@ -73,3 +77,36 @@ std::string FormatSubVersion(const std::string& name, int nClientVersion, const
7377
ss << "/";
7478
return ss.str();
7579
}
80+
81+
std::string CopyrightHolders(const std::string& strPrefix, unsigned int nStartYear, unsigned int nEndYear)
82+
{
83+
const auto copyright_devs = strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION);
84+
std::string strCopyrightHolders = strPrefix + strprintf(" %u-%u ", nStartYear, nEndYear) + copyright_devs;
85+
86+
// Check for untranslated substitution to make sure Dash Core copyright is not removed by accident
87+
if (copyright_devs.find("Dash Core") == std::string::npos) {
88+
strCopyrightHolders += "\n" + strPrefix + strprintf(" %u-%u ", 2014, nEndYear) + "The Dash Core developers";
89+
}
90+
// Check for untranslated substitution to make sure Bitcoin Core copyright is not removed by accident
91+
if (copyright_devs.find("Bitcoin Core") == std::string::npos) {
92+
strCopyrightHolders += "\n" + strPrefix + strprintf(" %u-%u ", 2009, nEndYear) + "The Bitcoin Core developers";
93+
}
94+
return strCopyrightHolders;
95+
}
96+
97+
std::string LicenseInfo()
98+
{
99+
const std::string URL_SOURCE_CODE = "<https://github.com/dashpay/dash>";
100+
101+
return CopyrightHolders(_("Copyright (C)").translated, 2014, COPYRIGHT_YEAR) + "\n" +
102+
"\n" +
103+
strprintf(_("Please contribute if you find %s useful. "
104+
"Visit %s for further information about the software.").translated, PACKAGE_NAME, "<" PACKAGE_URL ">") +
105+
"\n" +
106+
strprintf(_("The source code is available from %s.").translated, URL_SOURCE_CODE) +
107+
"\n" +
108+
"\n" +
109+
_("This is experimental software.").translated + "\n" +
110+
strprintf(_("Distributed under the MIT software license, see the accompanying file %s or %s").translated, "COPYING", "<https://opensource.org/licenses/MIT>") +
111+
"\n";
112+
}

src/clientversion.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ std::string FormatVersion(int nVersion);
4141
std::string FormatFullVersion();
4242
std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector<std::string>& comments);
4343

44+
std::string CopyrightHolders(const std::string& strPrefix, unsigned int nStartYear, unsigned int nEndYear);
45+
46+
/** Returns licensing information (for -version) */
47+
std::string LicenseInfo();
48+
4449
#endif // WINDRES_PREPROC
4550

4651
#endif // BITCOIN_CLIENTVERSION_H

src/init.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -794,25 +794,6 @@ void SetupServerArgs(ArgsManager& argsman)
794794
argsman.AddHiddenArgs(hidden_args);
795795
}
796796

797-
std::string LicenseInfo()
798-
{
799-
const std::string URL_SOURCE_CODE = "<https://github.com/dashpay/dash>";
800-
801-
return CopyrightHolders(_("Copyright (C)").translated, 2014, COPYRIGHT_YEAR) + "\n" +
802-
"\n" +
803-
strprintf(_("Please contribute if you find %s useful. "
804-
"Visit %s for further information about the software.").translated,
805-
PACKAGE_NAME, "<" PACKAGE_URL ">") +
806-
"\n" +
807-
strprintf(_("The source code is available from %s.").translated,
808-
URL_SOURCE_CODE) +
809-
"\n" +
810-
"\n" +
811-
_("This is experimental software.").translated + "\n" +
812-
strprintf(_("Distributed under the MIT software license, see the accompanying file %s or %s").translated, "COPYING", "<https://opensource.org/licenses/MIT>") +
813-
"\n";
814-
}
815-
816797
static bool fHaveGenesis = false;
817798
static Mutex g_genesis_wait_mutex;
818799
static std::condition_variable g_genesis_wait_cv;

src/init.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,4 @@ void PrepareShutdown(node::NodeContext& node);
7272
*/
7373
void SetupServerArgs(ArgsManager& argsman);
7474

75-
/** Returns licensing information (for -version) */
76-
std::string LicenseInfo();
77-
7875
#endif // BITCOIN_INIT_H

src/util/system.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,23 +1471,6 @@ int GetNumCores()
14711471
return std::thread::hardware_concurrency();
14721472
}
14731473

1474-
std::string CopyrightHolders(const std::string& strPrefix, unsigned int nStartYear, unsigned int nEndYear)
1475-
{
1476-
// std::string strCopyrightHolders = strPrefix + strprintf(" %u-%u ", nStartYear, nEndYear) + strprintf(_(COPYRIGHT_HOLDERS).translated, _(COPYRIGHT_HOLDERS_SUBSTITUTION));
1477-
const auto copyright_devs = strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION);
1478-
std::string strCopyrightHolders = strPrefix + strprintf(" %u-%u ", nStartYear, nEndYear) + copyright_devs;
1479-
1480-
// Check for untranslated substitution to make sure Dash Core copyright is not removed by accident
1481-
if (copyright_devs.find("Dash Core") == std::string::npos) {
1482-
strCopyrightHolders += "\n" + strPrefix + strprintf(" %u-%u ", 2014, nEndYear) + "The Dash Core developers";
1483-
}
1484-
// Check for untranslated substitution to make sure Bitcoin Core copyright is not removed by accident
1485-
if (copyright_devs.find("Bitcoin Core") == std::string::npos) {
1486-
strCopyrightHolders += "\n" + strPrefix + strprintf(" %u-%u ", 2009, nEndYear) + "The Bitcoin Core developers";
1487-
}
1488-
return strCopyrightHolders;
1489-
}
1490-
14911474
// Obtain the application startup time (used for uptime calculation)
14921475
int64_t GetStartupTime()
14931476
{

0 commit comments

Comments
 (0)