summaryrefslogtreecommitdiff
path: root/libcxx/utils/graph_header_deps.py
blob: bb5889f4e97796fda496116b82b74a12a19e476d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/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("}")