Skip to content

Commit 3a38086

Browse files
Peter Wencopybara-github
authored andcommitted
Android: Move dep-related code to dep_utils.py
This CL mostly moves code from lookup_dep.py -> dep_utils.py so that it is accessible by //build scripts. This paves the way to simplifying the code in subsequent CLs and making use of it in bytecode_processor.py. Bug: 1099522 Change-Id: Ia197e113a26b550a2a080c589ee23200fafe3767 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4567009 Commit-Queue: Mohamed Heikal <[email protected]> Reviewed-by: Mohamed Heikal <[email protected]> Auto-Submit: Peter Wen <[email protected]> Commit-Queue: Peter Wen <[email protected]> Cr-Commit-Position: refs/heads/main@{#1149807} NOKEYCHECK=True GitOrigin-RevId: 4ba710110b52161201898c376e50cc62418e0052
1 parent 4991e0f commit 3a38086

File tree

8 files changed

+274
-61
lines changed

8 files changed

+274
-61
lines changed

android/gyp/bytecode_processor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import sys
1414
from typing import Dict, List
1515

16-
import javac_output_processor
1716
from util import build_utils
17+
from util import dep_utils
1818
from util import jar_utils
1919
from util import server_utils
2020
import action_helpers # build_utils adds //build to sys.path.
@@ -215,7 +215,7 @@ def main(argv):
215215
args.full_classpath_jars = action_helpers.parse_gn_list(
216216
args.full_classpath_jars)
217217
args.full_classpath_gn_targets = [
218-
javac_output_processor.ReplaceGmsPackageIfNeeded(t)
218+
dep_utils.ReplaceGmsPackageIfNeeded(t)
219219
for t in action_helpers.parse_gn_list(args.full_classpath_gn_targets)
220220
]
221221
args.missing_classes_allowlist = action_helpers.parse_gn_list(

android/gyp/bytecode_processor.pydeps

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@
99
../../../third_party/catapult/devil/devil/android/sdk/version_codes.py
1010
../../../third_party/catapult/devil/devil/constants/__init__.py
1111
../../../third_party/catapult/devil/devil/constants/exit_codes.py
12-
../../../third_party/colorama/src/colorama/__init__.py
13-
../../../third_party/colorama/src/colorama/ansi.py
14-
../../../third_party/colorama/src/colorama/ansitowin32.py
15-
../../../third_party/colorama/src/colorama/initialise.py
16-
../../../third_party/colorama/src/colorama/win32.py
17-
../../../third_party/colorama/src/colorama/winterm.py
18-
../../../tools/android/modularization/convenience/lookup_dep.py
1912
../../../tools/android/modularization/gn/dep_operations.py
2013
../../../tools/android/modularization/gn/json_gn_editor.py
2114
../../../tools/android/modularization/gn/utils.py
@@ -28,8 +21,8 @@
2821
../pylib/__init__.py
2922
../pylib/constants/__init__.py
3023
bytecode_processor.py
31-
javac_output_processor.py
3224
util/__init__.py
3325
util/build_utils.py
26+
util/dep_utils.py
3427
util/jar_utils.py
3528
util/server_utils.py

android/gyp/compile_java.pydeps

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
../../../third_party/colorama/src/colorama/initialise.py
1616
../../../third_party/colorama/src/colorama/win32.py
1717
../../../third_party/colorama/src/colorama/winterm.py
18-
../../../tools/android/modularization/convenience/lookup_dep.py
1918
../../action_helpers.py
2019
../../gn_helpers.py
2120
../../print_python_deps.py
@@ -27,6 +26,7 @@ compile_java.py
2726
javac_output_processor.py
2827
util/__init__.py
2928
util/build_utils.py
29+
util/dep_utils.py
3030
util/jar_info_utils.py
3131
util/jar_utils.py
3232
util/md5_check.py

android/gyp/compile_kt.pydeps

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
../../../third_party/colorama/src/colorama/initialise.py
1616
../../../third_party/colorama/src/colorama/win32.py
1717
../../../third_party/colorama/src/colorama/winterm.py
18-
../../../tools/android/modularization/convenience/lookup_dep.py
1918
../../action_helpers.py
2019
../../gn_helpers.py
2120
../../print_python_deps.py
@@ -28,6 +27,7 @@ compile_kt.py
2827
javac_output_processor.py
2928
util/__init__.py
3029
util/build_utils.py
30+
util/dep_utils.py
3131
util/jar_info_utils.py
3232
util/jar_utils.py
3333
util/md5_check.py

android/gyp/javac_output_processor.py

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,19 @@
55
# found in the LICENSE file.
66
"""Contains helper class for processing javac output."""
77

8-
import dataclasses
98
import os
109
import pathlib
1110
import re
1211
import sys
1312
import traceback
14-
from typing import List
1513

1614
from util import build_utils
15+
from util import dep_utils
1716

1817
sys.path.insert(
1918
0,
2019
os.path.join(build_utils.DIR_SOURCE_ROOT, 'third_party', 'colorama', 'src'))
2120
import colorama
22-
sys.path.insert(
23-
0,
24-
os.path.join(build_utils.DIR_SOURCE_ROOT, 'tools', 'android',
25-
'modularization', 'convenience'))
26-
import lookup_dep
27-
28-
29-
def ReplaceGmsPackageIfNeeded(target_name: str) -> str:
30-
if target_name.startswith(
31-
('//third_party/android_deps:google_play_services_',
32-
'//clank/third_party/google3:google_play_services_')):
33-
return f'$google_play_services_package:{target_name.split(":")[1]}'
34-
return target_name
35-
36-
37-
def _DisambiguateDeps(class_entries: List[lookup_dep.ClassEntry]):
38-
def filter_if_not_empty(entries, filter_func):
39-
filtered_entries = [e for e in entries if filter_func(e)]
40-
return filtered_entries or entries
41-
42-
# When some deps are preferred, ignore all other potential deps.
43-
class_entries = filter_if_not_empty(class_entries, lambda e: e.preferred_dep)
44-
45-
# E.g. javax_annotation_jsr250_api_java.
46-
class_entries = filter_if_not_empty(class_entries,
47-
lambda e: 'jsr' in e.target)
48-
49-
# Avoid suggesting subtargets when regular targets exist.
50-
class_entries = filter_if_not_empty(class_entries,
51-
lambda e: '__' not in e.target)
52-
53-
# Swap out GMS package names if needed.
54-
class_entries = [
55-
dataclasses.replace(e, target=ReplaceGmsPackageIfNeeded(e.target))
56-
for e in class_entries
57-
]
58-
59-
# Convert to dict and then use list to get the keys back to remove dups and
60-
# keep order the same as before.
61-
class_entries = list({e: True for e in class_entries})
62-
63-
return class_entries
6421

6522

6623
class JavacOutputProcessor:
@@ -181,7 +138,7 @@ def _LookForUnknownSymbol(self, line, next_line):
181138
return
182139

183140
if self._class_lookup_index is None:
184-
self._class_lookup_index = lookup_dep.ClassLookupIndex(
141+
self._class_lookup_index = dep_utils.ClassLookupIndex(
185142
pathlib.Path(os.getcwd()),
186143
should_build=False,
187144
)
@@ -192,7 +149,7 @@ def _LookForUnknownSymbol(self, line, next_line):
192149
if not suggested_deps:
193150
return
194151

195-
suggested_deps = _DisambiguateDeps(suggested_deps)
152+
suggested_deps = dep_utils.DisambiguateDeps(suggested_deps)
196153
suggested_deps_str = ', '.join(s.target for s in suggested_deps)
197154

198155
if len(suggested_deps) > 1:

android/gyp/turbine.pydeps

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
../../../third_party/colorama/src/colorama/initialise.py
1616
../../../third_party/colorama/src/colorama/win32.py
1717
../../../third_party/colorama/src/colorama/winterm.py
18-
../../../tools/android/modularization/convenience/lookup_dep.py
1918
../../action_helpers.py
2019
../../gn_helpers.py
2120
../../print_python_deps.py
@@ -28,6 +27,7 @@ javac_output_processor.py
2827
turbine.py
2928
util/__init__.py
3029
util/build_utils.py
30+
util/dep_utils.py
3131
util/jar_info_utils.py
3232
util/jar_utils.py
3333
util/md5_check.py

android/gyp/util/build_utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import json
1313
import logging
1414
import os
15-
import pipes
1615
import re
1716
import shlex
1817
import shutil
@@ -21,7 +20,6 @@
2120
import sys
2221
import tempfile
2322
import textwrap
24-
import time
2523
import zipfile
2624

2725
sys.path.append(os.path.join(os.path.dirname(__file__),

0 commit comments

Comments
 (0)