1#!/usr/bin/env python
2# ===----------------------------------------------------------------------===##
3#
4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5# See https://llvm.org/LICENSE.txt for license information.
6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7#
8# ===----------------------------------------------------------------------===##
9
10import argparse
11import sys
12
13if __name__ == "__main__":
14    """Converts a header dependency CSV file to Graphviz dot file.
15
16    The header dependency CSV files are found on the directory
17    libcxx/test/libcxx/transitive_includes
18    """
19
20    parser = argparse.ArgumentParser(
21        description="""Converts a libc++ dependency CSV file to a Graphviz dot file.
22For example:
23  libcxx/utils/graph_header_deps.py libcxx/test/libcxx/transitive_includes/cxx20.csv | dot -Tsvg > graph.svg
24""",
25        formatter_class=argparse.RawDescriptionHelpFormatter,
26    )
27    parser.add_argument(
28        "input",
29        default=None,
30        metavar="FILE",
31        help="The header dependency CSV file.",
32    )
33    options = parser.parse_args()
34
35    print(
36        """digraph includes {
37graph [nodesep=0.5, ranksep=1];
38node [shape=box, width=4];"""
39    )
40    with open(options.input, "r") as f:
41        for line in f.readlines():
42            elements = line.rstrip().split(" ")
43            assert len(elements) == 2
44
45            print(f'\t"{elements[0]}" -> "{elements[1]}"')
46
47    print("}")
48