tools/android/dependency_analysis/generate_json_dependency_graph.py
def main():
    """Runs jdeps on all JARs a build target depends on.

    Creates a JSON file from the jdeps output."""
    arg_parser = argparse.ArgumentParser(
        description='Runs jdeps (dependency analysis tool) on all JARs a root '
        'build target depends on and writes the resulting dependency graph '
        'into a JSON file. The default root build target is '
        'chrome/android:monochrome_public_bundle.')
    required_arg_group = arg_parser.add_argument_group('required arguments')
    required_arg_group.add_argument('-C',
                                    '--build_output_dir',
                                    required=True,
                                    help='Build output directory.')
    required_arg_group.add_argument(
        '-o',
        '--output',
        required=True,
        help='Path to the file to write JSON output to. Will be created '
        'if it does not yet exist and overwrite existing '
        'content if it does.')
    arg_parser.add_argument('-t',
                            '--target',
                            default=DEFAULT_ROOT_TARGET,
                            help='Root build target.')
    arg_parser.add_argument('-d',
                            '--checkout-dir',
                            help='Path to the chromium checkout directory.')
    arg_parser.add_argument('-j',
                            '--jdeps-path',
                            help='Path to the jdeps executable.')
    arg_parser.add_argument('-g',
                            '--gn-path',
                            default='gn',
                            help='Path to the gn executable.')
    arguments = arg_parser.parse_args()

    if arguments.checkout_dir:
        src_path = pathlib.Path(arguments.checkout_dir)
    else:
        src_path = pathlib.Path(__file__).resolve().parents[3]

    if arguments.jdeps_path:
        jdeps_path = pathlib.Path(arguments.jdeps_path)
    else:
        jdeps_path = src_path.joinpath('third_party/jdk/current/bin/jdeps')

    # gn and git must be run from inside the git checkout.
    os.chdir(src_path)

    cr_position_str = git_utils.get_last_commit_cr_position()
    cr_position = int(cr_position_str) if cr_position_str else 0

    print('Getting list of dependency jars...')
    gn_desc_output = _run_gn_desc_list_dependencies(arguments.build_output_dir,
                                                    arguments.target,
                                                    arguments.gn_path)
    target_jars: JarTargetList = list_original_targets_and_jars(
        gn_desc_output, arguments.build_output_dir, cr_position)

    print('Running jdeps...')
    # jdeps already has some parallelism
    jdeps_process_number = math.ceil(multiprocessing.cpu_count() / 2)
    with multiprocessing.Pool(jdeps_process_number) as pool:
        jar_paths = [target_jar for _, target_jar in target_jars]
        jdeps_outputs = pool.map(functools.partial(_run_jdeps, jdeps_path),
                                 jar_paths)

    print('Parsing jdeps output...')
    jdeps_parser = JavaClassJdepsParser()
    for raw_jdeps_output, (build_target, _) in zip(jdeps_outputs, target_jars):
        jdeps_parser.parse_raw_jdeps_output(build_target, raw_jdeps_output)

    class_graph = jdeps_parser.graph
    print(f'Parsed class-level dependency graph, '
          f'got {class_graph.num_nodes} nodes '
          f'and {class_graph.num_edges} edges.')

    package_graph = package_dependency.JavaPackageDependencyGraph(class_graph)
    print(f'Created package-level dependency graph, '
          f'got {package_graph.num_nodes} nodes '
          f'and {package_graph.num_edges} edges.')

    print(f'Dumping JSON representation to {arguments.output}.')
    serialization.dump_class_and_package_graphs_to_file(
        class_graph, package_graph, arguments.output)
Runs jdeps on all JARs a build target depends on.

    Creates a JSON file from the jdeps output.
