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

[Lorenz] Copy graph metadata in modularization_stats.py

Bug: 1115268
Change-Id: Ib08fa726f29a39e857f2ee61ba72deac0c9de0f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2510771Reviewed-by: default avatarMohamed Heikal <mheikal@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822804}
parent 4e663182
...@@ -162,7 +162,7 @@ def main(): ...@@ -162,7 +162,7 @@ def main():
help='Path to the file to write the list of cycles to.') help='Path to the file to write the list of cycles to.')
args = arg_parser.parse_args() args = arg_parser.parse_args()
_, package_graph = serialization.load_class_and_package_graphs_from_file( _, package_graph, _ = serialization.load_class_and_package_graphs_from_file(
args.file) args.file)
all_cycles = find_cycles(package_graph, args.cycle_length) all_cycles = find_cycles(package_graph, args.cycle_length)
......
...@@ -18,6 +18,10 @@ import serialization ...@@ -18,6 +18,10 @@ import serialization
CLASSES_TO_COUNT_INBOUND = ['ChromeActivity', 'ChromeTabbedActivity'] CLASSES_TO_COUNT_INBOUND = ['ChromeActivity', 'ChromeTabbedActivity']
def _copy_metadata(metadata: Dict) -> Dict[str, str]:
return {f'meta_{key}': value for key, value in metadata.items()}
def _generate_graph_sizes( def _generate_graph_sizes(
class_graph: class_dependency.JavaClassDependencyGraph, class_graph: class_dependency.JavaClassDependencyGraph,
package_graph: package_dependency.JavaPackageDependencyGraph package_graph: package_dependency.JavaPackageDependencyGraph
...@@ -87,10 +91,11 @@ def main(): ...@@ -87,10 +91,11 @@ def main():
'stdout.') 'stdout.')
arguments = arg_parser.parse_args() arguments = arg_parser.parse_args()
class_graph, package_graph = \ class_graph, package_graph, graph_metadata = \
serialization.load_class_and_package_graphs_from_file(arguments.file) serialization.load_class_and_package_graphs_from_file(arguments.file)
stats = {} stats = {}
stats.update(_copy_metadata(graph_metadata))
stats.update(_generate_graph_sizes(class_graph, package_graph)) stats.update(_generate_graph_sizes(class_graph, package_graph))
stats.update(_generate_inbound_stats(class_graph, stats.update(_generate_inbound_stats(class_graph,
CLASSES_TO_COUNT_INBOUND)) CLASSES_TO_COUNT_INBOUND))
......
...@@ -293,7 +293,7 @@ def main(): ...@@ -293,7 +293,7 @@ def main():
ignore_same_package=arguments.ignore_same_package, ignore_same_package=arguments.ignore_same_package,
fully_qualified=arguments.fully_qualified) fully_qualified=arguments.fully_qualified)
class_graph, package_graph = \ class_graph, package_graph, _ = \
serialization.load_class_and_package_graphs_from_file(arguments.file) serialization.load_class_and_package_graphs_from_file(arguments.file)
valid_class_names = [] valid_class_names = []
......
...@@ -81,7 +81,7 @@ def main(): ...@@ -81,7 +81,7 @@ def main():
'browser.customtabs and browser.customtabs.content.') 'browser.customtabs and browser.customtabs.content.')
arguments = arg_parser.parse_args() arguments = arg_parser.parse_args()
_, package_graph = serialization.load_class_and_package_graphs_from_file( _, package_graph, _ = serialization.load_class_and_package_graphs_from_file(
arguments.file) arguments.file)
package_graph_keys = [node.name for node in package_graph.nodes] package_graph_keys = [node.name for node in package_graph.nodes]
valid_keys = print_dependencies_helper.get_valid_package_keys_matching( valid_keys = print_dependencies_helper.get_valid_package_keys_matching(
......
...@@ -132,7 +132,8 @@ def dump_class_and_package_graphs_to_file( ...@@ -132,7 +132,8 @@ def dump_class_and_package_graphs_to_file(
def load_class_graph_from_file( def load_class_graph_from_file(
filename: str) -> class_dependency.JavaClassDependencyGraph: filename: str
) -> Tuple[class_dependency.JavaClassDependencyGraph, Dict]:
"""Recreates a JavaClassDependencyGraph from a JSON file. """Recreates a JavaClassDependencyGraph from a JSON file.
The file is expected to be in the format dumped by The file is expected to be in the format dumped by
...@@ -141,13 +142,14 @@ def load_class_graph_from_file( ...@@ -141,13 +142,14 @@ def load_class_graph_from_file(
with open(filename, 'r') as json_file: with open(filename, 'r') as json_file:
json_obj = json.load(json_file) json_obj = json.load(json_file)
class_graph_json_obj = json_obj[json_consts.CLASS_GRAPH] class_graph_json_obj = json_obj[json_consts.CLASS_GRAPH]
return create_class_graph_from_json_obj(class_graph_json_obj) return create_class_graph_from_json_obj(
class_graph_json_obj), json_obj[json_consts.BUILD_METADATA]
def load_class_and_package_graphs_from_file( def load_class_and_package_graphs_from_file(
filename: str filename: str
) -> Tuple[class_dependency.JavaClassDependencyGraph, ) -> Tuple[class_dependency.JavaClassDependencyGraph, package_dependency.
package_dependency.JavaPackageDependencyGraph]: JavaPackageDependencyGraph, Dict]:
"""Recreates a Java(Class+Package)DependencyGraph from a JSON file. """Recreates a Java(Class+Package)DependencyGraph from a JSON file.
The file is expected to be in the format dumped by The file is expected to be in the format dumped by
...@@ -159,6 +161,6 @@ def load_class_and_package_graphs_from_file( ...@@ -159,6 +161,6 @@ def load_class_and_package_graphs_from_file(
a serialized package graph for other consumers of the JSON (eg. JS-side) a serialized package graph for other consumers of the JSON (eg. JS-side)
which may want to bypass the costly conversion from class to package graph. which may want to bypass the costly conversion from class to package graph.
""" """
class_graph = load_class_graph_from_file(filename) class_graph, metadata = load_class_graph_from_file(filename)
package_graph = package_dependency.JavaPackageDependencyGraph(class_graph) package_graph = package_dependency.JavaPackageDependencyGraph(class_graph)
return class_graph, package_graph return class_graph, package_graph, metadata
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