Skip to content

Commit 6690adb

Browse files
Tyler ChambersTyler Chambers
authored andcommitted
Warn when binaries are built from a dirty branch.
Adjusted version flag behavior in bitcoin-tx, bitcoin-wallet, and bitcoind to match. Added functionality in gen-manpages.sh to warning when attempting to generate man pages for binaries built from a dirty branch.
1 parent 555b5d1 commit 6690adb

File tree

4 files changed

+44
-21
lines changed

4 files changed

+44
-21
lines changed

contrib/devtools/gen-manpages.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,22 @@ BITCOINQT=${BITCOINQT:-$BINDIR/qt/bitcoin-qt}
1818

1919
[ ! -x $BITCOIND ] && echo "$BITCOIND not found or not executable." && exit 1
2020

21+
# Don't allow man pages to be generated for binaries built from a dirty tree
22+
DIRTY=""
23+
for cmd in $BITCOIND $BITCOINCLI $BITCOINTX $WALLET_TOOL $BITCOINQT; do
24+
VERSION_OUTPUT=$($cmd --version)
25+
if [[ $VERSION_OUTPUT == *"dirty"* ]]; then
26+
DIRTY="${DIRTY}${cmd}\n"
27+
fi
28+
done
29+
if [ -n "$DIRTY" ]
30+
then
31+
echo -e "WARNING: the following binaries were built from a dirty tree:\n"
32+
echo -e $DIRTY
33+
echo "man pages generated from dirty binaries should NOT be committed."
34+
echo "To properly generate man pages, please commit your changes to the above binaries, rebuild them, then run this script again."
35+
fi
36+
2137
# The autodetected version git tag can screw up manpage output a little bit
2238
read -r -a BTCVER <<< "$($BITCOINCLI --version | head -n1 | awk -F'[ -]' '{ print $6, $7 }')"
2339

src/bitcoin-tx.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static void SetupBitcoinTxArgs(ArgsManager &argsman)
4040
{
4141
SetupHelpOptions(argsman);
4242

43+
argsman.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
4344
argsman.AddArg("-create", "Create new, empty TX.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
4445
argsman.AddArg("-json", "Select JSON output", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
4546
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[])
9596

9697
fCreateBlank = gArgs.GetBoolArg("-create", false);
9798

98-
if (argc < 2 || HelpRequested(gArgs)) {
99+
if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
99100
// First part of help message is specific to this utility
100-
std::string strUsage = PACKAGE_NAME " bitcoin-tx utility version " + FormatFullVersion() + "\n\n" +
101-
"Usage: bitcoin-tx [options] <hex-tx> [commands] Update hex-encoded bitcoin transaction\n" +
102-
"or: bitcoin-tx [options] -create [commands] Create hex-encoded bitcoin transaction\n" +
103-
"\n";
104-
strUsage += gArgs.GetHelpMessage();
101+
std::string strUsage = PACKAGE_NAME " bitcoin-tx utility version " + FormatFullVersion() + "\n";
102+
if (!gArgs.IsArgSet("-version")) {
103+
strUsage += "\n"
104+
"Usage: bitcoin-tx [options] <hex-tx> [commands] Update hex-encoded bitcoin transaction\n"
105+
"or: bitcoin-tx [options] -create [commands] Create hex-encoded bitcoin transaction\n"
106+
"\n";
107+
strUsage += gArgs.GetHelpMessage();
108+
}
105109

106110
tfm::format(std::cout, "%s", strUsage);
107111

src/bitcoin-wallet.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ static void SetupWalletToolArgs(ArgsManager& argsman)
2424
SetupHelpOptions(argsman);
2525
SetupChainParamsBaseOptions(argsman);
2626

27+
argsman.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
2728
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
2829
argsman.AddArg("-wallet=<wallet-name>", "Specify wallet name", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::OPTIONS);
2930
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[])
4243
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error_message);
4344
return false;
4445
}
45-
if (argc < 2 || HelpRequested(gArgs)) {
46-
std::string usage = strprintf("%s bitcoin-wallet version", PACKAGE_NAME) + " " + FormatFullVersion() + "\n\n" +
47-
"bitcoin-wallet is an offline tool for creating and interacting with " PACKAGE_NAME " wallet files.\n" +
48-
"By default bitcoin-wallet will act on wallets in the default mainnet wallet directory in the datadir.\n" +
49-
"To change the target wallet, use the -datadir, -wallet and -testnet/-regtest arguments.\n\n" +
50-
"Usage:\n" +
51-
" bitcoin-wallet [options] <command>\n\n" +
52-
gArgs.GetHelpMessage();
53-
54-
tfm::format(std::cout, "%s", usage);
46+
if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
47+
std::string strUsage = strprintf("%s bitcoin-wallet version", PACKAGE_NAME) + " " + FormatFullVersion() + "\n";
48+
if (!gArgs.IsArgSet("-version")) {
49+
strUsage += "\n"
50+
"bitcoin-wallet is an offline tool for creating and interacting with " PACKAGE_NAME " wallet files.\n"
51+
"By default bitcoin-wallet will act on wallets in the default mainnet wallet directory in the datadir.\n"
52+
"To change the target wallet, use the -datadir, -wallet and -testnet/-regtest arguments.\n\n"
53+
"Usage:\n"
54+
" bitcoin-wallet [options] <command>\n";
55+
strUsage += "\n" + gArgs.GetHelpMessage();
56+
}
57+
tfm::format(std::cout, "%s", strUsage);
5558
return false;
5659
}
5760

src/bitcoind.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ static bool AppInit(int argc, char* argv[])
5757
if (HelpRequested(args) || args.IsArgSet("-version")) {
5858
std::string strUsage = PACKAGE_NAME " version " + FormatFullVersion() + "\n";
5959

60-
if (args.IsArgSet("-version")) {
61-
strUsage += FormatParagraph(LicenseInfo()) + "\n";
62-
} else {
63-
strUsage += "\nUsage: bitcoind [options] Start " PACKAGE_NAME "\n";
64-
strUsage += "\n" + args.GetHelpMessage();
60+
if (!args.IsArgSet("-version")) {
61+
strUsage += FormatParagraph(LicenseInfo()) + "\n"
62+
"\nUsage: bitcoind [options] Start " PACKAGE_NAME "\n"
63+
"\n";
64+
strUsage += args.GetHelpMessage();
6565
}
6666

6767
tfm::format(std::cout, "%s", strUsage);

0 commit comments

Comments
 (0)