Commit 3f85aed2 authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

[Lorenz] Add options to print only inbound or only outbound deps

print_class_dependencies.py is used to audit deps, and normally we look
at outbound deps and inbound deps at different points and in different
situations.

Change-Id: Ie331b7502ff09827a3ddf08a6c2cc3b8d7183b90
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2391593
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarMohamed Heikal <mheikal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804328}
parent 5dc8b4e0
...@@ -5,23 +5,37 @@ ...@@ -5,23 +5,37 @@
"""Command-line tool for printing class-level dependencies.""" """Command-line tool for printing class-level dependencies."""
import argparse import argparse
from dataclasses import dataclass
import class_dependency
import graph import graph
import print_dependencies_helper import print_dependencies_helper
import serialization import serialization
def print_class_dependencies_for_key(class_graph, key): @dataclass
class PrintMode:
"""Options of how and which dependencies to output."""
inbound: bool
outbound: bool
def print_class_dependencies_for_key(
class_graph: class_dependency.JavaClassDependencyGraph, key: str,
print_mode: PrintMode):
"""Prints dependencies for a valid key into the class graph.""" """Prints dependencies for a valid key into the class graph."""
node = class_graph.get_node_by_key(key) node: class_dependency.JavaClass = class_graph.get_node_by_key(key)
print(f'{len(node.inbound)} inbound dependency(ies) for {node.name}:') if print_mode.inbound:
for inbound_dep in graph.sorted_nodes_by_name(node.inbound): print(f'{len(node.inbound)} inbound dependency(ies) for {node.name}:')
print(f'\t{inbound_dep.name}') for inbound_dep in graph.sorted_nodes_by_name(node.inbound):
print(f'\t{inbound_dep.name}')
print(f'{len(node.outbound)} outbound dependency(ies) for {node.name}:') if print_mode.outbound:
for outbound_dep in graph.sorted_nodes_by_name(node.outbound): print(
print(f'\t{outbound_dep.name}') f'{len(node.outbound)} outbound dependency(ies) for {node.name}:')
for outbound_dep in graph.sorted_nodes_by_name(node.outbound):
print(f'\t{outbound_dep.name}')
def main(): def main():
...@@ -47,8 +61,20 @@ def main(): ...@@ -47,8 +61,20 @@ def main():
'`org.chromium.browser.AppHooks`. Specify multiple classes with a ' '`org.chromium.browser.AppHooks`. Specify multiple classes with a '
'comma-separated list, for example ' 'comma-separated list, for example '
'`ChromeActivity,ChromeTabbedActivity`') '`ChromeActivity,ChromeTabbedActivity`')
direction_arg_group = arg_parser.add_mutually_exclusive_group()
direction_arg_group.add_argument('--inbound',
dest='inbound_only',
action='store_true',
help='Print inbound dependencies only.')
direction_arg_group.add_argument('--outbound',
dest='outbound_only',
action='store_true',
help='Print outbound dependencies only.')
arguments = arg_parser.parse_args() arguments = arg_parser.parse_args()
print_mode = PrintMode(inbound=not arguments.outbound_only,
outbound=not arguments.inbound_only)
class_graph = serialization.load_class_graph_from_file(arguments.file) class_graph = serialization.load_class_graph_from_file(arguments.file)
class_graph_keys = [node.name for node in class_graph.nodes] class_graph_keys = [node.name for node in class_graph.nodes]
...@@ -70,7 +96,8 @@ def main(): ...@@ -70,7 +96,8 @@ def main():
print(f'\t{valid_key}') print(f'\t{valid_key}')
else: else:
print(f'Printing class dependencies for {valid_keys[0]}:') print(f'Printing class dependencies for {valid_keys[0]}:')
print_class_dependencies_for_key(class_graph, valid_keys[0]) print_class_dependencies_for_key(class_graph, valid_keys[0],
print_mode)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment