• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
11
12if __name__ == "__main__":
13    """Converts a header dependency CSV file to Graphviz dot file.
14
15    The header dependency CSV files are found on the directory
16    libcxx/test/libcxx/transitive_includes
17    """
18
19    parser = argparse.ArgumentParser(
20        description="""Converts a libc++ dependency CSV file to a Graphviz dot file.
21For example:
22  libcxx/utils/graph_header_deps.py libcxx/test/libcxx/transitive_includes/cxx20.csv | dot -Tsvg > graph.svg
23""",
24        formatter_class=argparse.RawDescriptionHelpFormatter,
25    )
26    parser.add_argument(
27        "input",
28        default=None,
29        metavar="FILE",
30        help="The header dependency CSV file.",
31    )
32    options = parser.parse_args()
33
34    print(
35        """digraph includes {
36graph [nodesep=0.5, ranksep=1];
37node [shape=box, width=4];"""
38    )
39    with open(options.input, "r") as f:
40        for line in f.readlines():
41            elements = line.rstrip().split(" ")
42            assert len(elements) == 2
43
44            print(f'\t"{elements[0]}" -> "{elements[1]}"')
45
46    print("}")
47