Commit e76f5f0f authored by Peter Wen's avatar Peter Wen Committed by Commit Bot

Android: Prefer direct deps for turbine

Rather than using direct deps for javac compilation, use it only for
turbine header compilation. The javac compilation process requires many
potential transitive deps that will take a more comprehensive approach,
perhaps similar to bazel's reduced java classpath.

Turbine using direct deps would only affect annotation processors. In
particular, possibly Dagger. Building chrome_java with only turbine's
direct deps seems to have worked, but only removing more of the dirs
in the allowlist can determine if this works for the entire codebase.

Bug: 1092528
Change-Id: Ifc745d269ce8850a6c675458fcff25c46ca39937
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2299531
Commit-Queue: Peter Wen <wnwen@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Auto-Submit: Peter Wen <wnwen@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#788795}
parent 2e8f7a2c
...@@ -431,7 +431,6 @@ def _RunCompiler(options, javac_cmd, java_files, classpath, jar_path, ...@@ -431,7 +431,6 @@ def _RunCompiler(options, javac_cmd, java_files, classpath, jar_path,
os.makedirs(temp_dir) os.makedirs(temp_dir)
try: try:
classes_dir = os.path.join(temp_dir, 'classes') classes_dir = os.path.join(temp_dir, 'classes')
transitive_classes = os.path.join(temp_dir, 'transitive_classes')
service_provider_configuration = os.path.join( service_provider_configuration = os.path.join(
temp_dir, 'service_provider_configuration') temp_dir, 'service_provider_configuration')
...@@ -461,34 +460,15 @@ def _RunCompiler(options, javac_cmd, java_files, classpath, jar_path, ...@@ -461,34 +460,15 @@ def _RunCompiler(options, javac_cmd, java_files, classpath, jar_path,
input_srcjars_dir) input_srcjars_dir)
logging.info('Done extracting srcjars') logging.info('Done extracting srcjars')
if classpath or options.header_jar: if options.header_jar:
logging.info('Extracting transitive classes to %s', transitive_classes) logging.info('Extracting service provider configs')
# All classes under META-INF/TRANSITIVE of all direct dependencies and the
# current target's META-INF/TRANSITIVE can be required during compile.
for path in classpath + [options.header_jar]:
if path.endswith('.turbine.jar'):
# Without the META-INF pattern prefix, it takes more than 4 seconds to
# extract all the .class files from chrome_java's header jar. With the
# prefix it takes less than 0.6 seconds.
# Set no_clobber=False since there are some overlaps in base classes
# from various header jars.
build_utils.ExtractAll(path,
no_clobber=False,
path=transitive_classes,
pattern='META-INF*.class')
# Specifying the root directory is required, see:
# https://docs.oracle.com/javase/8/docs/technotes/tools/findingclasses.html#userclass
# Extract META-INF/services/* so that it can be copied into the output # Extract META-INF/services/* so that it can be copied into the output
# .jar # .jar
build_utils.ExtractAll(options.header_jar, build_utils.ExtractAll(options.header_jar,
no_clobber=True, no_clobber=True,
path=service_provider_configuration, path=service_provider_configuration,
pattern='META-INF/services/*') pattern='META-INF/services/*')
logging.info('Done extracting service provider configs')
classpath.append(
os.path.join(transitive_classes, 'META-INF', 'TRANSITIVE'))
logging.info('Done extracting transitive classes')
if save_outputs and java_files: if save_outputs and java_files:
info_file_context.SubmitFiles(java_files) info_file_context.SubmitFiles(java_files)
...@@ -634,7 +614,7 @@ def _ParseOptions(argv): ...@@ -634,7 +614,7 @@ def _ParseOptions(argv):
parser.add_option( parser.add_option(
'--header-jar', '--header-jar',
help='This is the header jar for the current target that contains ' help='This is the header jar for the current target that contains '
'META-INF/TRANSITIVE class files to be included on the classpath.') 'META-INF/services/* files to be included in the output jar.')
options, args = parser.parse_args(argv) options, args = parser.parse_args(argv)
build_utils.CheckOptions(options, parser, required=('jar_path', )) build_utils.CheckOptions(options, parser, required=('jar_path', ))
......
...@@ -3030,7 +3030,7 @@ if (enable_java_templates) { ...@@ -3030,7 +3030,7 @@ if (enable_java_templates) {
] ]
} }
# Temporarily allow a list of directories to bypass direct deps. # Temporarily allow a list of directories to bypass turbine direct deps.
# TODO(crbug.com/1082904): Remove every entry in this allowlist. # TODO(crbug.com/1082904): Remove every entry in this allowlist.
_allow_transitive_interfaces = _allow_transitive_interfaces =
filter_exclude( filter_exclude(
...@@ -3052,11 +3052,11 @@ if (enable_java_templates) { ...@@ -3052,11 +3052,11 @@ if (enable_java_templates) {
"//weblayer*", "//weblayer*",
]) == [] ]) == []
if (_allow_transitive_interfaces) { if (invoker.use_turbine && !_allow_transitive_interfaces) {
args += [ "--classpath=@FileArg($_rebased_build_config:deps_info:javac_full_interface_classpath)" ] # Prefer direct deps for turbine as much as possible.
} else {
# Prefer direct interface classpath whenever possible.
args += [ "--classpath=@FileArg($_rebased_build_config:javac:interface_classpath)" ] args += [ "--classpath=@FileArg($_rebased_build_config:javac:interface_classpath)" ]
} else {
args += [ "--classpath=@FileArg($_rebased_build_config:deps_info:javac_full_interface_classpath)" ]
} }
if (_annotation_processing) { if (_annotation_processing) {
......
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