gn2bp: Convert java_actions to `java_group`
* This converts all of the `actions` whose script is in the list of `JAVA_BANNED_SCRIPTS` into a `java_group`. `java_group` don't have dependencies but all of the actions reachable through them are stored.
Test: m cronet_aml_components_cronet_android_cronet
Change-Id: Ib91dfdd6789fc25466e298a4a274e224fe08b5e9
diff --git a/tools/gn2bp/gn_utils.py b/tools/gn2bp/gn_utils.py
index 80c90f6..8f33ca2 100644
--- a/tools/gn2bp/gn_utils.py
+++ b/tools/gn2bp/gn_utils.py
@@ -30,7 +30,20 @@
BUILDFLAGS_TARGET = '//gn:gen_buildflags'
GEN_VERSION_TARGET = '//src/base:version_gen_h'
LINKER_UNIT_TYPES = ('executable', 'shared_library', 'static_library', 'source_set')
-
+JAVA_BANNED_SCRIPTS = [
+ "//build/android/gyp/turbine.py",
+ "//build/android/gyp/compile_java.py",
+ "//build/android/gyp/filter_zip.py",
+ "//build/android/gyp/dex.py",
+ "//build/android/gyp/write_build_config.py",
+ "//build/android/gyp/create_r_java.py",
+ "//build/android/gyp/ijar.py",
+ "//build/android/gyp/create_r_java.py",
+ "//build/android/gyp/bytecode_processor.py",
+ "//build/android/gyp/prepare_resources.py",
+ "//build/android/gyp/aar.py",
+ "//build/android/gyp/zip.py",
+]
# TODO(primiano): investigate these, they require further componentization.
ODR_VIOLATION_IGNORE_TARGETS = {
'//test/cts:perfetto_cts_deps',
@@ -72,6 +85,11 @@
def _is_java_source(src):
return os.path.splitext(src)[1] == '.java' and not src.startswith("//out/test/gen/")
+def is_java_action(script, outputs):
+ return (script != "" and script not in JAVA_BANNED_SCRIPTS) and any(
+ [file.endswith(".srcjar") or file.endswith(".java")
+ for file in outputs])
+
class GnParser(object):
"""A parser with some cleverness for GN json desc files
@@ -223,6 +241,7 @@
self.actions = {}
self.proto_libs = {}
self.java_sources = set()
+ self.java_actions = set()
def _get_response_file_contents(self, action_desc):
# response_file_contents are formatted as:
@@ -285,7 +304,9 @@
# genrule's do not allow to overload cmd per target OS / arch. Create a
# separate action for every architecture.
# Cover both action and action_foreach
- if type_.startswith('action'):
+ if type_.startswith('action') and \
+ not is_java_action(desc.get("script", ""), desc.get("outputs", [])):
+ # Don't meddle with the java actions name
target_name += '__' + arch
target = self.all_targets.get(target_name)
@@ -319,6 +340,14 @@
elif target.type in LINKER_UNIT_TYPES:
self.linker_units[gn_target_name] = target
target.arch[arch].sources.update(desc.get('sources', []))
+ elif desc.get("script", "") in JAVA_BANNED_SCRIPTS or 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)
+ if target.type == "action":
+ # Convert java actions into java_group and keep the inputs for collection.
+ target.inputs.update(desc.get('inputs', []))
+ target.type = 'java_group'
elif target.type in ['action', 'action_foreach']:
self.actions[gn_target_name] = target
target.inputs.update(desc.get('inputs', []))
@@ -331,11 +360,6 @@
elif target.type == 'copy':
# TODO: copy rules are not currently implemented.
self.actions[gn_target_name] = target
- elif 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
@@ -402,6 +426,8 @@
log.debug('Adding java sources for %s', dep.name)
java_srcs = [src for src in dep.inputs if _is_java_source(src)]
self.java_sources.update(java_srcs)
+ if dep.type in ["action"] and target.type == "java_group":
+ self.java_actions.add(dep.name)
return target
def get_proto_exports(self, proto_desc):