Commit 54452aac authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

[Lorenz] Adapt graph generation for older checkouts

In older checkouts, the .javac.jar is in gen/ rather than obj/

Change-Id: I1a149fd02e463b1fabd2be87e584bb0f9c759c19
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2518700Reviewed-by: default avatarMohamed Heikal <mheikal@chromium.org>
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824907}
parent 4d9ba87d
......@@ -14,6 +14,7 @@ import os
from typing import List, Tuple
import class_dependency
import git_utils
import package_dependency
import serialization
import subprocess_utils
......@@ -105,8 +106,8 @@ def _run_gn_desc_list_dependencies(build_output_dir: str, target: str,
JarTargetList = List[Tuple[str, pathlib.Path]]
def list_original_targets_and_jars(gn_desc_output: str,
build_output_dir: str) -> JarTargetList:
def list_original_targets_and_jars(gn_desc_output: str, build_output_dir: str,
cr_position: int) -> JarTargetList:
"""Parses gn desc output to list original java targets and output jar paths.
Returns a list of tuples (build_target: str, jar_path: str), where:
......@@ -121,19 +122,27 @@ def list_original_targets_and_jars(gn_desc_output: str,
continue
build_target = build_target_line.strip()
original_build_target = build_target.replace('__compile_java', '')
jar_path = _get_jar_path_for_target(build_output_dir, build_target)
jar_path = _get_jar_path_for_target(build_output_dir, build_target,
cr_position)
jar_tuples.append((original_build_target, jar_path))
return jar_tuples
def _get_jar_path_for_target(build_output_dir: str, build_target: str) -> str:
def _get_jar_path_for_target(build_output_dir: str, build_target: str,
cr_position: int) -> str:
if cr_position == 0: # Not running on main branch, use current convention.
subdirectory = 'obj'
elif cr_position < 761560: # crrev.com/c/2161205
subdirectory = 'gen'
else:
subdirectory = 'obj'
"""Calculates the output location of a jar for a java build target."""
target_path, target_name = build_target.split(':')
assert target_path.startswith('//'), \
f'Build target should start with "//" but is: "{build_target}"'
jar_dir = target_path[len('//'):]
jar_name = target_name.replace('__compile_java', '.javac.jar')
return pathlib.Path(build_output_dir) / 'obj' / jar_dir / jar_name
return pathlib.Path(build_output_dir) / subdirectory / jar_dir / jar_name
def main():
......@@ -186,12 +195,15 @@ def main():
# 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)
gn_desc_output, arguments.build_output_dir, cr_position)
print('Running jdeps...')
# jdeps already has some parallelism
......
......@@ -51,9 +51,46 @@ class TestHelperFunctions(unittest.TestCase):
generate_json_dependency_graph.class_is_interesting(
'java.lang.Object'))
def test_list_original_targets_and_jars(self):
def test_list_original_targets_and_jars_legacy(self):
result = generate_json_dependency_graph.list_original_targets_and_jars(
GN_DESC_OUTPUT, 'out/Test')
GN_DESC_OUTPUT, 'out/Test', 761559)
# Before crrev.com/c/2161205, *.javac.jar were in gen/
self.assertEqual(len(result), 3)
self.assertEqual(
result[0],
('//path/to/dep1:java',
pathlib.Path('out/Test/gen/path/to/dep1/java.javac.jar')))
self.assertEqual(
result[1],
('//path/to/dep2:java',
pathlib.Path('out/Test/gen/path/to/dep2/java.javac.jar')))
self.assertEqual(
result[2],
('//path/to/root:java',
pathlib.Path('out/Test/gen/path/to/root/java.javac.jar')))
def test_list_original_targets_and_jars_current(self):
# After crrev.com/c/2161205, *.javac.jar are in obj/
result = generate_json_dependency_graph.list_original_targets_and_jars(
GN_DESC_OUTPUT, 'out/Test', 761560)
self.assertEqual(len(result), 3)
self.assertEqual(
result[0],
('//path/to/dep1:java',
pathlib.Path('out/Test/obj/path/to/dep1/java.javac.jar')))
self.assertEqual(
result[1],
('//path/to/dep2:java',
pathlib.Path('out/Test/obj/path/to/dep2/java.javac.jar')))
self.assertEqual(
result[2],
('//path/to/root:java',
pathlib.Path('out/Test/obj/path/to/root/java.javac.jar')))
def test_list_original_targets_and_jars_branch(self):
# A branch without Commit-Cr-Position should be considered modern
result = generate_json_dependency_graph.list_original_targets_and_jars(
GN_DESC_OUTPUT, 'out/Test', 0)
self.assertEqual(len(result), 3)
self.assertEqual(
result[0],
......
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