Commit de766129 authored by Becky Zhou's avatar Becky Zhou Committed by Commit Bot

Revert "Using R8 in place of Proguard for creating main dex list"

This reverts commit eec7c07a.

Reason for revert: crbug.com/970298

Original change's description:
> Using R8 in place of Proguard for creating main dex list
> 
> Bug: 908988
> Change-Id: I9cfe718d3754b92022c9045f860dee36c7e049bb
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1635949
> Commit-Queue: Sam Maier <smaier@chromium.org>
> Auto-Submit: Sam Maier <smaier@chromium.org>
> Reviewed-by: Eric Stevenson <estevenson@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#665957}

TBR=estevenson@chromium.org,smaier@chromium.org

Change-Id: I101d3a08afe9ae37eb3ed37472a4b625ea12af7e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 908988
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1643081Reviewed-by: default avatarBecky Zhou <huayinz@chromium.org>
Commit-Queue: Becky Zhou <huayinz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665968}
parent d0a494cb
......@@ -32,8 +32,8 @@ def main(args):
parser.add_argument('--inputs',
help='JARs for which a main dex list should be '
'generated.')
parser.add_argument(
'--r8-path', required=True, help='Path to the r8 executable.')
parser.add_argument('--proguard-path', required=True,
help='Path to the proguard executable.')
parser.add_argument('--negative-main-dex-globs',
help='GN-list of globs of .class names (e.g. org/chromium/foo/Bar.class) '
'that will fail the build if they match files in the main dex.')
......@@ -55,24 +55,13 @@ def main(args):
args.negative_main_dex_globs)
proguard_cmd = [
'java',
'-jar',
args.r8_path,
'--classfile',
'--lib',
args.shrinked_android_path,
'java', '-jar', args.proguard_path,
'-forceprocessing',
'-dontwarn', '-dontoptimize', '-dontobfuscate', '-dontpreverify',
'-libraryjars', args.shrinked_android_path,
]
for m in args.main_dex_rules_paths:
proguard_cmd.extend(['--pg-conf', m])
proguard_flags = [
'-forceprocessing',
'-dontwarn',
'-dontoptimize',
'-dontobfuscate',
'-dontpreverify',
]
proguard_cmd.extend(['-include', m])
main_dex_list_cmd = [
'java', '-cp', args.dx_path,
......@@ -94,24 +83,17 @@ def main(args):
proguard_cmd,
main_dex_list_cmd,
]
if args.negative_main_dex_globs:
input_strings += args.negative_main_dex_globs
for glob in args.negative_main_dex_globs:
# Globs come with 1 asterix, but we want 2 to match subpackages.
proguard_flags.append('-checkdiscard class ' +
glob.replace('*', '**').replace('/', '.'))
output_paths = [
args.main_dex_list_path,
]
def _LineLengthHelperForOnStaleMd5():
_OnStaleMd5(proguard_cmd, proguard_flags, main_dex_list_cmd, args.paths,
args.main_dex_list_path)
build_utils.CallAndWriteDepfileIfStale(
_LineLengthHelperForOnStaleMd5,
lambda: _OnStaleMd5(proguard_cmd, main_dex_list_cmd, args.paths,
args.main_dex_list_path,
args.negative_main_dex_globs),
args,
input_paths=input_paths,
input_strings=input_strings,
......@@ -122,22 +104,38 @@ def main(args):
return 0
def _OnStaleMd5(proguard_cmd, proguard_flags, main_dex_list_cmd, paths,
main_dex_list_path):
def _CheckForUnwanted(kept_classes, proguard_cmd, negative_main_dex_globs):
# Check if ProGuard kept any unwanted classes.
found_unwanted_classes = sorted(
p for p in kept_classes
if build_utils.MatchesGlob(p, negative_main_dex_globs))
if found_unwanted_classes:
first_class = found_unwanted_classes[0].replace(
'.class', '').replace('/', '.')
proguard_cmd += ['-whyareyoukeeping', 'class', first_class, '{}']
output = build_utils.CheckOutput(
proguard_cmd, print_stderr=False,
stdout_filter=proguard_util.ProguardOutputFilter())
raise Exception(
('Found classes that should not be in the main dex:\n {}\n\n'
'Here is the -whyareyoukeeping output for {}: \n{}').format(
'\n '.join(found_unwanted_classes), first_class, output))
def _OnStaleMd5(proguard_cmd, main_dex_list_cmd, paths, main_dex_list_path,
negative_main_dex_globs):
paths_arg = ':'.join(paths)
main_dex_list = ''
try:
with tempfile.NamedTemporaryFile(suffix='.jar') as temp_jar:
# Step 1: Use ProGuard to find all @MainDex code, and all code reachable
# from @MainDex code (recursive).
proguard_cmd += ['--output', temp_jar.name]
with tempfile.NamedTemporaryFile() as proguard_flags_file:
for flag in proguard_flags:
proguard_flags_file.write(flag + '\n')
proguard_flags_file.flush()
proguard_cmd += ['--pg-conf', proguard_flags_file.name]
for injar in paths:
proguard_cmd.append(injar)
build_utils.CheckOutput(proguard_cmd, print_stderr=False)
proguard_cmd += [
'-injars', paths_arg,
'-outjars', temp_jar.name
]
build_utils.CheckOutput(proguard_cmd, print_stderr=False)
# Record the classes kept by ProGuard. Not used by the build, but useful
# for debugging what classes are kept by ProGuard vs. MainDexListBuilder.
......@@ -146,9 +144,18 @@ def _OnStaleMd5(proguard_cmd, proguard_flags, main_dex_list_cmd, paths,
with open(main_dex_list_path + '.partial', 'w') as f:
f.write('\n'.join(kept_classes) + '\n')
if negative_main_dex_globs:
# Perform assertions before MainDexListBuilder because:
# a) MainDexListBuilder is not recursive, so being included by it isn't
# a huge deal.
# b) Errors are much more actionable.
_CheckForUnwanted(kept_classes, proguard_cmd, negative_main_dex_globs)
# Step 2: Expand inclusion list to all classes referenced by the .class
# files of kept classes (non-recursive).
main_dex_list_cmd += [temp_jar.name, ':'.join(paths)]
main_dex_list_cmd += [
temp_jar.name, paths_arg
]
main_dex_list = build_utils.CheckOutput(main_dex_list_cmd)
except build_utils.CalledProcessError as e:
......
......@@ -1302,11 +1302,18 @@ if (enable_java_templates) {
# http://crbug.com/725224. Fix for bots running out of memory.
pool = "//build/toolchain:link_pool($default_toolchain)"
if (defined(invoker.proguard_jar_path)) {
_proguard_jar_path = invoker.proguard_jar_path
} else {
_proguard_jar_path = _default_proguard_jar_path
}
_shrinked_android = "$android_sdk_build_tools/lib/shrinkedAndroid.jar"
_dx = "$android_sdk_build_tools/lib/dx.jar"
inputs = [
_main_dex_rules,
_dx,
_proguard_jar_path,
_shrinked_android,
]
......@@ -1325,8 +1332,8 @@ if (enable_java_templates) {
rebase_path(_main_dex_list_path, root_build_dir),
"--main-dex-rules-path",
rebase_path(_main_dex_rules, root_build_dir),
"--r8-path",
rebase_path("//third_party/r8/lib/r8.jar", root_build_dir),
"--proguard-path",
rebase_path(_proguard_jar_path, root_build_dir),
]
if (defined(invoker.extra_main_dex_proguard_config)) {
......@@ -1351,11 +1358,11 @@ if (enable_java_templates) {
if (defined(invoker.input_jar_classpath)) {
inputs += [ invoker.build_config ]
args += [ "--inputs=@FileArg(${invoker.input_jar_classpath})" ]
} else {
inputs += _dexing_jars
if (_dexing_jars != []) {
args += rebase_path(_dexing_jars, root_build_dir)
}
}
inputs += _dexing_jars
if (_dexing_jars != []) {
args += rebase_path(_dexing_jars, root_build_dir)
}
}
}
......
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