3 # A small wrapper around xmllint and xsltproc that collects dependency
4 # information (in gcc's format) using --load-trace.
11 parser = argparse.ArgumentParser(
12 description='generate dependency file for docs')
14 parser.add_argument('--targetname', type=str, required=False, nargs='+')
15 parser.add_argument('--depfile', type=str, required=False)
16 parser.add_argument('--tool', type=str, required=True)
17 parser.add_argument('flags', nargs='*')
19 args = parser.parse_args()
22 command = [args.tool, '--load-trace'] + args.flags
24 # list of targets that depend on the loaded files we see via --load-trace
25 line_start = ' '.join(args.targetname) + ': '
27 # --load-trace flag displays all the documents loaded during the processing
29 res = subprocess.run(command, stderr=subprocess.PIPE,
30 universal_newlines=True)
32 line_re = re.compile('^Loaded URL="([^"]+)"')
33 with open(args.depfile, 'w') as f:
34 for line in res.stderr.splitlines():
35 m = re.match(line_re, line)
37 # continue to show errors
39 print(line, file=sys.stderr)
41 # Absolute paths are printed as file://, relative paths as-is. We
42 # don't care about http://, as a) those will be printed even if
43 # resolved locally b) we couldn't have a dependency anyway.
45 if fname.startswith('http://'):
47 if fname.startswith('file://'):
48 fname = fname.split('file://')[1]
49 f.write(line_start + fname + '\n')
51 command = [args.tool] + args.flags
52 res = subprocess.run(command)