Skip to content

Commit 3c56530

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#24409: Always output license/copyright info with -version
5a89bed contrib: address gen-manpages feedback from #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 #24263, and addresses the [comment](bitcoin/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
2 parents f062abe + 5a89bed commit 3c56530

File tree

13 files changed

+68
-55
lines changed

13 files changed

+68
-55
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 bitcoin-qt prints the copyright message on --version, so store it specifically.
51-
if relpath == 'src/qt/bitcoin-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
@@ -133,7 +133,10 @@ static int AppInitRPC(int argc, char* argv[])
133133
}
134134
if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
135135
std::string strUsage = PACKAGE_NAME " RPC client version " + FormatFullVersion() + "\n";
136-
if (!gArgs.IsArgSet("-version")) {
136+
137+
if (gArgs.IsArgSet("-version")) {
138+
strUsage += FormatParagraph(LicenseInfo());
139+
} else {
137140
strUsage += "\n"
138141
"Usage: bitcoin-cli [options] <command> [params] Send command to " PACKAGE_NAME "\n"
139142
"or: bitcoin-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
@@ -102,7 +102,10 @@ static int AppInitRawTx(int argc, char* argv[])
102102
if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
103103
// First part of help message is specific to this utility
104104
std::string strUsage = PACKAGE_NAME " bitcoin-tx utility version " + FormatFullVersion() + "\n";
105-
if (!gArgs.IsArgSet("-version")) {
105+
106+
if (gArgs.IsArgSet("-version")) {
107+
strUsage += FormatParagraph(LicenseInfo());
108+
} else {
106109
strUsage += "\n"
107110
"Usage: bitcoin-tx [options] <hex-tx> [commands] Update hex-encoded bitcoin transaction\n"
108111
"or: bitcoin-tx [options] -create [commands] Create hex-encoded bitcoin transaction\n"

src/bitcoin-util.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ static int AppInitUtil(ArgsManager& args, int argc, char* argv[])
5353
if (HelpRequested(args) || args.IsArgSet("-version")) {
5454
// First part of help message is specific to this utility
5555
std::string strUsage = PACKAGE_NAME " bitcoin-util utility version " + FormatFullVersion() + "\n";
56-
if (!args.IsArgSet("-version")) {
56+
57+
if (args.IsArgSet("-version")) {
58+
strUsage += FormatParagraph(LicenseInfo());
59+
} else {
5760
strUsage += "\n"
5861
"Usage: bitcoin-util [options] [commands] Do stuff\n";
5962
strUsage += "\n" + args.GetHelpMessage();

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 bitcoin-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
"bitcoin-wallet is an offline tool for creating and interacting with " PACKAGE_NAME " wallet files.\n"
6568
"By default bitcoin-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
@@ -126,9 +126,10 @@ static bool AppInit(NodeContext& node, int argc, char* argv[])
126126
if (HelpRequested(args) || args.IsArgSet("-version")) {
127127
std::string strUsage = PACKAGE_NAME " version " + FormatFullVersion() + "\n";
128128

129-
if (!args.IsArgSet("-version")) {
130-
strUsage += FormatParagraph(LicenseInfo()) + "\n"
131-
"\nUsage: bitcoind [options] Start " PACKAGE_NAME "\n"
129+
if (args.IsArgSet("-version")) {
130+
strUsage += FormatParagraph(LicenseInfo());
131+
} else {
132+
strUsage += "\nUsage: bitcoind [options] Start " PACKAGE_NAME "\n"
132133
"\n";
133134
strUsage += args.GetHelpMessage();
134135
}

src/clientversion.cpp

Lines changed: 33 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
@@ -72,3 +76,32 @@ std::string FormatSubVersion(const std::string& name, int nClientVersion, const
7276
ss << "/";
7377
return ss.str();
7478
}
79+
80+
std::string CopyrightHolders(const std::string& strPrefix)
81+
{
82+
const auto copyright_devs = strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION);
83+
std::string strCopyrightHolders = strPrefix + copyright_devs;
84+
85+
// Make sure Bitcoin Core copyright is not removed by accident
86+
if (copyright_devs.find("Bitcoin Core") == std::string::npos) {
87+
strCopyrightHolders += "\n" + strPrefix + "The Bitcoin Core developers";
88+
}
89+
return strCopyrightHolders;
90+
}
91+
92+
std::string LicenseInfo()
93+
{
94+
const std::string URL_SOURCE_CODE = "<https://github.com/bitcoin/bitcoin>";
95+
96+
return CopyrightHolders(strprintf(_("Copyright (C) %i-%i").translated, 2009, COPYRIGHT_YEAR) + " ") + "\n" +
97+
"\n" +
98+
strprintf(_("Please contribute if you find %s useful. "
99+
"Visit %s for further information about the software.").translated, PACKAGE_NAME, "<" PACKAGE_URL ">") +
100+
"\n" +
101+
strprintf(_("The source code is available from %s.").translated, URL_SOURCE_CODE) +
102+
"\n" +
103+
"\n" +
104+
_("This is experimental software.").translated + "\n" +
105+
strprintf(_("Distributed under the MIT software license, see the accompanying file %s or %s").translated, "COPYING", "<https://opensource.org/licenses/MIT>") +
106+
"\n";
107+
}

src/clientversion.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ extern const std::string CLIENT_NAME;
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);
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
@@ -594,25 +594,6 @@ void SetupServerArgs(ArgsManager& argsman)
594594
argsman.AddHiddenArgs(hidden_args);
595595
}
596596

597-
std::string LicenseInfo()
598-
{
599-
const std::string URL_SOURCE_CODE = "<https://github.com/bitcoin/bitcoin>";
600-
601-
return CopyrightHolders(strprintf(_("Copyright (C) %i-%i").translated, 2009, COPYRIGHT_YEAR) + " ") + "\n" +
602-
"\n" +
603-
strprintf(_("Please contribute if you find %s useful. "
604-
"Visit %s for further information about the software.").translated,
605-
PACKAGE_NAME, "<" PACKAGE_URL ">") +
606-
"\n" +
607-
strprintf(_("The source code is available from %s.").translated,
608-
URL_SOURCE_CODE) +
609-
"\n" +
610-
"\n" +
611-
_("This is experimental software.").translated + "\n" +
612-
strprintf(_("Distributed under the MIT software license, see the accompanying file %s or %s").translated, "COPYING", "<https://opensource.org/licenses/MIT>") +
613-
"\n";
614-
}
615-
616597
static bool fHaveGenesis = false;
617598
static Mutex g_genesis_wait_mutex;
618599
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
@@ -70,7 +70,4 @@ bool AppInitMain(node::NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip
7070
*/
7171
void SetupServerArgs(ArgsManager& argsman);
7272

73-
/** Returns licensing information (for -version) */
74-
std::string LicenseInfo();
75-
7673
#endif // BITCOIN_INIT_H

0 commit comments

Comments
 (0)