Commit ae67ca99 authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

[Lorenz] Group deps by build target in print_class_dependencies.py

This makes it easier to audit dependencies.

Change-Id: I1ea9db294f947f261b050dc61399ff93ef89dc69
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2391655
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarMohamed Heikal <mheikal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804410}
parent 7bc33826
......@@ -79,6 +79,8 @@ class JavaClass(graph.Node):
@property
def build_targets(self) -> Set[str]:
"""Which build target(s) contain the class."""
# TODO(crbug.com/1124836): Make this return a List, sorted by
# importance.
return self._build_targets
@build_targets.setter
......
......@@ -22,13 +22,32 @@ class PrintMode:
build_targets: bool
def print_with_indent(indent, message):
print(' ' * indent + message)
def print_class_nodes_grouped_by_target(
class_nodes: List[class_dependency.JavaClass], print_mode: PrintMode):
# TODO(crbug.com/1124836): This is not quite correct because
# sets considered equal can be converted to different strings. Fix this by
# making JavaClass.build_targets return a List instead of a Set.
class_nodes = sorted(class_nodes, key=lambda c: str(c.build_targets))
last_build_target = None
for class_node in class_nodes:
build_target = str(class_node.build_targets)
if last_build_target != build_target:
print_with_indent(4, f'[{", ".join(class_node.build_targets)}]')
last_build_target = build_target
print_with_indent(8, f'{class_node.name}')
def print_class_nodes(class_nodes: List[class_dependency.JavaClass],
print_mode: PrintMode):
for class_node in class_nodes:
output = f'\t{class_node.name}'
if print_mode.build_targets:
output += f' [{", ".join(class_node.build_targets)}]'
print(output)
if print_mode.build_targets:
print_class_nodes_grouped_by_target(class_nodes, print_mode)
else:
for class_node in class_nodes:
print_with_indent(8, f'{class_node.name}')
def print_class_dependencies_for_key(
......@@ -38,12 +57,12 @@ def print_class_dependencies_for_key(
node: class_dependency.JavaClass = class_graph.get_node_by_key(key)
if print_mode.inbound:
print(f'{len(node.inbound)} inbound dependency(ies) for {node.name}:')
print(f'{len(node.inbound)} inbound dependency(ies) into {node.name}:')
print_class_nodes(graph.sorted_nodes_by_name(node.inbound), print_mode)
if print_mode.outbound:
print(
f'{len(node.outbound)} outbound dependency(ies) for {node.name}:')
f'{len(node.outbound)} outbound dependency(ies) from {node.name}:')
print_class_nodes(graph.sorted_nodes_by_name(node.outbound),
print_mode)
......
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