Commit 55ab173a authored by Peter Wen's avatar Peter Wen Committed by Commit Bot

Android: Use turbine to generate java headers

See go/faster-javac for a detailed analysis of why turbine was chosen to
speed up our java builds. The current implementation is an initial
implementation that can be further optimized. It already gives savings
of 10-30% of our java incremental builds depending on the target in
question (see go/project-turbo for timing details).

This implementation does remove some of the benefits of the previous way
that java_library_impl was implemented, namely when a target's
.interface.jar file changes, it no longer short-circuits dependent
targets from being built since we now use group(target_name). This is
arguably more correct as prebuilts depend on javac jars directly. In the
future (after the androidx migration and other build improvements) this
can be improved by having prebuilts depend on the interface jars
instead.

Bug: 1056299
Change-Id: I49d18604203749cf447ce77c54a8f8469c83eae1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2105415
Commit-Queue: Peter Wen <wnwen@chromium.org>
Auto-Submit: Peter Wen <wnwen@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750651}
parent 5509b24c
...@@ -1337,6 +1337,7 @@ _ANDROID_SPECIFIC_PYDEPS_FILES = [ ...@@ -1337,6 +1337,7 @@ _ANDROID_SPECIFIC_PYDEPS_FILES = [
'build/android/gyp/merge_manifest.pydeps', 'build/android/gyp/merge_manifest.pydeps',
'build/android/gyp/prepare_resources.pydeps', 'build/android/gyp/prepare_resources.pydeps',
'build/android/gyp/proguard.pydeps', 'build/android/gyp/proguard.pydeps',
'build/android/gyp/turbine.pydeps',
'build/android/gyp/validate_static_library_dex_references.pydeps', 'build/android/gyp/validate_static_library_dex_references.pydeps',
'build/android/gyp/write_build_config.pydeps', 'build/android/gyp/write_build_config.pydeps',
'build/android/gyp/write_native_libraries_java.pydeps', 'build/android/gyp/write_native_libraries_java.pydeps',
......
#!/usr/bin/env python
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Wraps bin/helper/turbine and expands @FileArgs."""
import argparse
import logging
import os
import shutil
import subprocess
import sys
import time
from util import build_utils
from util import md5_check
def _OnStaleMd5(options, cmd, javac_cmd, files, classpath):
if classpath:
cmd += ['--classpath']
cmd += classpath
if options.java_srcjars:
cmd += ['--source_jars']
cmd += options.java_srcjars
if files:
# Use jar_path to ensure paths are relative (needed for goma).
files_rsp_path = options.jar_path + '.files_list.txt'
with open(files_rsp_path, 'w') as f:
f.write(' '.join(files))
# Pass source paths as response files to avoid extremely long command lines
# that are tedius to debug.
cmd += ['--sources']
cmd += ['@' + files_rsp_path]
if javac_cmd:
cmd.append('--javacopts')
cmd += javac_cmd
cmd.append('--') # Terminate javacopts
# Use AtomicOutput so that output timestamps are not updated when outputs
# are not changed.
with build_utils.AtomicOutput(options.jar_path) as f:
cmd += ['--output', f.name]
logging.info('Command: %s' % ' '.join(cmd))
start = time.time()
subprocess.check_call(cmd)
end = time.time() - start
logging.info('Header compilation took %ss', end)
logging.info('Completed all steps in _OnStaleMd5')
def main(argv):
build_utils.InitLogging('TURBINE_DEBUG')
argv = build_utils.ExpandFileArgs(argv[1:])
parser = argparse.ArgumentParser()
build_utils.AddDepfileOption(parser)
parser.add_argument(
'--turbine-jar-path', required=True, help='Path to the turbine jar file.')
parser.add_argument(
'--java-srcjars',
action='append',
default=[],
help='List of srcjars to include in compilation.')
parser.add_argument(
'--bootclasspath',
action='append',
default=[],
help='Boot classpath for javac. If this is specified multiple times, '
'they will all be appended to construct the classpath.')
parser.add_argument(
'--java-version',
help='Java language version to use in -source and -target args to javac.')
parser.add_argument('--classpath', action='append', help='Classpath to use.')
parser.add_argument(
'--processors',
action='append',
help='GN list of annotation processor main classes.')
parser.add_argument(
'--processorpath',
action='append',
help='GN list of jars that comprise the classpath used for Annotation '
'Processors.')
parser.add_argument(
'--processor-args',
action='append',
help='key=value arguments for the annotation processors.')
parser.add_argument('--jar-path', help='Jar output path.', required=True)
options, unknown_args = parser.parse_known_args(argv)
options.bootclasspath = build_utils.ParseGnList(options.bootclasspath)
options.classpath = build_utils.ParseGnList(options.classpath)
options.processorpath = build_utils.ParseGnList(options.processorpath)
options.processors = build_utils.ParseGnList(options.processors)
options.java_srcjars = build_utils.ParseGnList(options.java_srcjars)
files = []
for arg in unknown_args:
# Interpret a path prefixed with @ as a file containing a list of sources.
if arg.startswith('@'):
files.extend(build_utils.ReadSourcesList(arg[1:]))
cmd = [
build_utils.JAVA_PATH, '-classpath', options.turbine_jar_path,
'com.google.turbine.main.Main'
]
javac_cmd = []
# Turbine reads lists from command line args by consuming args until one
# starts with double dash (--). Thus command line args should be grouped
# together and passed in together.
if options.processors:
cmd += ['--processors']
cmd += options.processors
if options.java_version:
javac_cmd.extend([
'-source',
options.java_version,
'-target',
options.java_version,
])
if options.java_version == '1.8':
# Android's boot jar doesn't contain all java 8 classes.
options.bootclasspath.append(build_utils.RT_JAR_PATH)
if options.bootclasspath:
cmd += ['--bootclasspath']
for bootclasspath in options.bootclasspath:
cmd += bootclasspath.split(':')
if options.processorpath:
cmd += ['--processorpath']
cmd += options.processorpath
if options.processor_args:
for arg in options.processor_args:
javac_cmd.extend(['-A%s' % arg])
classpath_inputs = (
options.bootclasspath + options.classpath + options.processorpath)
# GN already knows of the java files, so avoid listing individual java files
# in the depfile.
depfile_deps = classpath_inputs + options.java_srcjars
input_paths = depfile_deps + files
output_paths = [
options.jar_path,
]
input_strings = cmd + options.classpath + files
md5_check.CallAndWriteDepfileIfStale(
lambda: _OnStaleMd5(options, cmd, javac_cmd, files, options.classpath),
options,
depfile_deps=depfile_deps,
input_paths=input_paths,
input_strings=input_strings,
output_paths=output_paths)
if __name__ == '__main__':
sys.exit(main(sys.argv))
# Generated by running:
# build/print_python_deps.py --root build/android/gyp --output build/android/gyp/turbine.pydeps build/android/gyp/turbine.py
../../gn_helpers.py
turbine.py
util/__init__.py
util/build_utils.py
util/md5_check.py
...@@ -248,8 +248,8 @@ Path to a file that is the result of processing ...@@ -248,8 +248,8 @@ Path to a file that is the result of processing
* `deps_info['interface_jar_path']: * `deps_info['interface_jar_path']:
Path to the interface jar generated for this library. This corresponds to Path to the interface jar generated for this library. This corresponds to
a jar file that only contains declarations. Generated by running the `ijar` a jar file that only contains declarations. Generated by running the `ijar` on
tool on `deps_info['jar_path']` `deps_info['jar_path']` or the `turbine` tool on source files.
* `deps_info['dex_path']`: * `deps_info['dex_path']`:
Path to the `.dex` file generated for this target, from `deps_info['jar_path']` Path to the `.dex` file generated for this target, from `deps_info['jar_path']`
......
...@@ -17,8 +17,7 @@ import("//build_overrides/build.gni") ...@@ -17,8 +17,7 @@ import("//build_overrides/build.gni")
assert(is_android) assert(is_android)
# These identify targets that have .build_config files (except for android_apk, # These identify targets that have .build_config files (except for android_apk,
# java_binary, android_app_bundle since we never need to # java_binary, android_app_bundle since we never need to depend on these).
# depend on these).
_java_target_patterns = [ _java_target_patterns = [
"*:*_java", "*:*_java",
"*:*_javalib", "*:*_javalib",
...@@ -44,6 +43,13 @@ _java_target_patterns = [ ...@@ -44,6 +43,13 @@ _java_target_patterns = [
# Targets that match the patterns but are not actually java targets. # Targets that match the patterns but are not actually java targets.
_java_target_exceptions = [ "*:*_unpack_aar" ] _java_target_exceptions = [ "*:*_unpack_aar" ]
# Targets that should be replace by their headers during javac.
_java_header_target_patterns = [
"*:*_java",
"*:*_javalib",
"*:java",
]
_r8_path = "//third_party/r8/lib/r8.jar" _r8_path = "//third_party/r8/lib/r8.jar"
_dexdump_path = "$android_sdk_build_tools/dexdump" _dexdump_path = "$android_sdk_build_tools/dexdump"
...@@ -2687,10 +2693,11 @@ if (enable_java_templates) { ...@@ -2687,10 +2693,11 @@ if (enable_java_templates) {
# additional_jar_files: Optional list of files to copy into the resulting # additional_jar_files: Optional list of files to copy into the resulting
# .jar file (by default, only .class files are put there). Each entry # .jar file (by default, only .class files are put there). Each entry
# has the 'srcPath:dstPath' format. # has the 'srcPath:dstPath' format.
# enable_errorprone: Optional. If True, use the errorprone compiler to # enable_errorprone: If True, use the errorprone compiler to check for
# check for error-prone constructs in the language. If not provided, # error-prone constructs in the language. If not provided, whether this is
# whether this is enabled depends on chromium_code and the global # enabled depends on chromium_code and the global
# use_errorprone_java_compiler variable. # use_errorprone_java_compiler variable.
# use_turbine: If True, compile headers using turbine.py.
# apk_name: Optional APK name. If provided, will tell compile_java.py to also # apk_name: Optional APK name. If provided, will tell compile_java.py to also
# generate an .apk.jar.info file under size-info/${apk_name}.apk.jar.info # generate an .apk.jar.info file under size-info/${apk_name}.apk.jar.info
# provider_configurations: Optional list of paths to Java service # provider_configurations: Optional list of paths to Java service
...@@ -2742,16 +2749,20 @@ if (enable_java_templates) { ...@@ -2742,16 +2749,20 @@ if (enable_java_templates) {
} }
action_with_pydeps(target_name) { action_with_pydeps(target_name) {
script = "//build/android/gyp/compile_java.py" if (invoker.use_turbine) {
script = "//build/android/gyp/turbine.py"
} else {
script = "//build/android/gyp/compile_java.py"
}
depfile = "$target_gen_dir/$target_name.d" depfile = "$target_gen_dir/$target_name.d"
deps = _srcjar_deps deps = _srcjar_deps
if (defined(invoker.deps)) { if (defined(invoker.deps)) {
deps += invoker.deps deps += invoker.deps
} }
outputs = [ invoker.javac_jar_path ] outputs = [ invoker.output_jar_path ]
if (!invoker.enable_errorprone) { if (!invoker.enable_errorprone && !invoker.use_turbine) {
outputs += [ invoker.javac_jar_path + ".info" ] outputs += [ invoker.output_jar_path + ".info" ]
} }
inputs = invoker.java_files + _java_srcjars + [ _build_config ] inputs = invoker.java_files + _java_srcjars + [ _build_config ]
if (invoker.java_files != []) { if (invoker.java_files != []) {
...@@ -2759,8 +2770,8 @@ if (enable_java_templates) { ...@@ -2759,8 +2770,8 @@ if (enable_java_templates) {
} }
_rebased_build_config = rebase_path(_build_config, root_build_dir) _rebased_build_config = rebase_path(_build_config, root_build_dir)
_rebased_javac_jar_path = _rebased_output_jar_path =
rebase_path(invoker.javac_jar_path, root_build_dir) rebase_path(invoker.output_jar_path, root_build_dir)
_rebased_java_srcjars = rebase_path(_java_srcjars, root_build_dir) _rebased_java_srcjars = rebase_path(_java_srcjars, root_build_dir)
_rebased_depfile = rebase_path(depfile, root_build_dir) _rebased_depfile = rebase_path(depfile, root_build_dir)
_rebased_generated_dir = rebase_path( _rebased_generated_dir = rebase_path(
...@@ -2769,13 +2780,23 @@ if (enable_java_templates) { ...@@ -2769,13 +2780,23 @@ if (enable_java_templates) {
args = [ args = [
"--depfile=$_rebased_depfile", "--depfile=$_rebased_depfile",
"--generated-dir=$_rebased_generated_dir", "--generated-dir=$_rebased_generated_dir",
"--jar-path=$_rebased_javac_jar_path", "--jar-path=$_rebased_output_jar_path",
"--java-srcjars=$_rebased_java_srcjars", "--java-srcjars=$_rebased_java_srcjars",
"--classpath=@FileArg($_rebased_build_config:deps_info:javac_full_interface_classpath)", "--classpath=@FileArg($_rebased_build_config:deps_info:javac_full_interface_classpath)",
"--processorpath=@FileArg($_rebased_build_config:javac:processor_classpath)", "--processorpath=@FileArg($_rebased_build_config:javac:processor_classpath)",
"--processors=@FileArg($_rebased_build_config:javac:processor_classes)", "--processors=@FileArg($_rebased_build_config:javac:processor_classes)",
] ]
if (invoker.supports_android) { if (invoker.use_turbine) {
_turbine_jar_path = "//third_party/turbine/turbine.jar"
inputs += [ _turbine_jar_path ]
args += [
"--turbine-jar-path",
rebase_path(_turbine_jar_path, root_build_dir),
]
}
# Currently turbine does not support JDK11.
if (invoker.supports_android || invoker.use_turbine) {
args += [ "--java-version=1.8" ] args += [ "--java-version=1.8" ]
} }
if ((!defined(invoker.never_goma) || !invoker.never_goma) && if ((!defined(invoker.never_goma) || !invoker.never_goma) &&
...@@ -2845,6 +2866,27 @@ if (enable_java_templates) { ...@@ -2845,6 +2866,27 @@ if (enable_java_templates) {
} }
} }
template("java_header_group") {
forward_variables_from(invoker, [ "testonly" ])
group(target_name) {
if (defined(invoker.deps)) {
deps = []
foreach(_dep, invoker.deps) {
set_sources_assignment_filter(_java_header_target_patterns)
_target_label = get_label_info(_dep, "label_no_toolchain")
sources = [ _target_label ]
if (sources == []) {
# This is a java dep, so replace it with its header.
deps += [ "${_target_label}__header" ]
} else {
deps += [ _dep ]
}
sources = []
}
}
}
}
# Create an interface jar from a normal jar. # Create an interface jar from a normal jar.
# #
# Variables # Variables
...@@ -2934,6 +2976,9 @@ if (enable_java_templates) { ...@@ -2934,6 +2976,9 @@ if (enable_java_templates) {
# testonly: True iff target should only be used for tests. # testonly: True iff target should only be used for tests.
# no_build_hooks: Disables bytecode rewriting of asserts and android # no_build_hooks: Disables bytecode rewriting of asserts and android
# resources methods. # resources methods.
# enable_turbine: If exists then will be used to determine whether to run
# turbine or not. Useful for disabling turbine headers for problematic
# targets.
# chromium_code: Optional. Whether this is Chromium-specific code. If not # chromium_code: Optional. Whether this is Chromium-specific code. If not
# provided, this is determined automatically, based on the location of # provided, this is determined automatically, based on the location of
# the source files (i.e. anything under third_party/ is not # the source files (i.e. anything under third_party/ is not
...@@ -3112,15 +3157,32 @@ if (enable_java_templates) { ...@@ -3112,15 +3157,32 @@ if (enable_java_templates) {
_accumulated_public_deps = [] _accumulated_public_deps = []
_accumulated_deps = [] _accumulated_deps = []
_java_header_deps = []
_java_full_deps = []
if (defined(invoker.deps)) { if (defined(invoker.deps)) {
_accumulated_deps = invoker.deps foreach(_dep, invoker.deps) {
set_sources_assignment_filter(_java_header_target_patterns)
_target_label = get_label_info(_dep, "label_no_toolchain")
sources = [ _target_label ]
if (sources == []) {
# This is a java header dep, so replace it with its header.
_java_header_deps += [ "${_target_label}__header" ]
_java_full_deps += [ _dep ]
} else {
# Not a java header dep, so no need to replace it with its header.
_accumulated_deps += [ _dep ]
}
sources = []
}
} }
_enable_build_hooks = _enable_build_hooks =
_supports_android && _supports_android &&
(!defined(invoker.no_build_hooks) || !invoker.no_build_hooks) (!defined(invoker.no_build_hooks) || !invoker.no_build_hooks)
if (_enable_build_hooks) { if (_enable_build_hooks) {
_accumulated_deps += [ "//build/android/buildhooks:build_hooks_java" ] _java_full_deps += [ "//build/android/buildhooks:build_hooks_java" ]
_java_header_deps +=
[ "//build/android/buildhooks:build_hooks_java__header" ]
} }
# Some testonly targets use their own resources and the code being # Some testonly targets use their own resources and the code being
...@@ -3130,7 +3192,9 @@ if (enable_java_templates) { ...@@ -3130,7 +3192,9 @@ if (enable_java_templates) {
_enable_build_hooks && _requires_android && _enable_build_hooks && _requires_android &&
(!defined(invoker.testonly) || !invoker.testonly) (!defined(invoker.testonly) || !invoker.testonly)
if (_enable_build_hooks_android) { if (_enable_build_hooks_android) {
_accumulated_deps += # This is only needed for the process_java_prebuilt step, so no header
# necessary.
_java_full_deps +=
[ "//build/android/buildhooks:build_hooks_android_java" ] [ "//build/android/buildhooks:build_hooks_android_java" ]
} }
...@@ -3160,7 +3224,9 @@ if (enable_java_templates) { ...@@ -3160,7 +3224,9 @@ if (enable_java_templates) {
!invoker.jacoco_never_instrument && _jacoco_instrument !invoker.jacoco_never_instrument && _jacoco_instrument
} }
if (_jacoco_instrument) { if (_jacoco_instrument) {
_accumulated_deps += [ "//third_party/jacoco:jacocoagent_java" ] # This is only needed for the process_java_prebuilt step, so no header
# necessary.
_java_full_deps += [ "//third_party/jacoco:jacocoagent_java" ]
} }
} }
...@@ -3177,11 +3243,13 @@ if (enable_java_templates) { ...@@ -3177,11 +3243,13 @@ if (enable_java_templates) {
_include_android_sdk = invoker.include_android_sdk _include_android_sdk = invoker.include_android_sdk
} }
if (_include_android_sdk) { if (_include_android_sdk) {
_sdk_java_dep = "//third_party/android_sdk:android_sdk_java"
if (defined(invoker.alternative_android_sdk_dep)) { if (defined(invoker.alternative_android_sdk_dep)) {
_accumulated_deps += [ invoker.alternative_android_sdk_dep ] _sdk_java_dep = invoker.alternative_android_sdk_dep
} else {
_accumulated_deps += [ "//third_party/android_sdk:android_sdk_java" ]
} }
# This is an android_system_java_prebuilt target, so no headers.
_accumulated_deps += [ _sdk_java_dep ]
} }
_jetified_jar_path = _jetified_jar_path =
"$target_out_dir/${target_name}__process_prebuilt-jetified.jar" "$target_out_dir/${target_name}__process_prebuilt-jetified.jar"
...@@ -3245,7 +3313,7 @@ if (enable_java_templates) { ...@@ -3245,7 +3313,7 @@ if (enable_java_templates) {
build_config = _build_config build_config = _build_config
is_prebuilt = _is_prebuilt is_prebuilt = _is_prebuilt
jetified_jar_path = _jetified_jar_path jetified_jar_path = _jetified_jar_path
possible_config_deps = _accumulated_deps possible_config_deps = _java_full_deps + _accumulated_deps
skip_jetify = defined(invoker.skip_jetify) && invoker.skip_jetify skip_jetify = defined(invoker.skip_jetify) && invoker.skip_jetify
if (defined(apk_under_test)) { if (defined(apk_under_test)) {
possible_config_deps += [ apk_under_test ] possible_config_deps += [ apk_under_test ]
...@@ -3288,12 +3356,14 @@ if (enable_java_templates) { ...@@ -3288,12 +3356,14 @@ if (enable_java_templates) {
# Don't need to depend on the apk-under-test to be packaged. # Don't need to depend on the apk-under-test to be packaged.
if (defined(invoker.apk_under_test)) { if (defined(invoker.apk_under_test)) {
_accumulated_deps += [ "${invoker.apk_under_test}__java" ] _java_full_deps += [ "${invoker.apk_under_test}__java" ]
_java_header_deps += [ "${invoker.apk_under_test}__java__header" ]
} }
if (defined(invoker.android_manifest_dep)) { if (defined(invoker.android_manifest_dep)) {
_accumulated_deps += [ invoker.android_manifest_dep ] _accumulated_deps += [ invoker.android_manifest_dep ]
} }
if (defined(invoker.annotation_processor_deps)) { if (defined(invoker.annotation_processor_deps)) {
# We need the full annotation processors rather than just the headers.
_accumulated_deps += invoker.annotation_processor_deps _accumulated_deps += invoker.annotation_processor_deps
} }
...@@ -3320,8 +3390,10 @@ if (enable_java_templates) { ...@@ -3320,8 +3390,10 @@ if (enable_java_templates) {
template("compile_java_helper") { template("compile_java_helper") {
compile_java(target_name) { compile_java(target_name) {
forward_variables_from(invoker, "*") forward_variables_from(invoker, "*")
enable_errorprone = invoker.enable_errorprone output_jar_path = invoker.output_jar_path
javac_jar_path = invoker.javac_jar_path enable_errorprone =
defined(invoker.enable_errorprone) && invoker.enable_errorprone
use_turbine = defined(invoker.use_turbine) && invoker.use_turbine
main_target_name = _main_target_name main_target_name = _main_target_name
build_config = _build_config build_config = _build_config
...@@ -3333,7 +3405,8 @@ if (enable_java_templates) { ...@@ -3333,7 +3405,8 @@ if (enable_java_templates) {
chromium_code = _chromium_code chromium_code = _chromium_code
supports_android = _supports_android supports_android = _supports_android
requires_android = _requires_android requires_android = _requires_android
deps = _accumulated_deps + _accumulated_public_deps deps =
_java_header_deps + _accumulated_deps + _accumulated_public_deps
# android_apk and junit_binary pass R.java srcjars via srcjar_deps. # android_apk and junit_binary pass R.java srcjars via srcjar_deps.
if (_type == "java_library" && _requires_android) { if (_type == "java_library" && _requires_android) {
...@@ -3342,8 +3415,6 @@ if (enable_java_templates) { ...@@ -3342,8 +3415,6 @@ if (enable_java_templates) {
} }
} }
} }
_analysis_public_deps = []
_compile_java_target = "${_main_target_name}__compile_java"
_compile_java_forward_variables = [ _compile_java_forward_variables = [
"additional_jar_files", "additional_jar_files",
"apk_name", "apk_name",
...@@ -3353,10 +3424,11 @@ if (enable_java_templates) { ...@@ -3353,10 +3424,11 @@ if (enable_java_templates) {
"jar_excluded_patterns", "jar_excluded_patterns",
"never_goma", "never_goma",
] ]
_analysis_public_deps = []
_compile_java_target = "${_main_target_name}__compile_java"
compile_java_helper(_compile_java_target) { compile_java_helper(_compile_java_target) {
forward_variables_from(invoker, _compile_java_forward_variables) forward_variables_from(invoker, _compile_java_forward_variables)
enable_errorprone = false output_jar_path = _javac_jar_path
javac_jar_path = _javac_jar_path
} }
if (_enable_errorprone) { if (_enable_errorprone) {
_compile_java_errorprone_target = _compile_java_errorprone_target =
...@@ -3370,7 +3442,7 @@ if (enable_java_templates) { ...@@ -3370,7 +3442,7 @@ if (enable_java_templates) {
} }
javac_args += invoker.errorprone_args javac_args += invoker.errorprone_args
} }
javac_jar_path = _javac_jar_path + ".errorprone_stamp" output_jar_path = _javac_jar_path + ".errorprone_stamp"
} }
_analysis_public_deps += [ ":$_compile_java_errorprone_target" ] _analysis_public_deps += [ ":$_compile_java_errorprone_target" ]
} }
...@@ -3420,6 +3492,36 @@ if (enable_java_templates) { ...@@ -3420,6 +3492,36 @@ if (enable_java_templates) {
_accumulated_public_deps += [ ":$_compile_java_target" ] _accumulated_public_deps += [ ":$_compile_java_target" ]
} # _has_sources } # _has_sources
if (_is_prebuilt || _has_sources) {
_header_target_name = "${target_name}__header"
_enable_turbine = _has_sources && _chromium_code
if (defined(invoker.enable_turbine)) {
_enable_turbine = invoker.enable_turbine
}
if (_enable_turbine) {
compile_java_helper(_header_target_name) {
forward_variables_from(invoker, _compile_java_forward_variables)
use_turbine = true
output_jar_path = _final_ijar_path
}
} else {
generate_interface_jar(_header_target_name) {
# Always used the unfiltered .jar to create the interface jar so that
# other targets will resolve filtered classes when depending on
# BuildConfig, NativeLibraries, etc.
input_jar = _unprocessed_jar_path
output_jar = _final_ijar_path
# Some prebuilts have java deps (e.g. //third_party/proguard:retrace_java).
deps = _accumulated_deps + _java_header_deps
if (_has_sources) {
deps += [ ":$_compile_java_target" ]
}
}
}
_accumulated_public_deps += [ ":$_header_target_name" ]
} # _is_prebuilt || _has_sources
if (defined(_final_jar_path)) { if (defined(_final_jar_path)) {
if (_is_system_library) { if (_is_system_library) {
_copy_system_library_target_name = "${target_name}__copy_system_library" _copy_system_library_target_name = "${target_name}__copy_system_library"
...@@ -3455,7 +3557,20 @@ if (enable_java_templates) { ...@@ -3455,7 +3557,20 @@ if (enable_java_templates) {
java_sources_file = _java_sources_file java_sources_file = _java_sources_file
} }
output_jar_path = _final_jar_path output_jar_path = _final_jar_path
deps = _accumulated_deps + _accumulated_public_deps deps = _java_full_deps + _accumulated_deps + _accumulated_public_deps
# proguard_configs listed on java_library targets need to be marked
# as inputs to at least one action so that "gn analyze" will know
# about them. Although ijar doesn't use them, it's a convenient spot
# to list them.
# https://crbug.com/827197
if (defined(invoker.proguard_configs)) {
inputs = invoker.proguard_configs
if (!defined(deps)) {
deps = []
}
deps += _srcjar_deps # For the aapt-generated proguard rules.
}
} }
_accumulated_public_deps += [ ":$_process_prebuilt_target_name" ] _accumulated_public_deps += [ ":$_process_prebuilt_target_name" ]
...@@ -3479,12 +3594,7 @@ if (enable_java_templates) { ...@@ -3479,12 +3594,7 @@ if (enable_java_templates) {
} }
if (!_is_java_binary) { if (!_is_java_binary) {
# Export the interface jar as the main target (rather than a group) group(target_name) {
# so that ninja will notice when the output is unchanged and not rebuild
# reverse-dependencies. Targets that should be rebuilt when the
# non-interface .jar changes use a depfile to indicate that they should
# be rebuilt even when the interface jar does not change.
generate_interface_jar(target_name) {
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
"assert_no_deps", "assert_no_deps",
...@@ -3498,30 +3608,12 @@ if (enable_java_templates) { ...@@ -3498,30 +3608,12 @@ if (enable_java_templates) {
# as inputs to other targets. # as inputs to other targets.
public_deps = _accumulated_public_deps public_deps = _accumulated_public_deps
# Always used the unfiltered .jar to create the interface jar so that
# other targets will resolve filtered classes when depending on
# BuildConfig, NativeLibraries, etc.
input_jar = _unprocessed_jar_path
output_jar = _final_ijar_path
if (_lint_enabled || _enable_errorprone) { if (_lint_enabled || _enable_errorprone) {
if (!defined(data_deps)) { if (!defined(data_deps)) {
data_deps = [] data_deps = []
} }
data_deps += [ ":${_main_target_name}__analysis" ] data_deps += [ ":${_main_target_name}__analysis" ]
} }
# proguard_configs listed on java_library targets need to be marked
# as inputs to at least one action so that "gn analyze" will know
# about them. Although ijar doesn't use them, it's a convenient spot
# to list them.
# https://crbug.com/827197
if (defined(invoker.proguard_configs)) {
inputs = invoker.proguard_configs
if (!defined(deps)) {
deps = []
}
deps += _srcjar_deps # For the aapt-generated proguard rules.
}
} }
} }
} }
......
...@@ -1130,6 +1130,9 @@ if (enable_java_templates) { ...@@ -1130,6 +1130,9 @@ if (enable_java_templates) {
possible_config_deps = invoker.deps possible_config_deps = invoker.deps
} }
} }
java_header_group("${target_name}__header") {
forward_variables_from(invoker, [ "deps" ])
}
group(target_name) { group(target_name) {
forward_variables_from(invoker, "*") forward_variables_from(invoker, "*")
if (!defined(deps)) { if (!defined(deps)) {
......
...@@ -6,5 +6,11 @@ ...@@ -6,5 +6,11 @@
import("//build/config/android/rules.gni") import("//build/config/android/rules.gni")
android_library("compositor_animator_java") { android_library("compositor_animator_java") {
# Turbine does not generate bridge methods in the parent class. Thus each
# child class generates its own bridge methods and adds a number of methods.
# This target would add about 30 methods if it enabled turbine. We are
# hoping to turn this back on once r8 can mitigate these extra methods.
enable_turbine = false
sources = [ "java/src/org/chromium/chrome/browser/compositor/animation/FloatProperty.java" ] sources = [ "java/src/org/chromium/chrome/browser/compositor/animation/FloatProperty.java" ]
} }
...@@ -413,7 +413,6 @@ java_library("robolectric_utils_java") { ...@@ -413,7 +413,6 @@ java_library("robolectric_utils_java") {
"robolectric/utils/reflector/src/main/java/org/robolectric/util/reflector/WeakerHashMap.java", "robolectric/utils/reflector/src/main/java/org/robolectric/util/reflector/WeakerHashMap.java",
"robolectric/utils/reflector/src/main/java/org/robolectric/util/reflector/WithType.java", "robolectric/utils/reflector/src/main/java/org/robolectric/util/reflector/WithType.java",
"robolectric/utils/src/main/java/org/robolectric/AndroidMetadata.java", "robolectric/utils/src/main/java/org/robolectric/AndroidMetadata.java",
"robolectric/utils/src/main/java/org/robolectric/AndroidMetadata.java",
"robolectric/utils/src/main/java/org/robolectric/util/Clock.java", "robolectric/utils/src/main/java/org/robolectric/util/Clock.java",
"robolectric/utils/src/main/java/org/robolectric/util/Consumer.java", "robolectric/utils/src/main/java/org/robolectric/util/Consumer.java",
"robolectric/utils/src/main/java/org/robolectric/util/Join.java", "robolectric/utils/src/main/java/org/robolectric/util/Join.java",
...@@ -559,6 +558,10 @@ java_library("robolectric_shadowapi_java") { ...@@ -559,6 +558,10 @@ java_library("robolectric_shadowapi_java") {
java_library("shadows_core_java") { java_library("shadows_core_java") {
output_name = "shadows-core-3.2" output_name = "shadows-core-3.2"
# Disable java headers since this target fails to compile with:
# error: An exception occurred in org.robolectric.annotation.processing.RobolectricProcessor:
enable_turbine = false
# Skip platform checks since we must depend on accessibility_test_framework_java # Skip platform checks since we must depend on accessibility_test_framework_java
# here which requires_android. # here which requires_android.
bypass_platform_checks = true bypass_platform_checks = true
...@@ -1085,6 +1088,11 @@ java_library("shadows_multidex_java") { ...@@ -1085,6 +1088,11 @@ java_library("shadows_multidex_java") {
# Skip platform checks since we must depend on android_support_multidex_java # Skip platform checks since we must depend on android_support_multidex_java
# here which requires_android. # here which requires_android.
bypass_platform_checks = true bypass_platform_checks = true
# Disable java headers since this target fails to compile with:
# error: An exception occurred in org.robolectric.annotation.processing.RobolectricProcessor:
enable_turbine = false
skip_jetify = true skip_jetify = true
testonly = true testonly = true
processor_args_javac = [ "org.robolectric.annotation.processing.shadowPackage=org.robolectric.shadows.multidex" ] processor_args_javac = [ "org.robolectric.annotation.processing.shadowPackage=org.robolectric.shadows.multidex" ]
...@@ -1127,6 +1135,10 @@ java_library("shadows_play_services_java") { ...@@ -1127,6 +1135,10 @@ java_library("shadows_play_services_java") {
# and google_play_services_library here which both requires_android. # and google_play_services_library here which both requires_android.
bypass_platform_checks = true bypass_platform_checks = true
# Disable java headers since this target fails to compile with:
# error: An exception occurred in org.robolectric.annotation.processing.RobolectricProcessor:
enable_turbine = false
testonly = true testonly = true
skip_jetify = true skip_jetify = true
processor_args_javac = [ "org.robolectric.annotation.processing.shadowPackage=org.robolectric.shadows.gms" ] processor_args_javac = [ "org.robolectric.annotation.processing.shadowPackage=org.robolectric.shadows.gms" ]
......
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