Commit 93aa458f authored by Sam Maier's avatar Sam Maier Committed by Commit Bot

Android build: moved proguarding into dex() for most cases

This is to allow R8 to proguard and dex in one call, since it has some
optimizations that only work when doing everything in one shot.

Bug: 872904
Change-Id: Id2c75dac4d9feecae461a0b1e279056253f1b71b
Reviewed-on: https://chromium-review.googlesource.com/c/1227142Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Reviewed-by: default avataragrieve <agrieve@chromium.org>
Commit-Queue: Sam Maier <smaier@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597257}
parent b2612e18
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
import optparse import optparse
import os import os
import shutil
import sys import sys
import tempfile import tempfile
...@@ -56,15 +57,23 @@ def _ParseOptions(args): ...@@ -56,15 +57,23 @@ def _ParseOptions(args):
'included by --proguard-configs, but that should ' 'included by --proguard-configs, but that should '
'not actually be included.') 'not actually be included.')
parser.add_option('--mapping', help='Path to proguard mapping to apply.') parser.add_option('--mapping', help='Path to proguard mapping to apply.')
parser.add_option('--mapping-output',
help='Path for proguard to output mapping file to.')
parser.add_option('--classpath', action='append', parser.add_option('--classpath', action='append',
help='Classpath for proguard.') help='Classpath for proguard.')
parser.add_option('--enable-dangerous-optimizations', action='store_true', parser.add_option('--enable-dangerous-optimizations', action='store_true',
help='Enable optimizations which are known to have issues.') help='Enable optimizations which are known to have issues.')
parser.add_option('--main-dex-rules-path', action='append',
help='Paths to main dex rules for multidex'
'- only works with R8.')
parser.add_option('--verbose', '-v', action='store_true', parser.add_option('--verbose', '-v', action='store_true',
help='Print all proguard output') help='Print all proguard output')
options, _ = parser.parse_args(args) options, _ = parser.parse_args(args)
assert not options.main_dex_rules_path or options.r8_path, \
"R8 must be enabled to pass main dex rules."
classpath = [] classpath = []
for arg in options.classpath: for arg in options.classpath:
classpath += build_utils.ParseGnList(arg) classpath += build_utils.ParseGnList(arg)
...@@ -79,16 +88,38 @@ def _ParseOptions(args): ...@@ -79,16 +88,38 @@ def _ParseOptions(args):
options.input_paths = build_utils.ParseGnList(options.input_paths) options.input_paths = build_utils.ParseGnList(options.input_paths)
if not options.mapping_output:
options.mapping_output = options.output_path + ".mapping"
return options return options
def _CreateR8Command(options, map_output_path): def _MoveTempDexFile(tmp_dex_dir, dex_path):
"""Move the temp dex file out of |tmp_dex_dir|.
Args:
tmp_dex_dir: Path to temporary directory created with tempfile.mkdtemp().
The directory should have just a single file.
dex_path: Target path to move dex file to.
Raises:
Exception if there are multiple files in |tmp_dex_dir|.
"""
tempfiles = os.listdir(tmp_dex_dir)
if len(tempfiles) > 1:
raise Exception('%d files created, expected 1' % len(tempfiles))
tmp_dex_path = os.path.join(tmp_dex_dir, tempfiles[0])
shutil.move(tmp_dex_path, dex_path)
def _CreateR8Command(options, map_output_path, output_dir):
# TODO: R8 needs -applymapping equivalent. # TODO: R8 needs -applymapping equivalent.
cmd = [ cmd = [
'java', '-jar', options.r8_path, 'java', '-jar', options.r8_path,
'--no-desugaring', '--no-desugaring',
'--classfile', '--no-data-resources',
'--output', options.output_path, '--output', output_dir,
'--pg-map-output', map_output_path, '--pg-map-output', map_output_path,
] ]
...@@ -101,6 +132,10 @@ def _CreateR8Command(options, map_output_path): ...@@ -101,6 +132,10 @@ def _CreateR8Command(options, map_output_path):
for config_file in options.proguard_configs: for config_file in options.proguard_configs:
cmd += ['--pg-conf', config_file] cmd += ['--pg-conf', config_file]
if options.main_dex_rules_path:
for main_dex_rule in options.main_dex_rules_path:
cmd += ['--main-dex-rules', main_dex_rule]
cmd += options.input_paths cmd += options.input_paths
return cmd return cmd
...@@ -114,6 +149,7 @@ def main(args): ...@@ -114,6 +149,7 @@ def main(args):
proguard.configs(options.proguard_configs) proguard.configs(options.proguard_configs)
proguard.config_exclusions(options.proguard_config_exclusions) proguard.config_exclusions(options.proguard_config_exclusions)
proguard.outjar(options.output_path) proguard.outjar(options.output_path)
proguard.mapping_output(options.mapping_output)
# If a jar is part of input no need to include it as library jar. # If a jar is part of input no need to include it as library jar.
classpath = [ classpath = [
...@@ -127,12 +163,17 @@ def main(args): ...@@ -127,12 +163,17 @@ def main(args):
# TODO(agrieve): Remove proguard usages. # TODO(agrieve): Remove proguard usages.
if options.r8_path: if options.r8_path:
with tempfile.NamedTemporaryFile() as mapping_temp: with tempfile.NamedTemporaryFile() as mapping_temp:
# R8 will output mapping file to this temp file if options.output_path.endswith('.dex'):
cmd = _CreateR8Command(options, mapping_temp.name) with build_utils.TempDir() as tmp_dex_dir:
cmd = _CreateR8Command(options, mapping_temp.name, tmp_dex_dir)
build_utils.CheckOutput(cmd)
_MoveTempDexFile(tmp_dex_dir, options.output_path)
else:
cmd = _CreateR8Command(options, mapping_temp.name, options.output_path)
build_utils.CheckOutput(cmd) build_utils.CheckOutput(cmd)
# Copy the mapping file back to where it should be. # Copy the mapping file back to where it should be.
map_path = options.output_path + ".mapping" map_path = options.mapping_output
with build_utils.AtomicOutput(map_path) as mapping: with build_utils.AtomicOutput(map_path) as mapping:
# Mapping files generated by R8 include comments that may break # Mapping files generated by R8 include comments that may break
# some of our tooling so remove those. # some of our tooling so remove those.
......
...@@ -51,6 +51,7 @@ class ProguardCmdBuilder(object): ...@@ -51,6 +51,7 @@ class ProguardCmdBuilder(object):
self._configs = None self._configs = None
self._config_exclusions = None self._config_exclusions = None
self._outjar = None self._outjar = None
self._mapping_output = None
self._verbose = False self._verbose = False
self._disabled_optimizations = [] self._disabled_optimizations = []
...@@ -58,6 +59,10 @@ class ProguardCmdBuilder(object): ...@@ -58,6 +59,10 @@ class ProguardCmdBuilder(object):
assert self._outjar is None assert self._outjar is None
self._outjar = path self._outjar = path
def mapping_output(self, path):
assert self._mapping_output is None
self._mapping_output = path
def mapping(self, path): def mapping(self, path):
assert self._mapping is None assert self._mapping is None
assert os.path.exists(path), path assert os.path.exists(path), path
...@@ -124,7 +129,7 @@ class ProguardCmdBuilder(object): ...@@ -124,7 +129,7 @@ class ProguardCmdBuilder(object):
'-outjars', self._outjar, '-outjars', self._outjar,
'-printseeds', self._outjar + '.seeds', '-printseeds', self._outjar + '.seeds',
'-printusage', self._outjar + '.usage', '-printusage', self._outjar + '.usage',
'-printmapping', self._outjar + '.mapping', '-printmapping', self._mapping_output,
] ]
if self._verbose: if self._verbose:
...@@ -156,7 +161,7 @@ class ProguardCmdBuilder(object): ...@@ -156,7 +161,7 @@ class ProguardCmdBuilder(object):
return [ return [
self._outjar, self._outjar,
self._outjar + '.flags', self._outjar + '.flags',
self._outjar + '.mapping', self._mapping_output,
self._outjar + '.seeds', self._outjar + '.seeds',
self._outjar + '.usage', self._outjar + '.usage',
] ]
......
...@@ -944,7 +944,7 @@ if (enable_java_templates) { ...@@ -944,7 +944,7 @@ if (enable_java_templates) {
# http://crbug.com/725224. Fix for bots running out of memory. # http://crbug.com/725224. Fix for bots running out of memory.
pool = "//build/toolchain:link_pool($default_toolchain)" pool = "//build/toolchain:link_pool($default_toolchain)"
_output_jar_path = invoker.output_jar_path _output_path = invoker.output_path
_proguard_jar_path = _default_proguard_jar_path _proguard_jar_path = _default_proguard_jar_path
if (defined(invoker.proguard_jar_path)) { if (defined(invoker.proguard_jar_path)) {
_proguard_jar_path = invoker.proguard_jar_path _proguard_jar_path = invoker.proguard_jar_path
...@@ -957,10 +957,14 @@ if (enable_java_templates) { ...@@ -957,10 +957,14 @@ if (enable_java_templates) {
if (defined(invoker.inputs)) { if (defined(invoker.inputs)) {
inputs += invoker.inputs inputs += invoker.inputs
} }
_mapping_path = "$_output_path.mapping"
if (defined(invoker.proguard_mapping_path)) {
_mapping_path = invoker.proguard_mapping_path
}
depfile = "${target_gen_dir}/${target_name}.d" depfile = "${target_gen_dir}/${target_name}.d"
outputs = [ outputs = [
_output_jar_path, _output_path,
"$_output_jar_path.mapping", _mapping_path,
] ]
_rebased_build_config = rebase_path(invoker.build_config, root_build_dir) _rebased_build_config = rebase_path(invoker.build_config, root_build_dir)
args = [ args = [
...@@ -969,7 +973,9 @@ if (enable_java_templates) { ...@@ -969,7 +973,9 @@ if (enable_java_templates) {
"--proguard-path", "--proguard-path",
rebase_path(_proguard_jar_path, root_build_dir), rebase_path(_proguard_jar_path, root_build_dir),
"--output-path", "--output-path",
rebase_path(_output_jar_path, root_build_dir), rebase_path(_output_path, root_build_dir),
"--mapping-output",
rebase_path(_mapping_path, root_build_dir),
"--classpath", "--classpath",
"@FileArg($_rebased_build_config:deps_info:proguard_classpath_jars)", "@FileArg($_rebased_build_config:deps_info:proguard_classpath_jars)",
"--classpath", "--classpath",
...@@ -1058,9 +1064,81 @@ if (enable_java_templates) { ...@@ -1058,9 +1064,81 @@ if (enable_java_templates) {
} }
template("dex") { template("dex") {
assert(defined(invoker.output))
_proguard_enabled =
defined(invoker.proguard_enabled) && invoker.proguard_enabled
_proguarding_with_r8 = _proguard_enabled && experimental_r8_path != ""
assert(!(defined(invoker.input_jars) && _proguard_enabled),
"input_jars can't be specified when proguarding a dex.")
if (!_proguarding_with_r8) {
_dexing_jars = []
if (defined(invoker.input_jars)) {
_dexing_jars += invoker.input_jars
}
}
if (_proguard_enabled) {
if (defined(invoker.enable_multidex)) {
assert(invoker.enable_multidex || !invoker.enable_multidex)
if (defined(invoker.extra_main_dex_proguard_config)) {
assert(invoker.extra_main_dex_proguard_config != [])
}
if (defined(invoker.negative_main_dex_globs)) {
assert(invoker.negative_main_dex_globs != [])
}
}
if (_proguarding_with_r8) {
_proguard_output_path = invoker.output
_proguard_target_name = target_name
} else {
_proguard_output_path = invoker.output + ".proguard.jar"
_proguard_target_name = "${target_name}__proguard"
_dexing_jars += [ _proguard_output_path ]
}
proguard(_proguard_target_name) {
forward_variables_from(invoker,
[
"proguard_jar_path",
"deps",
"build_config",
"proguard_mapping_path",
"testonly",
])
inputs = []
if (defined(invoker.inputs)) {
inputs += invoker.inputs
}
if (defined(invoker.proguard_configs)) {
inputs += invoker.proguard_configs
}
_rebased_build_config = rebase_path(build_config, root_build_dir)
args = [
"--proguard-configs=@FileArg($_rebased_build_config:deps_info:proguard_all_configs)",
"--input-paths=@FileArg($_rebased_build_config:deps_info:java_runtime_classpath)",
]
if (defined(invoker.proguard_config_exclusions)) {
_rebased_proguard_config_exclusions =
rebase_path(invoker.proguard_config_exclusions, root_build_dir)
args += [
"--proguard-config-exclusions=$_rebased_proguard_config_exclusions",
]
}
if (defined(invoker.proguard_args)) {
args += invoker.proguard_args
}
output_path = _proguard_output_path
}
}
if (!_proguarding_with_r8) {
_enable_multidex = _enable_multidex =
defined(invoker.enable_multidex) && invoker.enable_multidex defined(invoker.enable_multidex) && invoker.enable_multidex
if (_enable_multidex) { if (_enable_multidex) {
_main_dex_list_path = invoker.output + ".main_dex_list" _main_dex_list_path = invoker.output + ".main_dex_list"
_main_dex_list_target_name = "${target_name}__main_dex_list" _main_dex_list_target_name = "${target_name}__main_dex_list"
...@@ -1117,13 +1195,19 @@ if (enable_java_templates) { ...@@ -1117,13 +1195,19 @@ if (enable_java_templates) {
inputs += [ invoker.extra_main_dex_proguard_config ] inputs += [ invoker.extra_main_dex_proguard_config ]
args += [ args += [
"--main-dex-rules-path", "--main-dex-rules-path",
rebase_path(invoker.extra_main_dex_proguard_config, root_build_dir), rebase_path(invoker.extra_main_dex_proguard_config,
root_build_dir),
] ]
} }
if (_proguard_enabled) {
deps += [ ":${_proguard_target_name}" ]
}
if (defined(invoker.negative_main_dex_globs)) { if (defined(invoker.negative_main_dex_globs)) {
args += args += [
[ "--negative-main-dex-globs=${invoker.negative_main_dex_globs}" ] "--negative-main-dex-globs=${invoker.negative_main_dex_globs}",
]
} }
if (defined(invoker.input_jars_file_arg)) { if (defined(invoker.input_jars_file_arg)) {
...@@ -1131,14 +1215,13 @@ if (enable_java_templates) { ...@@ -1131,14 +1215,13 @@ if (enable_java_templates) {
args += [ "--inputs=${invoker.input_jars_file_arg}" ] args += [ "--inputs=${invoker.input_jars_file_arg}" ]
} }
if (defined(invoker.input_jars)) { inputs += _dexing_jars
inputs += invoker.input_jars if (_dexing_jars != []) {
args += rebase_path(invoker.input_jars, root_build_dir) args += rebase_path(_dexing_jars, root_build_dir)
} }
} }
} }
assert(defined(invoker.output))
action_with_pydeps(target_name) { action_with_pydeps(target_name) {
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
...@@ -1152,10 +1235,6 @@ if (enable_java_templates) { ...@@ -1152,10 +1235,6 @@ if (enable_java_templates) {
invoker.output, invoker.output,
] ]
if (defined(invoker.use_pool) && invoker.use_pool) {
pool = "//build/toolchain:link_pool($default_toolchain)"
}
_rebased_output = rebase_path(invoker.output, root_build_dir) _rebased_output = rebase_path(invoker.output, root_build_dir)
args = [ args = [
...@@ -1165,21 +1244,8 @@ if (enable_java_templates) { ...@@ -1165,21 +1244,8 @@ if (enable_java_templates) {
_rebased_output, _rebased_output,
] ]
if (defined(invoker.dexlayout_profile)) { if (_proguard_enabled) {
args += [ deps += [ ":${_proguard_target_name}" ]
"--dexlayout-profile",
rebase_path(invoker.dexlayout_profile, root_build_dir),
"--dexlayout-path",
rebase_path(_dexlayout_path, root_build_dir),
"--profman-path",
rebase_path(_profman_path, root_build_dir),
]
inputs += [
_dexlayout_path,
_profman_path,
invoker.dexlayout_profile,
]
inputs += _default_art_libs
} }
if (_enable_multidex) { if (_enable_multidex) {
...@@ -1197,9 +1263,26 @@ if (enable_java_templates) { ...@@ -1197,9 +1263,26 @@ if (enable_java_templates) {
args += [ "--inputs=${invoker.input_jars_file_arg}" ] args += [ "--inputs=${invoker.input_jars_file_arg}" ]
} }
if (defined(invoker.input_jars)) { inputs += _dexing_jars
inputs += invoker.input_jars if (_dexing_jars != []) {
args += rebase_path(invoker.input_jars, root_build_dir) args += rebase_path(_dexing_jars, root_build_dir)
}
if (defined(invoker.dexlayout_profile)) {
args += [
"--dexlayout-profile",
rebase_path(invoker.dexlayout_profile, root_build_dir),
"--dexlayout-path",
rebase_path(_dexlayout_path, root_build_dir),
"--profman-path",
rebase_path(_profman_path, root_build_dir),
]
inputs += [
_dexlayout_path,
_profman_path,
invoker.dexlayout_profile,
]
inputs += _default_art_libs
} }
_d8_path = "//third_party/r8/lib/d8.jar" _d8_path = "//third_party/r8/lib/d8.jar"
...@@ -1210,6 +1293,7 @@ if (enable_java_templates) { ...@@ -1210,6 +1293,7 @@ if (enable_java_templates) {
] ]
} }
} }
}
template("emma_instr") { template("emma_instr") {
action_with_pydeps(target_name) { action_with_pydeps(target_name) {
......
...@@ -1406,18 +1406,12 @@ if (enable_java_templates) { ...@@ -1406,18 +1406,12 @@ if (enable_java_templates) {
# #
# Variables: # Variables:
# output: Path to the output jar. # output: Path to the output jar.
# dex_path: Path to dex()'ed output (optional).
# override_build_config: Use a pre-existing .build_config. Must be of type # override_build_config: Use a pre-existing .build_config. Must be of type
# "apk". # "apk".
# use_interface_jars: Use all dependent interface .jars rather than # use_interface_jars: Use all dependent interface .jars rather than
# implementation .jars. # implementation .jars.
# use_unprocessed_jars: Use unprocessed / undesugared .jars. # use_unprocessed_jars: Use unprocessed / undesugared .jars.
# direct_deps_only: Do not recurse on deps. # direct_deps_only: Do not recurse on deps.
# proguard_enabled: Whether to run ProGuard on resulting jar.
# proguard_configs: List of proguard configs.
# proguard_jar_path: The path to proguard.jar you wish to use. If undefined,
# the proguard used will be the checked in one in //third_party/proguard.
# alternative_android_sdk_jar: System jar to use when proguard is enabled.
# #
# Example # Example
# dist_jar("lib_fatjar") { # dist_jar("lib_fatjar") {
...@@ -1435,29 +1429,16 @@ if (enable_java_templates) { ...@@ -1435,29 +1429,16 @@ if (enable_java_templates) {
!defined(invoker.supports_android) || invoker.supports_android !defined(invoker.supports_android) || invoker.supports_android
_requires_android = _requires_android =
defined(invoker.requires_android) && invoker.requires_android defined(invoker.requires_android) && invoker.requires_android
_proguard_enabled =
defined(invoker.proguard_enabled) && invoker.proguard_enabled
_use_interface_jars = _use_interface_jars =
defined(invoker.use_interface_jars) && invoker.use_interface_jars defined(invoker.use_interface_jars) && invoker.use_interface_jars
_use_unprocessed_jars = _use_unprocessed_jars =
defined(invoker.use_unprocessed_jars) && invoker.use_unprocessed_jars defined(invoker.use_unprocessed_jars) && invoker.use_unprocessed_jars
_direct_deps_only = _direct_deps_only =
defined(invoker.direct_deps_only) && invoker.direct_deps_only defined(invoker.direct_deps_only) && invoker.direct_deps_only
assert(!(_proguard_enabled && _use_interface_jars),
"Cannot set both proguard_enabled and use_interface_jars")
assert(!(_proguard_enabled && _direct_deps_only),
"Cannot set both proguard_enabled and direct_deps_only")
assert(!(_use_unprocessed_jars && _use_interface_jars), assert(!(_use_unprocessed_jars && _use_interface_jars),
"Cannot set both use_interface_jars and use_unprocessed_jars") "Cannot set both use_interface_jars and use_unprocessed_jars")
_jar_target_name = target_name _jar_target_name = target_name
if (defined(invoker.dex_path)) {
if (_proguard_enabled) {
_jar_target_name = "${target_name}__proguard"
} else {
_jar_target_name = "${target_name}__dist_jar"
}
}
_deps = [] _deps = []
if (defined(invoker.deps)) { if (defined(invoker.deps)) {
...@@ -1481,11 +1462,6 @@ if (enable_java_templates) { ...@@ -1481,11 +1462,6 @@ if (enable_java_templates) {
write_build_config(_build_config_target_name) { write_build_config(_build_config_target_name) {
type = "dist_jar" type = "dist_jar"
forward_variables_from(invoker,
[
"proguard_enabled",
"proguard_configs",
])
supports_android = _supports_android supports_android = _supports_android
requires_android = _requires_android requires_android = _requires_android
possible_config_deps = _deps possible_config_deps = _deps
...@@ -1496,38 +1472,6 @@ if (enable_java_templates) { ...@@ -1496,38 +1472,6 @@ if (enable_java_templates) {
} }
_rebased_build_config = rebase_path(_build_config, root_build_dir) _rebased_build_config = rebase_path(_build_config, root_build_dir)
if (_proguard_enabled) {
proguard(_jar_target_name) {
forward_variables_from(invoker,
[
"data",
"proguard_jar_path",
])
build_config = _build_config
deps = _deps
# Although these will be listed as deps in the depfile, they must also
# appear here so that "gn analyze" knows about them.
# https://crbug.com/827197
inputs = []
if (defined(invoker.proguard_configs)) {
inputs += invoker.proguard_configs
}
output_jar_path = invoker.output
args = [
"--proguard-configs=@FileArg($_rebased_build_config:deps_info:proguard_all_configs)",
"--input-paths=@FileArg($_rebased_build_config:deps_info:java_runtime_classpath)",
]
if (defined(invoker.proguard_config_exclusions)) {
_rebased_proguard_config_exclusions =
rebase_path(invoker.proguard_config_exclusions, root_build_dir)
args += [
"--proguard-config-exclusions=$_rebased_proguard_config_exclusions",
]
}
}
} else {
action_with_pydeps(_jar_target_name) { action_with_pydeps(_jar_target_name) {
forward_variables_from(invoker, [ "data" ]) forward_variables_from(invoker, [ "data" ])
script = "//build/android/gyp/create_dist_jar.py" script = "//build/android/gyp/create_dist_jar.py"
...@@ -1551,10 +1495,11 @@ if (enable_java_templates) { ...@@ -1551,10 +1495,11 @@ if (enable_java_templates) {
if (_direct_deps_only) { if (_direct_deps_only) {
if (_use_interface_jars) { if (_use_interface_jars) {
args += [ "--jars=@FileArg($_rebased_build_config:javac:interface_classpath)" ] args += [
"--jars=@FileArg($_rebased_build_config:javac:interface_classpath)",
]
} else if (_use_unprocessed_jars) { } else if (_use_unprocessed_jars) {
args += args += [ "--jars=@FileArg($_rebased_build_config:javac:classpath)" ]
[ "--jars=@FileArg($_rebased_build_config:javac:classpath)" ]
} else { } else {
assert( assert(
false, false,
...@@ -1571,14 +1516,55 @@ if (enable_java_templates) { ...@@ -1571,14 +1516,55 @@ if (enable_java_templates) {
} }
} }
} }
if (defined(invoker.dex_path)) {
dex(target_name) { # Combines all dependent .jar files into a single proguarded .dex file.
deps = [ #
":$_jar_target_name", # Variables:
# output: Path to the output dex.
# proguard_configs: List of proguard configs.
# proguard_jar_path: The path to proguard.jar you wish to use. If undefined,
# the proguard used will be the checked in one in //third_party/proguard.
#
# Example
# dist_dex("lib_fatjar") {
# deps = [ ":my_java_lib" ]
# output = "$root_build_dir/MyLibrary.jar"
# }
# dist_jar("sideloaded_dex") {
# deps = [ ":my_java_lib" ]
# output = "$root_build_dir/MyLibrary.jar"
# dex_path = "$root_build_dir/MyLibrary.dex"
# }
template("proguarded_dist_dex") {
_deps = [
"//third_party/android_tools:android_sdk_java",
"//build/android/buildhooks:build_hooks_android_impl_java",
] ]
input_jars = [ invoker.output ] if (defined(invoker.deps)) {
output = invoker.dex_path _deps += invoker.deps
} }
_build_config = "$target_gen_dir/$target_name.build_config"
_build_config_target_name = "${target_name}__build_config"
write_build_config(_build_config_target_name) {
type = "dist_jar"
forward_variables_from(invoker, [ "proguard_configs" ])
supports_android = true
requires_android = true
proguard_enabled = true
possible_config_deps = _deps
build_config = _build_config
}
_deps += [ ":$_build_config_target_name" ]
dex(target_name) {
deps = _deps
build_config = _build_config
proguard_enabled = true
forward_variables_from(invoker, [ "proguard_configs" ])
output = invoker.output
} }
} }
...@@ -1920,11 +1906,7 @@ if (enable_java_templates) { ...@@ -1920,11 +1906,7 @@ if (enable_java_templates) {
_enable_multidex = _enable_multidex =
defined(invoker.enable_multidex) && invoker.enable_multidex defined(invoker.enable_multidex) && invoker.enable_multidex
if (_enable_multidex) {
_final_dex_path = "$_gen_dir/classes.dex.zip" _final_dex_path = "$_gen_dir/classes.dex.zip"
} else {
_final_dex_path = "$_gen_dir/classes.dex"
}
if (defined(invoker.final_apk_path)) { if (defined(invoker.final_apk_path)) {
_final_apk_path = invoker.final_apk_path _final_apk_path = invoker.final_apk_path
...@@ -2443,65 +2425,38 @@ if (enable_java_templates) { ...@@ -2443,65 +2425,38 @@ if (enable_java_templates) {
# place later due to synchronized proguarding. For more details, # place later due to synchronized proguarding. For more details,
# read build/android/docs/android_app_bundles.md # read build/android/docs/android_app_bundles.md
if (!(_is_bundle_module && _proguard_enabled)) { if (!(_is_bundle_module && _proguard_enabled)) {
if (_proguard_enabled) { _final_dex_target_name = "${_template_name}__final_dex"
_proguard_target = "${_template_name}__proguard" dex(_final_dex_target_name) {
proguard(_proguard_target) { forward_variables_from(invoker, [ "dexlayout_profile" ])
forward_variables_from(invoker, [ "proguard_jar_path" ]) proguard_enabled = _proguard_enabled
build_config = _build_config build_config = _build_config
deps = _deps + [ deps = [
":$_build_config_target", ":$_build_config_target",
":$_compile_resources_target",
":$_java_target", ":$_java_target",
] ]
inputs = [ if (_proguard_enabled) {
_jar_path, forward_variables_from(invoker, [ "proguard_jar_path" ])
] deps += _deps + [ ":$_compile_resources_target" ]
proguard_configs = [ _jar_path ]
output_jar_path = _proguard_output_jar_path
args = [
"--proguard-configs=@FileArg($_rebased_build_config:deps_info:proguard_all_configs)",
"--input-paths=@FileArg($_rebased_build_config:deps_info:java_runtime_classpath)",
]
if (defined(invoker.proguard_config_exclusions)) {
_rebased_proguard_config_exclusions =
rebase_path(invoker.proguard_config_exclusions, root_build_dir)
args += [ "--proguard-config-exclusions=$_rebased_proguard_config_exclusions" ]
}
if (defined(invoker.apk_under_test)) { if (defined(invoker.apk_under_test)) {
args += [ "--mapping=@FileArg($_rebased_build_config:deps_info:proguard_under_test_mapping)" ] proguard_args = [ "--mapping=@FileArg($_rebased_build_config:deps_info:proguard_under_test_mapping)" ]
deps += [ "${invoker.apk_under_test}__proguard" ] deps += [ "${invoker.apk_under_test}__final_dex" ]
}
}
_dex_sources = [ _proguard_output_jar_path ]
_dex_deps = [ ":$_proguard_target" ]
_copy_proguard_mapping_target =
"${_template_name}__copy_proguard_mapping"
copy(_copy_proguard_mapping_target) {
sources = [
"$_proguard_output_jar_path.mapping",
]
outputs = [
"$_final_apk_path.mapping",
]
deps = [
":$_proguard_target",
]
} }
proguard_mapping_path = "$_final_apk_path.mapping"
} else { } else {
if (_enable_multidex) { if (_enable_multidex) {
# .jar already included in java_runtime_classpath. # .jar already included in java_runtime_classpath.
_dex_sources = [] input_jars = []
_dex_arg_key =
"${_rebased_build_config}:deps_info:java_runtime_classpath"
} else { } else {
_dex_sources = [ _lib_dex_path ] input_jars = [ _lib_dex_path ]
_dex_arg_key =
"${_rebased_build_config}:final_dex:dependency_dex_files"
} }
_dex_deps = [ ":$_java_target" ] input_jars_file_arg = "@FileArg($_dex_arg_key)"
} }
_final_dex_target_name = "${_template_name}__final_dex"
dex("$_final_dex_target_name") {
deps = _dex_deps + [ ":$_build_config_target" ]
input_jars = _dex_sources
output = _final_dex_path output = _final_dex_path
enable_multidex = _enable_multidex enable_multidex = _enable_multidex
...@@ -2510,24 +2465,6 @@ if (enable_java_templates) { ...@@ -2510,24 +2465,6 @@ if (enable_java_templates) {
extra_main_dex_proguard_config = _generated_proguard_main_dex_config extra_main_dex_proguard_config = _generated_proguard_main_dex_config
deps += [ ":$_compile_resources_target" ] deps += [ ":$_compile_resources_target" ]
} }
forward_variables_from(invoker, [ "dexlayout_profile" ])
# All deps are already included in _dex_sources when proguard is used.
if (!_proguard_enabled) {
if (_enable_multidex) {
_dex_arg_key =
"${_rebased_build_config}:deps_info:java_runtime_classpath"
} else {
_dex_arg_key =
"${_rebased_build_config}:final_dex:dependency_dex_files"
}
build_config = _build_config
input_jars_file_arg = "@FileArg($_dex_arg_key)"
}
# http://crbug.com/725224. Fix for bots running out of memory.
use_pool = true
} }
} else { } else {
# A small sanity check to help developers with a subtle point! # A small sanity check to help developers with a subtle point!
...@@ -2788,13 +2725,6 @@ if (enable_java_templates) { ...@@ -2788,13 +2725,6 @@ if (enable_java_templates) {
# Generate apk related operations at runtime. # Generate apk related operations at runtime.
public_deps += _apk_operations public_deps += _apk_operations
# Make the proguard .mapping file easy to find by putting it beside the .apk.
if (_proguard_enabled && !_is_bundle_module) {
deps = [
":$_copy_proguard_mapping_target",
]
}
} }
} }
...@@ -3821,7 +3751,7 @@ if (enable_java_templates) { ...@@ -3821,7 +3751,7 @@ if (enable_java_templates) {
build_config = _build_config build_config = _build_config
deps = _module_targets + [ ":$_build_config_target" ] deps = _module_targets + [ ":$_build_config_target" ]
output_jar_path = _proguard_output_jar_path output_path = _proguard_output_jar_path
args = [ args = [
"--proguard-configs=@FileArg($_rebased_build_config:deps_info:proguard_all_configs)", "--proguard-configs=@FileArg($_rebased_build_config:deps_info:proguard_all_configs)",
"--input-paths=@FileArg($_rebased_build_config:deps_info:java_runtime_classpath)", "--input-paths=@FileArg($_rebased_build_config:deps_info:java_runtime_classpath)",
...@@ -3879,9 +3809,6 @@ if (enable_java_templates) { ...@@ -3879,9 +3809,6 @@ if (enable_java_templates) {
input_jars = [ _module_jar_path ] input_jars = [ _module_jar_path ]
output = _module_final_dex_path output = _module_final_dex_path
# http://crbug.com/725224. Fix for bots running out of memory.
use_pool = true
if (_enable_multidex && _module.name == "base") { if (_enable_multidex && _module.name == "base") {
enable_multidex = _enable_multidex enable_multidex = _enable_multidex
extra_main_dex_proguard_config = extra_main_dex_proguard_config =
......
...@@ -1500,8 +1500,10 @@ template("monochrome_public_apk_or_module_tmpl") { ...@@ -1500,8 +1500,10 @@ template("monochrome_public_apk_or_module_tmpl") {
} }
version_name = chrome_version_name version_name = chrome_version_name
if (experimental_r8_path == "") {
enable_multidex = true enable_multidex = true
} }
}
} }
monochrome_public_apk_or_module_tmpl("monochrome_public_apk") { monochrome_public_apk_or_module_tmpl("monochrome_public_apk") {
...@@ -1848,7 +1850,9 @@ android_app_bundle("monochrome_public_bundle") { ...@@ -1848,7 +1850,9 @@ android_app_bundle("monochrome_public_bundle") {
base_module_target = ":monochrome_public_base_module" base_module_target = ":monochrome_public_base_module"
if (!is_java_debug) { if (!is_java_debug) {
proguard_enabled = true proguard_enabled = true
if (experimental_r8_path == "") {
enable_multidex = true enable_multidex = true
}
proguard_android_sdk_dep = webview_framework_dep proguard_android_sdk_dep = webview_framework_dep
} }
if (modularize_ar) { if (modularize_ar) {
......
...@@ -49,19 +49,16 @@ android_library("runtime_library_for_tests_java") { ...@@ -49,19 +49,16 @@ android_library("runtime_library_for_tests_java") {
] ]
} }
dist_jar("webapk_runtime_library") { proguarded_dist_dex("webapk_runtime_library") {
requires_android = true
deps = [ deps = [
":runtime_library_for_assets_java", ":runtime_library_for_assets_java",
] ]
proguard_enabled = true
proguard_configs = [ proguard_configs = [
"runtime_library.proguard.flags", "runtime_library.proguard.flags",
"//base/android/proguard/chromium_code.flags", "//base/android/proguard/chromium_code.flags",
"//base/android/proguard/chromium_apk.flags", "//base/android/proguard/chromium_apk.flags",
] ]
output = "$target_gen_dir/$target_name.jar" output = "$target_gen_dir/$runtime_library_dex_asset_name"
dex_path = "$target_gen_dir/$runtime_library_dex_asset_name"
} }
android_assets("runtime_library_assets") { android_assets("runtime_library_assets") {
......
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