Merge #20468: build: warn when generating man pages for binaries built from a dirty branch

6690adba08 Warn when binaries are built from a dirty branch. (Tyler Chambers)

Pull request description:

  - Adjusted `--version` flag behavior in bitcoind and bitcoin-wallet to have the same behavior.
  - Added `--version` flag to bitcoin-tx to match.
  - Added functionality in gen-manpages.sh to error when attempting to generate man pages for binaries built from a dirty branch.

  mitigates problem with  issue #20412

ACKs for top commit:
  laanwj:
    Tested ACK 6690adba08

Tree-SHA512: b5ca509f1a57f66808c2bebc4b710ca00c6fec7b5ebd7eef58018e28e716f5f2358e36551b8a4df571bf3204baed565a297aeefb93990e7a99add502b97ee1b8
This commit is contained in:
Wladimir J. van der Laan
2020-12-07 10:15:32 +01:00
4 changed files with 44 additions and 21 deletions

View File

@@ -18,6 +18,22 @@ BITCOINQT=${BITCOINQT:-$BINDIR/qt/bitcoin-qt}
[ ! -x $BITCOIND ] && echo "$BITCOIND not found or not executable." && exit 1 [ ! -x $BITCOIND ] && echo "$BITCOIND not found or not executable." && exit 1
# Don't allow man pages to be generated for binaries built from a dirty tree
DIRTY=""
for cmd in $BITCOIND $BITCOINCLI $BITCOINTX $WALLET_TOOL $BITCOINQT; do
VERSION_OUTPUT=$($cmd --version)
if [[ $VERSION_OUTPUT == *"dirty"* ]]; then
DIRTY="${DIRTY}${cmd}\n"
fi
done
if [ -n "$DIRTY" ]
then
echo -e "WARNING: the following binaries were built from a dirty tree:\n"
echo -e $DIRTY
echo "man pages generated from dirty binaries should NOT be committed."
echo "To properly generate man pages, please commit your changes to the above binaries, rebuild them, then run this script again."
fi
# The autodetected version git tag can screw up manpage output a little bit # The autodetected version git tag can screw up manpage output a little bit
read -r -a BTCVER <<< "$($BITCOINCLI --version | head -n1 | awk -F'[ -]' '{ print $6, $7 }')" read -r -a BTCVER <<< "$($BITCOINCLI --version | head -n1 | awk -F'[ -]' '{ print $6, $7 }')"

View File

@@ -40,6 +40,7 @@ static void SetupBitcoinTxArgs(ArgsManager &argsman)
{ {
SetupHelpOptions(argsman); SetupHelpOptions(argsman);
argsman.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-create", "Create new, empty TX.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-create", "Create new, empty TX.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-json", "Select JSON output", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-json", "Select JSON output", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-txid", "Output only the hex-encoded transaction id of the resultant transaction.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-txid", "Output only the hex-encoded transaction id of the resultant transaction.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
@@ -95,13 +96,16 @@ static int AppInitRawTx(int argc, char* argv[])
fCreateBlank = gArgs.GetBoolArg("-create", false); fCreateBlank = gArgs.GetBoolArg("-create", false);
if (argc < 2 || HelpRequested(gArgs)) { if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
// First part of help message is specific to this utility // First part of help message is specific to this utility
std::string strUsage = PACKAGE_NAME " bitcoin-tx utility version " + FormatFullVersion() + "\n\n" + std::string strUsage = PACKAGE_NAME " bitcoin-tx utility version " + FormatFullVersion() + "\n";
"Usage: bitcoin-tx [options] <hex-tx> [commands] Update hex-encoded bitcoin transaction\n" + if (!gArgs.IsArgSet("-version")) {
"or: bitcoin-tx [options] -create [commands] Create hex-encoded bitcoin transaction\n" + strUsage += "\n"
"\n"; "Usage: bitcoin-tx [options] <hex-tx> [commands] Update hex-encoded bitcoin transaction\n"
strUsage += gArgs.GetHelpMessage(); "or: bitcoin-tx [options] -create [commands] Create hex-encoded bitcoin transaction\n"
"\n";
strUsage += gArgs.GetHelpMessage();
}
tfm::format(std::cout, "%s", strUsage); tfm::format(std::cout, "%s", strUsage);

View File

@@ -24,6 +24,7 @@ static void SetupWalletToolArgs(ArgsManager& argsman)
SetupHelpOptions(argsman); SetupHelpOptions(argsman);
SetupChainParamsBaseOptions(argsman); SetupChainParamsBaseOptions(argsman);
argsman.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-wallet=<wallet-name>", "Specify wallet name", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::OPTIONS); argsman.AddArg("-wallet=<wallet-name>", "Specify wallet name", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::OPTIONS);
argsman.AddArg("-debug=<category>", "Output debugging information (default: 0).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); argsman.AddArg("-debug=<category>", "Output debugging information (default: 0).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
@@ -42,16 +43,18 @@ static bool WalletAppInit(int argc, char* argv[])
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error_message); tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error_message);
return false; return false;
} }
if (argc < 2 || HelpRequested(gArgs)) { if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
std::string usage = strprintf("%s bitcoin-wallet version", PACKAGE_NAME) + " " + FormatFullVersion() + "\n\n" + std::string strUsage = strprintf("%s bitcoin-wallet version", PACKAGE_NAME) + " " + FormatFullVersion() + "\n";
"bitcoin-wallet is an offline tool for creating and interacting with " PACKAGE_NAME " wallet files.\n" + if (!gArgs.IsArgSet("-version")) {
"By default bitcoin-wallet will act on wallets in the default mainnet wallet directory in the datadir.\n" + strUsage += "\n"
"To change the target wallet, use the -datadir, -wallet and -testnet/-regtest arguments.\n\n" + "bitcoin-wallet is an offline tool for creating and interacting with " PACKAGE_NAME " wallet files.\n"
"Usage:\n" + "By default bitcoin-wallet will act on wallets in the default mainnet wallet directory in the datadir.\n"
" bitcoin-wallet [options] <command>\n\n" + "To change the target wallet, use the -datadir, -wallet and -testnet/-regtest arguments.\n\n"
gArgs.GetHelpMessage(); "Usage:\n"
" bitcoin-wallet [options] <command>\n";
tfm::format(std::cout, "%s", usage); strUsage += "\n" + gArgs.GetHelpMessage();
}
tfm::format(std::cout, "%s", strUsage);
return false; return false;
} }

View File

@@ -57,11 +57,11 @@ static bool AppInit(int argc, char* argv[])
if (HelpRequested(args) || args.IsArgSet("-version")) { if (HelpRequested(args) || args.IsArgSet("-version")) {
std::string strUsage = PACKAGE_NAME " version " + FormatFullVersion() + "\n"; std::string strUsage = PACKAGE_NAME " version " + FormatFullVersion() + "\n";
if (args.IsArgSet("-version")) { if (!args.IsArgSet("-version")) {
strUsage += FormatParagraph(LicenseInfo()) + "\n"; strUsage += FormatParagraph(LicenseInfo()) + "\n"
} else { "\nUsage: bitcoind [options] Start " PACKAGE_NAME "\n"
strUsage += "\nUsage: bitcoind [options] Start " PACKAGE_NAME "\n"; "\n";
strUsage += "\n" + args.GetHelpMessage(); strUsage += args.GetHelpMessage();
} }
tfm::format(std::cout, "%s", strUsage); tfm::format(std::cout, "%s", strUsage);