|
| 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/dashd', |
| 12 | +'src/dash-cli', |
| 13 | +'src/dash-tx', |
| 14 | +'src/dash-wallet', |
| 15 | +#'src/dash-util', |
| 16 | +'src/qt/dash-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 dash-qt prints the copyright message on --version, so store it specifically. |
| 51 | + if relpath == 'src/qt/dash-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) |
0 commit comments