From 4c3e3c57463b029d335e685d3dcdaf26456666cf Mon Sep 17 00:00:00 2001 From: fanquake Date: Mon, 21 Feb 2022 15:30:46 +0000 Subject: [PATCH 1/3] refactor: shift CopyrightHolders() and LicenseInfo() to clientversion.cpp --- src/clientversion.cpp | 33 ++++++++++++++++++++++++++++++++ src/clientversion.h | 5 +++++ src/init.cpp | 19 ------------------ src/init.h | 3 --- src/util/system.cpp | 12 ------------ src/util/system.h | 2 -- test/lint/lint-format-strings.py | 2 +- 7 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/clientversion.cpp b/src/clientversion.cpp index 9b65952b02b..192e9c52bc0 100644 --- a/src/clientversion.cpp +++ b/src/clientversion.cpp @@ -3,9 +3,13 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include +#include #include +#include +#include +#include /** * 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 ss << "/"; return ss.str(); } + +std::string CopyrightHolders(const std::string& strPrefix) +{ + const auto copyright_devs = strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION); + std::string strCopyrightHolders = strPrefix + copyright_devs; + + // Make sure Bitcoin Core copyright is not removed by accident + if (copyright_devs.find("Bitcoin Core") == std::string::npos) { + strCopyrightHolders += "\n" + strPrefix + "The Bitcoin Core developers"; + } + return strCopyrightHolders; +} + +std::string LicenseInfo() +{ + const std::string URL_SOURCE_CODE = ""; + + return CopyrightHolders(strprintf(_("Copyright (C) %i-%i").translated, 2009, COPYRIGHT_YEAR) + " ") + "\n" + + "\n" + + strprintf(_("Please contribute if you find %s useful. " + "Visit %s for further information about the software.").translated, PACKAGE_NAME, "<" PACKAGE_URL ">") + + "\n" + + strprintf(_("The source code is available from %s.").translated, URL_SOURCE_CODE) + + "\n" + + "\n" + + _("This is experimental software.").translated + "\n" + + strprintf(_("Distributed under the MIT software license, see the accompanying file %s or %s").translated, "COPYING", "") + + "\n"; +} diff --git a/src/clientversion.h b/src/clientversion.h index a39d96292da..d2efd7dcab5 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -41,6 +41,11 @@ extern const std::string CLIENT_NAME; std::string FormatFullVersion(); std::string FormatSubVersion(const std::string& name, int nClientVersion, const std::vector& comments); +std::string CopyrightHolders(const std::string& strPrefix); + +/** Returns licensing information (for -version) */ +std::string LicenseInfo(); + #endif // WINDRES_PREPROC #endif // BITCOIN_CLIENTVERSION_H diff --git a/src/init.cpp b/src/init.cpp index 64ed8683331..02ea30e28e9 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -594,25 +594,6 @@ void SetupServerArgs(ArgsManager& argsman) argsman.AddHiddenArgs(hidden_args); } -std::string LicenseInfo() -{ - const std::string URL_SOURCE_CODE = ""; - - return CopyrightHolders(strprintf(_("Copyright (C) %i-%i").translated, 2009, COPYRIGHT_YEAR) + " ") + "\n" + - "\n" + - strprintf(_("Please contribute if you find %s useful. " - "Visit %s for further information about the software.").translated, - PACKAGE_NAME, "<" PACKAGE_URL ">") + - "\n" + - strprintf(_("The source code is available from %s.").translated, - URL_SOURCE_CODE) + - "\n" + - "\n" + - _("This is experimental software.").translated + "\n" + - strprintf(_("Distributed under the MIT software license, see the accompanying file %s or %s").translated, "COPYING", "") + - "\n"; -} - static bool fHaveGenesis = false; static Mutex g_genesis_wait_mutex; static std::condition_variable g_genesis_wait_cv; diff --git a/src/init.h b/src/init.h index 1292cc1a3a7..ddd439f6198 100644 --- a/src/init.h +++ b/src/init.h @@ -70,7 +70,4 @@ bool AppInitMain(node::NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip */ void SetupServerArgs(ArgsManager& argsman); -/** Returns licensing information (for -version) */ -std::string LicenseInfo(); - #endif // BITCOIN_INIT_H diff --git a/src/util/system.cpp b/src/util/system.cpp index 69811a751bd..aa9122106bd 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -1342,18 +1342,6 @@ int GetNumCores() return std::thread::hardware_concurrency(); } -std::string CopyrightHolders(const std::string& strPrefix) -{ - const auto copyright_devs = strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION); - std::string strCopyrightHolders = strPrefix + copyright_devs; - - // Make sure Bitcoin Core copyright is not removed by accident - if (copyright_devs.find("Bitcoin Core") == std::string::npos) { - strCopyrightHolders += "\n" + strPrefix + "The Bitcoin Core developers"; - } - return strCopyrightHolders; -} - // Obtain the application startup time (used for uptime calculation) int64_t GetStartupTime() { diff --git a/src/util/system.h b/src/util/system.h index a72ba3f3ed1..f193c8ac0b6 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -512,8 +512,6 @@ std::string HelpMessageOpt(const std::string& option, const std::string& message */ int GetNumCores(); -std::string CopyrightHolders(const std::string& strPrefix); - /** * On platforms that support it, tell the kernel the calling thread is * CPU-intensive and non-interactive. See SCHED_BATCH in sched(7) for details. diff --git a/test/lint/lint-format-strings.py b/test/lint/lint-format-strings.py index 2870432bffb..ed0d97d4f68 100755 --- a/test/lint/lint-format-strings.py +++ b/test/lint/lint-format-strings.py @@ -16,7 +16,7 @@ FALSE_POSITIVES = [ ("src/dbwrapper.cpp", "vsnprintf(p, limit - p, format, backup_ap)"), ("src/index/base.cpp", "FatalError(const char* fmt, const Args&... args)"), ("src/netbase.cpp", "LogConnectFailure(bool manual_connection, const char* fmt, const Args&... args)"), - ("src/util/system.cpp", "strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION)"), + ("src/clientversion.cpp", "strprintf(_(COPYRIGHT_HOLDERS).translated, COPYRIGHT_HOLDERS_SUBSTITUTION)"), ("src/validationinterface.cpp", "LogPrint(BCLog::VALIDATION, fmt \"\\n\", __VA_ARGS__)"), ("src/wallet/wallet.h", "WalletLogPrintf(std::string fmt, Params... parameters)"), ("src/wallet/wallet.h", "LogPrintf((\"%s \" + fmt).c_str(), GetDisplayName(), parameters...)"), From 2618fb8d15d01dca967856c92ebf3e4cc09699a2 Mon Sep 17 00:00:00 2001 From: fanquake Date: Mon, 21 Feb 2022 19:32:59 +0000 Subject: [PATCH 2/3] Output license info when binaries are passed -version Consolidate to outputting the licensing info when we pass -version to a binary, i.e bitcoind -version: ```bash itcoin Core version v22.99.0-fc1f355913f6-dirty Copyright (C) 2009-2022 The Bitcoin Core developers Please contribute if you find Bitcoin Core useful. Visit for further information about the software. The source code is available from . This is experimental software. Distributed under the MIT software license, see the accompanying file COPYING or ``` --- src/bitcoin-cli.cpp | 5 ++++- src/bitcoin-tx.cpp | 5 ++++- src/bitcoin-util.cpp | 5 ++++- src/bitcoin-wallet.cpp | 5 ++++- src/bitcoind.cpp | 7 ++++--- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 874e38752a4..5523fff3b26 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -133,7 +133,10 @@ static int AppInitRPC(int argc, char* argv[]) } if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) { std::string strUsage = PACKAGE_NAME " RPC client version " + FormatFullVersion() + "\n"; - if (!gArgs.IsArgSet("-version")) { + + if (gArgs.IsArgSet("-version")) { + strUsage += FormatParagraph(LicenseInfo()); + } else { strUsage += "\n" "Usage: bitcoin-cli [options] [params] Send command to " PACKAGE_NAME "\n" "or: bitcoin-cli [options] -named [name=value]... Send command to " PACKAGE_NAME " (with named arguments)\n" diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index ec07114d6ec..b297081cab8 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -102,7 +102,10 @@ static int AppInitRawTx(int argc, char* argv[]) if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) { // First part of help message is specific to this utility std::string strUsage = PACKAGE_NAME " bitcoin-tx utility version " + FormatFullVersion() + "\n"; - if (!gArgs.IsArgSet("-version")) { + + if (gArgs.IsArgSet("-version")) { + strUsage += FormatParagraph(LicenseInfo()); + } else { strUsage += "\n" "Usage: bitcoin-tx [options] [commands] Update hex-encoded bitcoin transaction\n" "or: bitcoin-tx [options] -create [commands] Create hex-encoded bitcoin transaction\n" diff --git a/src/bitcoin-util.cpp b/src/bitcoin-util.cpp index 973f4f28833..b457e0b354d 100644 --- a/src/bitcoin-util.cpp +++ b/src/bitcoin-util.cpp @@ -53,7 +53,10 @@ static int AppInitUtil(ArgsManager& args, int argc, char* argv[]) if (HelpRequested(args) || args.IsArgSet("-version")) { // First part of help message is specific to this utility std::string strUsage = PACKAGE_NAME " bitcoin-util utility version " + FormatFullVersion() + "\n"; - if (!args.IsArgSet("-version")) { + + if (args.IsArgSet("-version")) { + strUsage += FormatParagraph(LicenseInfo()); + } else { strUsage += "\n" "Usage: bitcoin-util [options] [commands] Do stuff\n"; strUsage += "\n" + args.GetHelpMessage(); diff --git a/src/bitcoin-wallet.cpp b/src/bitcoin-wallet.cpp index ff5485e2da4..2f3dd45267d 100644 --- a/src/bitcoin-wallet.cpp +++ b/src/bitcoin-wallet.cpp @@ -59,7 +59,10 @@ static bool WalletAppInit(ArgsManager& args, int argc, char* argv[]) } if (argc < 2 || HelpRequested(args) || args.IsArgSet("-version")) { std::string strUsage = strprintf("%s bitcoin-wallet version", PACKAGE_NAME) + " " + FormatFullVersion() + "\n"; - if (!args.IsArgSet("-version")) { + + if (args.IsArgSet("-version")) { + strUsage += FormatParagraph(LicenseInfo()); + } else { strUsage += "\n" "bitcoin-wallet is an offline tool for creating and interacting with " PACKAGE_NAME " wallet files.\n" "By default bitcoin-wallet will act on wallets in the default mainnet wallet directory in the datadir.\n" diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 6432e8849d7..98433826825 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -126,9 +126,10 @@ static bool AppInit(NodeContext& node, int argc, char* argv[]) if (HelpRequested(args) || args.IsArgSet("-version")) { std::string strUsage = PACKAGE_NAME " version " + FormatFullVersion() + "\n"; - if (!args.IsArgSet("-version")) { - strUsage += FormatParagraph(LicenseInfo()) + "\n" - "\nUsage: bitcoind [options] Start " PACKAGE_NAME "\n" + if (args.IsArgSet("-version")) { + strUsage += FormatParagraph(LicenseInfo()); + } else { + strUsage += "\nUsage: bitcoind [options] Start " PACKAGE_NAME "\n" "\n"; strUsage += args.GetHelpMessage(); } From 5a89bed410d724360b8f90bd9d7d28d6e62331c0 Mon Sep 17 00:00:00 2001 From: fanquake Date: Mon, 21 Feb 2022 14:18:59 +0000 Subject: [PATCH 3/3] contrib: address gen-manpages feedback from #24263 Co-authored-by: Carl Dong --- contrib/devtools/gen-manpages.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/contrib/devtools/gen-manpages.py b/contrib/devtools/gen-manpages.py index 05f613da38d..26612cc444d 100755 --- a/contrib/devtools/gen-manpages.py +++ b/contrib/devtools/gen-manpages.py @@ -32,7 +32,6 @@ mandir = os.getenv('MANDIR', os.path.join(topdir, 'doc/man')) # Verify that all the required binaries are usable, and extract copyright # message in a first pass. -copyright = None versions = [] for relpath in BINARIES: abspath = os.path.join(builddir, relpath) @@ -42,18 +41,17 @@ for relpath in BINARIES: print(f'{abspath} not found or not an executable', file=sys.stderr) sys.exit(1) # take first line (which must contain version) - verstr = r.stdout.split('\n')[0] + verstr = r.stdout.splitlines()[0] # last word of line is the actual version e.g. v22.99.0-5c6b3d5b3508 verstr = verstr.split()[-1] assert verstr.startswith('v') + # remaining lines are copyright + copyright = r.stdout.split('\n')[1:] + assert copyright[0].startswith('Copyright (C)') - # Only bitcoin-qt prints the copyright message on --version, so store it specifically. - if relpath == 'src/qt/bitcoin-qt': - copyright = r.stdout.split('\n')[1:] + versions.append((abspath, verstr, copyright)) - versions.append((abspath, verstr)) - -if any(verstr.endswith('-dirty') for (_, verstr) in versions): +if any(verstr.endswith('-dirty') for (_, verstr, _) in versions): print("WARNING: Binaries were built from a dirty tree.") print('man pages generated from dirty binaries should NOT be committed.') print('To properly generate man pages, please commit your changes (or discard them), rebuild, then run this script again.') @@ -61,13 +59,13 @@ if any(verstr.endswith('-dirty') for (_, verstr) in versions): with tempfile.NamedTemporaryFile('w', suffix='.h2m') as footer: # Create copyright footer, and write it to a temporary include file. - assert copyright + # Copyright is the same for all binaries, so just use the first. footer.write('[COPYRIGHT]\n') - footer.write('\n'.join(copyright).strip()) + footer.write('\n'.join(versions[0][2]).strip()) footer.flush() # Call the binaries through help2man to produce a manual page for each of them. - for (abspath, verstr) in versions: + for (abspath, verstr, _) in versions: outname = os.path.join(mandir, os.path.basename(abspath) + '.1') print(f'Generating {outname}…') subprocess.run([help2man, '-N', '--version-string=' + verstr, '--include=' + footer.name, '-o', outname, abspath], check=True)