Skip to content

Commit 42c2028

Browse files
committed
doc: Fix gen-manpages, rewrite in Python
Rewrite the manual page generation script in Python. This: - Solves '-' stripping issue (fixes #22681) - Makes that copyright footer is generated again
1 parent a5edd19 commit 42c2028

File tree

4 files changed

+76
-56
lines changed

4 files changed

+76
-56
lines changed

contrib/devtools/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ year rather than two hyphenated years.
7676
If the file already has a copyright for `The Bitcoin Core developers`, the
7777
script will exit.
7878

79-
gen-manpages.sh
79+
gen-manpages.py
8080
===============
8181

8282
A small script to automatically create manpages in ../../doc/man by running the release binaries with the -help option.
@@ -87,7 +87,7 @@ repostitory. To use this tool with out-of-tree builds set `BUILDDIR`. For
8787
example:
8888

8989
```bash
90-
BUILDDIR=$PWD/build contrib/devtools/gen-manpages.sh
90+
BUILDDIR=$PWD/build contrib/devtools/gen-manpages.py
9191
```
9292

9393
security-check.py and test-security-check.py

contrib/devtools/gen-manpages.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2022 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
import os
6+
import subprocess
7+
import sys
8+
import tempfile
9+
10+
BINARIES = [
11+
'src/bitcoind',
12+
'src/bitcoin-cli',
13+
'src/bitcoin-tx',
14+
'src/bitcoin-wallet',
15+
'src/bitcoin-util',
16+
'src/qt/bitcoin-qt',
17+
]
18+
19+
# Paths to external utilities.
20+
git = os.getenv('GIT', 'git')
21+
help2man = os.getenv('HELP2MAN', 'help2man')
22+
23+
# If not otherwise specified, get top directory from git.
24+
topdir = os.getenv('TOPDIR')
25+
if not topdir:
26+
r = subprocess.run([git, 'rev-parse', '--show-toplevel'], stdout=subprocess.PIPE, check=True, universal_newlines=True)
27+
topdir = r.stdout.rstrip()
28+
29+
# Get input and output directories.
30+
builddir = os.getenv('BUILDDIR', topdir)
31+
mandir = os.getenv('MANDIR', os.path.join(topdir, 'doc/man'))
32+
33+
# Verify that all the required binaries are usable, and extract copyright
34+
# message in a first pass.
35+
copyright = None
36+
versions = []
37+
for relpath in BINARIES:
38+
abspath = os.path.join(builddir, relpath)
39+
try:
40+
r = subprocess.run([abspath, '--version'], stdout=subprocess.PIPE, universal_newlines=True)
41+
except IOError:
42+
print(f'{abspath} not found or not an executable', file=sys.stderr)
43+
sys.exit(1)
44+
# take first line (which must contain version)
45+
verstr = r.stdout.split('\n')[0]
46+
# last word of line is the actual version e.g. v22.99.0-5c6b3d5b3508
47+
verstr = verstr.split()[-1]
48+
assert verstr.startswith('v')
49+
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:]
53+
54+
versions.append((abspath, verstr))
55+
56+
if any(verstr.endswith('-dirty') for (_, verstr) in versions):
57+
print("WARNING: Binaries were built from a dirty tree.")
58+
print('man pages generated from dirty binaries should NOT be committed.')
59+
print('To properly generate man pages, please commit your changes (or discard them), rebuild, then run this script again.')
60+
print()
61+
62+
with tempfile.NamedTemporaryFile('w', suffix='.h2m') as footer:
63+
# Create copyright footer, and write it to a temporary include file.
64+
assert copyright
65+
footer.write('[COPYRIGHT]\n')
66+
footer.write('\n'.join(copyright).strip())
67+
footer.flush()
68+
69+
# Call the binaries through help2man to produce a manual page for each of them.
70+
for (abspath, verstr) in versions:
71+
outname = os.path.join(mandir, os.path.basename(abspath) + '.1')
72+
print(f'Generating {outname}…')
73+
subprocess.run([help2man, '-N', '--version-string=' + verstr, '--include=' + footer.name, '-o', outname, abspath], check=True)

contrib/devtools/gen-manpages.sh

Lines changed: 0 additions & 53 deletions
This file was deleted.

doc/release-process.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Release Process
66
### Before every release candidate
77

88
* Update translations see [translation_process.md](https://github.com/bitcoin/bitcoin/blob/master/doc/translation_process.md#synchronising-translations).
9-
* Update manpages, see [gen-manpages.sh](https://github.com/bitcoin/bitcoin/blob/master/contrib/devtools/README.md#gen-manpagessh).
9+
* Update manpages, see [gen-manpages.py](https://github.com/bitcoin/bitcoin/blob/master/contrib/devtools/README.md#gen-manpagespy).
1010
* Update release candidate version in `configure.ac` (`CLIENT_VERSION_RC`).
1111

1212
### Before every major and minor release

0 commit comments

Comments
 (0)