Commit 8a5a16af authored by Peter Wen's avatar Peter Wen Committed by Commit Bot

Android: Replace desugar with d8 and r8 for debug

For release builds, desugar.jar still runs first, before d8 or r8, so
nothing is changing for them as by the time d8 or r8 runs, the code has
already been desugared.

When r8 is enabled, it can desugar all targets that enable proguard, and
d8 can desugar all targets that do not enable proguard.

This can only be turned on once r8 replaces proguard since proguard does
not understand java 8 code that has not been desugared already.

Bug: 906803, 913679, 916733
Change-Id: I3fcc5a20b38e7fdc78cdeed1533583675d58346b
Reviewed-on: https://chromium-review.googlesource.com/c/1384945Reviewed-by: default avatarSam Maier <smaier@chromium.org>
Commit-Queue: Peter Wen <wnwen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619434}
parent b0a4d000
......@@ -37,6 +37,10 @@ def _ParseArgs(args):
parser = optparse.OptionParser()
build_utils.AddDepfileOption(parser)
parser.add_option('--classpath', help='Classpaths necessary for desugaring.')
parser.add_option(
'--sdk-jars',
help='Path(s) to android sdk jar, necessary for desugaring.')
parser.add_option('--output-directory',
default=os.getcwd(),
help='Path to the output build directory.')
......@@ -318,7 +322,13 @@ def main(args):
if options.multi_dex:
input_paths.append(options.main_dex_list_path)
dex_cmd = ['java', '-jar', options.d8_jar_path, '--no-desugaring']
dex_cmd = ['java', '-jar', options.d8_jar_path]
options.sdk_jars = build_utils.ParseGnList(options.sdk_jars)
options.classpath = build_utils.ParseGnList(options.classpath)
for path in options.classpath:
dex_cmd += ['--classpath', path]
for path in options.sdk_jars:
dex_cmd += ['--lib', path]
if options.multi_dex:
dex_cmd += ['--main-dex-list', options.main_dex_list_path]
if options.release:
......
......@@ -121,7 +121,6 @@ def _CreateR8Command(options, map_output_path, output_dir):
# TODO: R8 needs -applymapping equivalent.
cmd = [
'java', '-jar', options.r8_path,
'--no-desugaring',
'--no-data-resources',
'--output', output_dir,
'--pg-map-output', map_output_path,
......
......@@ -1243,18 +1243,23 @@ if (enable_java_templates) {
])
script = "//build/android/gyp/dex.py"
depfile = "$target_gen_dir/$target_name.d"
inputs = []
inputs = [
invoker.build_config,
]
outputs = [
invoker.output,
]
_rebased_output = rebase_path(invoker.output, root_build_dir)
_rebased_build_config =
rebase_path(invoker.build_config, root_build_dir)
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--dex-path",
_rebased_output,
"--classpath=@FileArg($_rebased_build_config:deps_info:javac_full_interface_classpath)",
"--sdk-jars=@FileArg($_rebased_build_config:android:sdk_jars)",
]
if (_proguard_enabled) {
......@@ -1425,7 +1430,7 @@ if (enable_java_templates) {
# Turned off because of existing code which fails the assertion
_enable_thread_annotations = false
_desugar = defined(invoker.supports_android) && invoker.supports_android
_desugar = defined(invoker.desugar) && invoker.desugar
_emma_instrument = invoker.emma_instrument
_enable_bytecode_rewriter =
_enable_assert || _enable_custom_resources || _enable_thread_annotations
......@@ -3357,6 +3362,9 @@ if (enable_java_templates) {
_accumulated_public_deps += [ ":$_copy_system_library_target_name" ]
} else {
_process_prebuilt_target_name = "${target_name}__process_prebuilt"
# Skip desugaring for debug builds using r8 due to binary size issue.
_desugar = _supports_android && !(is_java_debug && experimental_use_r8)
process_java_prebuilt(_process_prebuilt_target_name) {
forward_variables_from(invoker,
[
......@@ -3366,7 +3374,7 @@ if (enable_java_templates) {
"jar_included_patterns",
])
is_prebuilt = _is_prebuilt
supports_android = _supports_android
desugar = _desugar
enable_build_hooks = _enable_build_hooks
enable_build_hooks_android = _enable_build_hooks_android
build_config = _build_config
......@@ -3389,7 +3397,9 @@ if (enable_java_templates) {
dex("${target_name}__dex") {
input_jars = [ _final_jar_path ]
output = _dex_path
build_config = _build_config
deps = [
":$_build_config_target_name",
":$_process_prebuilt_target_name",
]
}
......
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