contrib: address gen-manpages feedback from #24263

Co-authored-by: Carl Dong <contact@carldong.me>
pull/826/head
fanquake 3 years ago
parent 2618fb8d15
commit 5a89bed410
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1

@ -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)

Loading…
Cancel
Save