llvm-project/libcxx/utils/graph_header_deps.py
Mark de Wever ddb6c2b301 [libc++] Rewrites graph_header_deps.py.
The new version is a lot simpler and has less option which were not
used. This uses the CSV files as generated by D133127 as input data.

The current Python script has more features but uses a simple "grep"
making the output less accurate:
- Conditionally included header are always included. This is an issue
  since part of our includes are unneeded transitive includes. Based on
  the language version they may be omitted. The script however always
  includes them.
- Includes in comments are processed as-if they are includes. This is an
  issue when comments explain how certain data is generated; of course
  there are digraphs which the script omits.

This implementation uses Clang's --trace-includes to generate the includes
per header. This means the input of the generation script always has the
real list of includes.

Libc++ is moving from large monolithic Standard headers to more fine
grained headers. For example, algorithm includes every header in
`__algorithm`. Adding all these detail headers in the graph makes the
output unusable. Instead it only shows the Standard headers. The
transitive includes of the detail headers are parsed and "attributed" to
the Standard header including them. This gives an accurate include graph
without the unneeded clutter. Note that this graph is still big.

This changes fixes the cyclic dependency issue with the previous version
of the tool so the markers and its documentation is removed.

Since the input has no cycles the CI test is removed.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D134188
2022-09-25 15:06:21 +02:00

48 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python
# ===----------------------------------------------------------------------===##
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# ===----------------------------------------------------------------------===##
import argparse
import sys
if __name__ == "__main__":
"""Converts a header dependency CSV file to Graphviz dot file.
The header dependency CSV files are found on the directory
libcxx/test/libcxx/transitive_includes
"""
parser = argparse.ArgumentParser(
description="""Converts a libc++ dependency CSV file to a Graphviz dot file.
For example:
libcxx/utils/graph_header_deps.py libcxx/test/libcxx/transitive_includes/cxx20.csv | dot -Tsvg > graph.svg
""",
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument(
"input",
default=None,
metavar="FILE",
help="The header dependency CSV file.",
)
options = parser.parse_args()
print(
"""digraph includes {
graph [nodesep=0.5, ranksep=1];
node [shape=box, width=4];"""
)
with open(options.input, "r") as f:
for line in f.readlines():
elements = line.rstrip().split(" ")
assert len(elements) == 2
print(f'\t"{elements[0]}" -> "{elements[1]}"')
print("}")