1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-23 03:21:12 +03:00
Files
postgres/doc/src/sgml/xmltools_dep_wrapper
Andres Freund 29668e3186 meson: docs: Add xml{lint,proc} wrapper to collect dependencies
meson/ninja do not support specifying dependencies via globs (as those make it
significantly more expensive to check the current build state). Instead
targets should emit dependency information when running that then can be
cheaply re-checked during future builds.

To handle xmllint and xsltproc invocations in the docs, add and use a wrapper
that uses --load-trace to collect dependency information.

Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
Author: Nazir Bilal Yavuz <byavuz81@gmail.com>
Author: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/c5736f70-bb6d-8d25-e35c-e3d886e4e905@enterprisedb.com
2022-10-05 09:56:05 -07:00

55 lines
1.8 KiB
Python

#!/usr/bin/env python3
# A small wrapper around xmllint and xsltproc that collects dependency
# information (in gcc's format) using --load-trace.
import argparse
import re
import subprocess
import sys
parser = argparse.ArgumentParser(
description='generate dependency file for docs')
parser.add_argument('--targetname', type=str, required=False, nargs='+')
parser.add_argument('--depfile', type=str, required=False)
parser.add_argument('--tool', type=str, required=True)
parser.add_argument('flags', nargs='*')
args = parser.parse_args()
if args.depfile:
command = [args.tool, '--load-trace'] + args.flags
# list of targets that depend on the loaded files we see via --load-trace
line_start = ' '.join(args.targetname) + ': '
# --load-trace flag displays all the documents loaded during the processing
# to stderr
res = subprocess.run(command, stderr=subprocess.PIPE,
universal_newlines=True)
line_re = re.compile('^Loaded URL="([^"]+)"')
with open(args.depfile, 'w') as f:
for line in res.stderr.splitlines():
m = re.match(line_re, line)
# continue to show errors
if m is None:
print(line, file=sys.stderr)
continue
# Absolute paths are printed as file://, relative paths as-is. We
# don't care about http://, as a) those will be printed even if
# resolved locally b) we couldn't have a dependency anyway.
fname = m.group(1)
if fname.startswith('http://'):
continue
if fname.startswith('file://'):
fname = fname.split('file://')[1]
f.write(line_start + fname + '\n')
else:
command = [args.tool] + args.flags
res = subprocess.run(command)
exit(res.returncode)