Commit 5df91bf7 authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Silence build logs about d8's desugaring

We use Desugar to desugar default interface methods, so do not need to
pay attention to these D8/R8 messages.

Sadly, -dontnote does not work for them, and there is no way to disable
desugaring of default interface methods without also disabling method
backporting (which we do want D8/R8 to perform.

Bug: 1029357
Change-Id: Icb73b0d7f4233d7402c681bd30e3bcfdb101db33
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2304969Reviewed-by: default avatarSam Maier <smaier@chromium.org>
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790001}
parent db5fc682
...@@ -23,7 +23,7 @@ import convert_dex_profile ...@@ -23,7 +23,7 @@ import convert_dex_profile
_IGNORE_WARNINGS = ( _IGNORE_WARNINGS = (
# A play services library triggers this. # Caused by Play Services:
r'Type `libcore.io.Memory` was not found', r'Type `libcore.io.Memory` was not found',
# Filter out warnings caused by our fake main dex list used to enable # Filter out warnings caused by our fake main dex list used to enable
# multidex on library targets. # multidex on library targets.
...@@ -73,6 +73,9 @@ def _ParseArgs(args): ...@@ -73,6 +73,9 @@ def _ParseArgs(args):
help='GN-list of bootclasspath. Needed for --desugar') help='GN-list of bootclasspath. Needed for --desugar')
parser.add_argument( parser.add_argument(
'--desugar-jdk-libs-json', help='Path to desugar_jdk_libs.json.') '--desugar-jdk-libs-json', help='Path to desugar_jdk_libs.json.')
parser.add_argument('--show-desugar-default-interface-warnings',
action='store_true',
help='Enable desugaring warnings.')
parser.add_argument( parser.add_argument(
'--classpath', '--classpath',
action='append', action='append',
...@@ -136,24 +139,21 @@ def _ParseArgs(args): ...@@ -136,24 +139,21 @@ def _ParseArgs(args):
return options return options
def _RunD8(dex_cmd, input_paths, output_path): def CreateStderrFilter(show_desugar_default_interface_warnings):
dex_cmd = dex_cmd + ['--output', output_path] + input_paths def filter_stderr(output):
def stderr_filter(output):
patterns = _IGNORE_WARNINGS patterns = _IGNORE_WARNINGS
# No classpath means we are using Bazel's Desugar tool to desugar lambdas # When using Bazel's Desugar tool to desugar lambdas and interface methods,
# and interface methods, in which case we intentionally do not pass a # we do not provide D8 with a classpath, which causes a lot of warnings
# classpath to D8. # from D8's default interface desugaring pass.
# Not having a classpath makes incremental dexing much more effective. # Not having a classpath makes incremental dexing much more effective.
# D8 will still be used for backported method desugaring. # D8 still does backported method desugaring.
# We still use D8 for backported method desugaring. if not show_desugar_default_interface_warnings:
if '--classpath' not in dex_cmd:
patterns = list(patterns) + ['default or static interface methods'] patterns = list(patterns) + ['default or static interface methods']
combined_pattern = '|'.join(re.escape(p) for p in patterns) combined_pattern = '|'.join(re.escape(p) for p in patterns)
output = build_utils.FilterLines(output, combined_pattern) output = build_utils.FilterLines(output, combined_pattern)
# Each warning has a prefix line of tthe file it's from. If we've filtered # Each warning has a prefix line of the file it's from. If we've filtered
# out the warning, then also filter out the file header. # out the warning, then also filter out the file header.
# E.g.: # E.g.:
# Warning in path/to/Foo.class: # Warning in path/to/Foo.class:
...@@ -162,6 +162,15 @@ def _RunD8(dex_cmd, input_paths, output_path): ...@@ -162,6 +162,15 @@ def _RunD8(dex_cmd, input_paths, output_path):
output = re.sub(r'^Warning in .*?:\n(?! )', '', output, flags=re.MULTILINE) output = re.sub(r'^Warning in .*?:\n(?! )', '', output, flags=re.MULTILINE)
return output return output
return filter_stderr
def _RunD8(dex_cmd, input_paths, output_path,
show_desugar_default_interface_warnings):
dex_cmd = dex_cmd + ['--output', output_path] + input_paths
stderr_filter = CreateStderrFilter(show_desugar_default_interface_warnings)
with tempfile.NamedTemporaryFile() as flag_file: with tempfile.NamedTemporaryFile() as flag_file:
# Chosen arbitrarily. Needed to avoid command-line length limits. # Chosen arbitrarily. Needed to avoid command-line length limits.
MAX_ARGS = 50 MAX_ARGS = 50
...@@ -353,7 +362,8 @@ def _CreateFinalDex(d8_inputs, output, tmp_dir, dex_cmd, options=None): ...@@ -353,7 +362,8 @@ def _CreateFinalDex(d8_inputs, output, tmp_dir, dex_cmd, options=None):
tmp_dex_dir = os.path.join(tmp_dir, 'tmp_dex_dir') tmp_dex_dir = os.path.join(tmp_dir, 'tmp_dex_dir')
os.mkdir(tmp_dex_dir) os.mkdir(tmp_dex_dir)
_RunD8(dex_cmd, d8_inputs, tmp_dex_dir) _RunD8(dex_cmd, d8_inputs, tmp_dex_dir,
(options and options.show_desugar_default_interface_warnings))
logging.debug('Performed dex merging') logging.debug('Performed dex merging')
dex_files = [os.path.join(tmp_dex_dir, f) for f in os.listdir(tmp_dex_dir)] dex_files = [os.path.join(tmp_dex_dir, f) for f in os.listdir(tmp_dex_dir)]
...@@ -435,7 +445,8 @@ def _CreateIntermediateDexFiles(changes, options, tmp_dir, dex_cmd): ...@@ -435,7 +445,8 @@ def _CreateIntermediateDexFiles(changes, options, tmp_dir, dex_cmd):
if class_files: if class_files:
# Dex necessary classes into intermediate dex files. # Dex necessary classes into intermediate dex files.
dex_cmd = dex_cmd + ['--intermediate', '--file-per-class-file'] dex_cmd = dex_cmd + ['--intermediate', '--file-per-class-file']
_RunD8(dex_cmd, class_files, options.incremental_dir) _RunD8(dex_cmd, class_files, options.incremental_dir,
options.show_desugar_default_interface_warnings)
logging.debug('Dexed class files.') logging.debug('Dexed class files.')
......
...@@ -12,6 +12,7 @@ import sys ...@@ -12,6 +12,7 @@ import sys
import tempfile import tempfile
import zipfile import zipfile
import dex
import dex_jdk_libs import dex_jdk_libs
from util import build_utils from util import build_utils
from util import diff_utils from util import diff_utils
...@@ -31,48 +32,6 @@ _CHECKDISCARD_RE = re.compile(r'^\s*-checkdiscard[\s\S]*?}', re.MULTILINE) ...@@ -31,48 +32,6 @@ _CHECKDISCARD_RE = re.compile(r'^\s*-checkdiscard[\s\S]*?}', re.MULTILINE)
_DIRECTIVE_RE = re.compile(r'^\s*-', re.MULTILINE) _DIRECTIVE_RE = re.compile(r'^\s*-', re.MULTILINE)
class _ProguardOutputFilter(object):
"""ProGuard outputs boring stuff to stdout (ProGuard version, jar path, etc)
as well as interesting stuff (notes, warnings, etc). If stdout is entirely
boring, this class suppresses the output.
"""
IGNORE_RE = re.compile(
r'Pro.*version|Note:|Reading|Preparing|Printing|ProgramClass:|Searching|'
r'jar \[|\d+ class path entries checked')
def __init__(self):
self._last_line_ignored = False
self._ignore_next_line = False
def __call__(self, output):
ret = []
for line in output.splitlines(True):
if self._ignore_next_line:
self._ignore_next_line = False
continue
if '***BINARY RUN STATS***' in line:
self._last_line_ignored = True
self._ignore_next_line = True
elif not line.startswith(' '):
self._last_line_ignored = bool(self.IGNORE_RE.match(line))
elif 'You should check if you need to specify' in line:
self._last_line_ignored = True
if not self._last_line_ignored:
ret.append(line)
return ''.join(ret)
class ProguardProcessError(build_utils.CalledProcessError):
"""Wraps CalledProcessError and enables adding extra output to failures."""
def __init__(self, cpe, output):
super(ProguardProcessError, self).__init__(cpe.cwd, cpe.args,
cpe.output + output)
def _ValidateAndFilterCheckDiscards(configs): def _ValidateAndFilterCheckDiscards(configs):
"""Check for invalid -checkdiscard rules and filter out -checkdiscards. """Check for invalid -checkdiscard rules and filter out -checkdiscards.
...@@ -196,6 +155,9 @@ def _ParseOptions(): ...@@ -196,6 +155,9 @@ def _ParseOptions():
action='append', action='append',
dest='feature_names', dest='feature_names',
help='The name of the feature module.') help='The name of the feature module.')
parser.add_argument('--show-desugar-default-interface-warnings',
action='store_true',
help='Enable desugaring warnings.')
parser.add_argument( parser.add_argument(
'--stamp', '--stamp',
help='File to touch upon success. Mutually exclusive with --output-path') help='File to touch upon success. Mutually exclusive with --output-path')
...@@ -295,6 +257,16 @@ class _DexPathContext(object): ...@@ -295,6 +257,16 @@ class _DexPathContext(object):
shutil.move(tmp_jar_output, self._final_output_path) shutil.move(tmp_jar_output, self._final_output_path)
def _CreateStderrFilter(show_desugar_default_interface_warnings):
d8_filter = dex.CreateStderrFilter(show_desugar_default_interface_warnings)
def filter_stderr(output):
output = re.sub(r'.*_JAVA_OPTIONS.*\n?', '', output)
return d8_filter(output)
return filter_stderr
def _OptimizeWithR8(options, def _OptimizeWithR8(options,
config_paths, config_paths,
libraries, libraries,
...@@ -380,19 +352,23 @@ def _OptimizeWithR8(options, ...@@ -380,19 +352,23 @@ def _OptimizeWithR8(options,
cmd += sorted(extra_jars) cmd += sorted(extra_jars)
env = os.environ.copy() env = os.environ.copy()
stderr_filter = lambda l: re.sub(r'.*_JAVA_OPTIONS.*\n?', '', l)
env['_JAVA_OPTIONS'] = '-Dcom.android.tools.r8.allowTestProguardOptions=1' env['_JAVA_OPTIONS'] = '-Dcom.android.tools.r8.allowTestProguardOptions=1'
if options.disable_outlining: if options.disable_outlining:
env['_JAVA_OPTIONS'] += ' -Dcom.android.tools.r8.disableOutlining=1' env['_JAVA_OPTIONS'] += ' -Dcom.android.tools.r8.disableOutlining=1'
try: try:
build_utils.CheckOutput( stderr_filter = _CreateStderrFilter(
cmd, env=env, print_stdout=print_stdout, stderr_filter=stderr_filter) options.show_desugar_default_interface_warnings)
build_utils.CheckOutput(cmd,
env=env,
print_stdout=print_stdout,
stderr_filter=stderr_filter)
except build_utils.CalledProcessError as err: except build_utils.CalledProcessError as err:
debugging_link = ('R8 failed. Please see {}.'.format( debugging_link = ('\n\nR8 failed. Please see {}.'.format(
'https://chromium.googlesource.com/chromium/src/+/HEAD/build/' 'https://chromium.googlesource.com/chromium/src/+/HEAD/build/'
'android/docs/java_optimization.md#Debugging-common-failures\n')) 'android/docs/java_optimization.md#Debugging-common-failures\n'))
raise ProguardProcessError(err, debugging_link) raise build_utils.CalledProcessError(err.cwd, err.args,
err.output + debugging_link)
base_has_imported_lib = False base_has_imported_lib = False
if options.desugar_jdk_libs_json: if options.desugar_jdk_libs_json:
......
# Generated by running: # Generated by running:
# build/print_python_deps.py --root build/android/gyp --output build/android/gyp/proguard.pydeps build/android/gyp/proguard.py # build/print_python_deps.py --root build/android/gyp --output build/android/gyp/proguard.pydeps build/android/gyp/proguard.py
../../gn_helpers.py ../../gn_helpers.py
../../print_python_deps.py
../convert_dex_profile.py
dex.py
dex_jdk_libs.py dex_jdk_libs.py
proguard.py proguard.py
util/__init__.py util/__init__.py
util/build_utils.py util/build_utils.py
util/diff_utils.py util/diff_utils.py
util/md5_check.py
util/zipalign.py
...@@ -1211,6 +1211,9 @@ if (enable_java_templates) { ...@@ -1211,6 +1211,9 @@ if (enable_java_templates) {
rebase_path(_desugared_library_keep_rule_output_path, root_build_dir), rebase_path(_desugared_library_keep_rule_output_path, root_build_dir),
] ]
} }
if (!enable_bazel_desugar) {
_args += [ "--show-desugar-default-interface-warnings" ]
}
_enable_assert = is_java_debug || dcheck_always_on _enable_assert = is_java_debug || dcheck_always_on
if (_enable_assert) { if (_enable_assert) {
...@@ -1656,6 +1659,9 @@ if (enable_java_templates) { ...@@ -1656,6 +1659,9 @@ if (enable_java_templates) {
rebase_path(_desugar_jdk_libs_json, root_build_dir), rebase_path(_desugar_jdk_libs_json, root_build_dir),
] ]
} }
if (!enable_bazel_desugar) {
_args += [ "--show-desugar-default-interface-warnings" ]
}
} }
if (_desugar_needs_classpath) { if (_desugar_needs_classpath) {
args += [ args += [
......
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