gn2bp: mark java targets as java_group

According to the docs, java target names are (somewhat) guaranteed to end in
_java. There are some other variations that are allowlisted, though it
is currently unclear if those need to be supported for our purposes.

Test: //net:net
Change-Id: I0647dac6a078790e23509d437628aed0d8d62f77
This commit is contained in:
Patrick Rohr
2022-11-04 14:27:04 -07:00
parent 8995e5126e
commit af92fa6088
2 changed files with 19 additions and 5027 deletions

View File

@@ -20,6 +20,7 @@ import collections
import errno
import filecmp
import json
import logging as log
import os
import re
import shutil
@@ -185,6 +186,13 @@ class GnParser(object):
return ' '.join(formatted_flags)
def _is_java_target(self, target):
# Per https://chromium.googlesource.com/chromium/src/build/+/HEAD/android/docs/java_toolchain.md
# java target names must end in "_java".
# TODO: There are some other possible variations we might need to support.
return re.match('.*_java$', target.name)
def get_target(self, gn_target_name):
"""Returns a Target object from the fully qualified GN target name.
@@ -243,6 +251,11 @@ class GnParser(object):
elif target.type == 'copy':
# TODO: copy rules are not currently implemented.
self.actions[gn_target_name] = target
elif target.type == 'group' and self._is_java_target(target):
# java_group identifies the group target generated by the android_library
# or java_library template. A java_group must not be added as a dependency, but sources are collected
log.debug('Found java target %s', target.name)
target.type = 'java_group'
# Default for 'public' is //* - all headers in 'sources' are public.
# TODO(primiano): if a 'public' section is specified (even if empty), then