Runs jdeps on all JARs a build target depends on.
Creates a JSON file from the jdeps output.
Runs jdeps on all JARs a build target depends on . Creates a JSON file from the jdeps output .
def main():
    arg_parser = argparse.ArgumentParser(
        description='Runs jdeps (dependency analysis tool) on all JARs a root '
        'build target depends on and writes the resulting dependency graph '
        'into a JSON file. The default root build target is '
        'chrome/android:monochrome_public_bundle.')
    required_arg_group = arg_parser.add_argument_group('required arguments')
    required_arg_group.add_argument('-C',
                                    '--build_output_dir',
                                    required=True,
                                    help='Build output directory.')
    required_arg_group.add_argument(
        '-o',
        '--output',
        required=True,
        help='Path to the file to write JSON output to. Will be created '
        'if it does not yet exist and overwrite existing '
        'content if it does.')
    arg_parser.add_argument('-t',
                            '--target',
                            default=DEFAULT_ROOT_TARGET,
                            help='Root build target.')
    arg_parser.add_argument('-d',
                            '--checkout-dir',
                            help='Path to the chromium checkout directory.')
    arg_parser.add_argument('-j',
                            '--jdeps-path',
                            help='Path to the jdeps executable.')
    arg_parser.add_argument('-g',
                            '--gn-path',
                            default='gn',
                            help='Path to the gn executable.')
    arguments = arg_parser.parse_args()
    if arguments.checkout_dir:
        src_path = pathlib.Path(arguments.checkout_dir)
    else:
        src_path = pathlib.Path(__file__).resolve().parents[3]
    if arguments.jdeps_path:
        jdeps_path = pathlib.Path(arguments.jdeps_path)
    else:
        jdeps_path = src_path.joinpath('third_party/jdk/current/bin/jdeps')
    os.chdir(src_path)
    cr_position_str = git_utils.get_last_commit_cr_position()
    cr_position = int(cr_position_str) if cr_position_str else 0
    print('Getting list of dependency jars...')
    gn_desc_output = _run_gn_desc_list_dependencies(arguments.build_output_dir,
                                                    arguments.target,
                                                    arguments.gn_path)
    target_jars: JarTargetList = list_original_targets_and_jars(
        gn_desc_output, arguments.build_output_dir, cr_position)
    print('Running jdeps...')
    jdeps_process_number = math.ceil(multiprocessing.cpu_count() / 2)
    with multiprocessing.Pool(jdeps_process_number) as pool:
        jar_paths = [target_jar for _, target_jar in target_jars]
        jdeps_outputs = pool.map(functools.partial(_run_jdeps, jdeps_path),
                                 jar_paths)
    print('Parsing jdeps output...')
    jdeps_parser = JavaClassJdepsParser()
    for raw_jdeps_output, (build_target, _) in zip(jdeps_outputs, target_jars):
        jdeps_parser.parse_raw_jdeps_output(build_target, raw_jdeps_output)
    class_graph = jdeps_parser.graph
    print(f'Parsed class-level dependency graph, '
          f'got {class_graph.num_nodes} nodes '
          f'and {class_graph.num_edges} edges.')
    package_graph = package_dependency.JavaPackageDependencyGraph(class_graph)
    print(f'Created package-level dependency graph, '
          f'got {package_graph.num_nodes} nodes '
          f'and {package_graph.num_edges} edges.')
    print(f'Dumping JSON representation to {arguments.output}.')
    serialization.dump_class_and_package_graphs_to_file(
        class_graph, package_graph, arguments.output)
def main ( ) : arg_parser = argparse . ArgumentParser ( description = 'Runs jdeps (dependency analysis tool) on all JARs a root ' 'build target depends on and writes the resulting dependency graph ' 'into a JSON file. The default root build target is ' 'chrome/android:monochrome_public_bundle.' ) required_arg_group = arg_parser . add_argument_group ( 'required arguments' ) required_arg_group . add_argument ( '-C' , '--build_output_dir' , required = True , help = 'Build output directory.' ) required_arg_group . add_argument ( '-o' , '--output' , required = True , help = 'Path to the file to write JSON output to. Will be created ' 'if it does not yet exist and overwrite existing ' 'content if it does.' ) arg_parser . add_argument ( '-t' , '--target' , default = DEFAULT_ROOT_TARGET , help = 'Root build target.' ) arg_parser . add_argument ( '-d' , '--checkout-dir' , help = 'Path to the chromium checkout directory.' ) arg_parser . add_argument ( '-j' , '--jdeps-path' , help = 'Path to the jdeps executable.' ) arg_parser . add_argument ( '-g' , '--gn-path' , default = 'gn' , help = 'Path to the gn executable.' ) arguments = arg_parser . parse_args ( ) if arguments . checkout_dir : src_path = pathlib . Path ( arguments . checkout_dir ) else : src_path = pathlib . Path ( __file__ ) . resolve ( ) . parents [ 3 ] if arguments . jdeps_path : jdeps_path = pathlib . Path ( arguments . jdeps_path ) else : jdeps_path = src_path . joinpath ( 'third_party/jdk/current/bin/jdeps' ) os . chdir ( src_path ) cr_position_str = git_utils . get_last_commit_cr_position ( ) cr_position = int ( cr_position_str ) if cr_position_str else 0 print ( 'Getting list of dependency jars...' ) gn_desc_output = _run_gn_desc_list_dependencies ( arguments . build_output_dir , arguments . target , arguments . gn_path ) target_jars : JarTargetList = list_original_targets_and_jars ( gn_desc_output , arguments . build_output_dir , cr_position ) print ( 'Running jdeps...' ) jdeps_process_number = math . ceil ( multiprocessing . cpu_count ( ) / 2 ) with multiprocessing . Pool ( jdeps_process_number ) as pool : jar_paths = [ target_jar for _ , target_jar in target_jars ] jdeps_outputs = pool . map ( functools . partial ( _run_jdeps , jdeps_path ) , jar_paths ) print ( 'Parsing jdeps output...' ) jdeps_parser = JavaClassJdepsParser ( ) for raw_jdeps_output , ( build_target , _ ) in zip ( jdeps_outputs , target_jars ) : jdeps_parser . parse_raw_jdeps_output ( build_target , raw_jdeps_output ) class_graph = jdeps_parser . graph print ( f'Parsed class-level dependency graph, ' f'got {class_graph.num_nodes} nodes ' f'and {class_graph.num_edges} edges.' ) package_graph = package_dependency . JavaPackageDependencyGraph ( class_graph ) print ( f'Created package-level dependency graph, ' f'got {package_graph.num_nodes} nodes ' f'and {package_graph.num_edges} edges.' ) print ( f'Dumping JSON representation to {arguments.output}.' ) serialization . dump_class_and_package_graphs_to_file ( class_graph , package_graph , arguments . output )
Runs jdeps on all JARs a build target depends on.
Runs jdeps on all JARs a build target depends on .
"""Runs jdeps on all JARs a build target depends on.

    Creates a JSON file from the jdeps output.""" # gn and git must be run from inside the git checkout. # jdeps already has some parallelism