Commit 31c83779 authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

Android: When lint fails, print hint about treat_warnings_as_errors=false

Bug: 1029357
Change-Id: I39cd0de5922bfd583edf203ec6086cbe57d7a99c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2363806
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Commit-Queue: Peter Wen <wnwen@chromium.org>
Reviewed-by: default avatarPeter Wen <wnwen@chromium.org>
Auto-Submit: Andrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799796}
parent 2ecafa1c
...@@ -26,6 +26,7 @@ _LINT_MD_URL = 'https://chromium.googlesource.com/chromium/src/+/master/build/an ...@@ -26,6 +26,7 @@ _LINT_MD_URL = 'https://chromium.googlesource.com/chromium/src/+/master/build/an
# These checks are not useful for chromium. # These checks are not useful for chromium.
_DISABLED_ALWAYS = [ _DISABLED_ALWAYS = [
"Assert", # R8 --force-enable-assertions is used to enable java asserts. "Assert", # R8 --force-enable-assertions is used to enable java asserts.
"LintBaseline", # Don't warn about using baseline.xml files.
"MissingApplicationIcon", # False positive for non-production targets. "MissingApplicationIcon", # False positive for non-production targets.
"SwitchIntDef", # Many C++ enums are not used at all in java. "SwitchIntDef", # Many C++ enums are not used at all in java.
"UniqueConstants", # Chromium enums allow aliases. "UniqueConstants", # Chromium enums allow aliases.
...@@ -154,17 +155,11 @@ def _RunLint(lint_binary_path, ...@@ -154,17 +155,11 @@ def _RunLint(lint_binary_path,
lint_gen_dir, lint_gen_dir,
baseline, baseline,
testonly_target=False, testonly_target=False,
warnings_as_errors=False, warnings_as_errors=False):
silent=False):
logging.info('Lint starting') logging.info('Lint starting')
cmd = [ cmd = [
lint_binary_path, lint_binary_path,
# Consider all lint warnings as errors. Warnings should either always be
# fixed or completely suppressed in suppressions.xml. They should not
# bloat build output if they are not important enough to be fixed.
'-Werror',
'--exitcode', # Sets error code if there are errors.
'--quiet', # Silences lint's "." progress updates. '--quiet', # Silences lint's "." progress updates.
'--disable', '--disable',
','.join(_DISABLED_ALWAYS), ','.join(_DISABLED_ALWAYS),
...@@ -238,32 +233,37 @@ def _RunLint(lint_binary_path, ...@@ -238,32 +233,37 @@ def _RunLint(lint_binary_path,
env['LINT_PRINT_STACKTRACE'] = 'true' env['LINT_PRINT_STACKTRACE'] = 'true'
# This filter is necessary for JDK11. # This filter is necessary for JDK11.
stderr_filter = build_utils.FilterReflectiveAccessJavaWarnings stderr_filter = build_utils.FilterReflectiveAccessJavaWarnings
stdout_filter = lambda x: build_utils.FilterLines(x, 'No issues found')
start = time.time()
logging.debug('Lint command %s', cmd)
failed = True
try: try:
logging.debug('Lint command %s', cmd) failed = bool(
start = time.time() build_utils.CheckOutput(cmd,
# Lint outputs "No issues found" if it succeeds, and uses stderr when it env=env,
# fails, so we can safely ignore stdout. print_stdout=True,
build_utils.CheckOutput(cmd, stdout_filter=stdout_filter,
env=env, stderr_filter=stderr_filter,
stderr_filter=stderr_filter) fail_on_output=warnings_as_errors))
finally:
# When not treating warnings as errors, display the extra footer.
is_debug = os.environ.get('LINT_DEBUG', '0') != '0'
if failed:
print('- For more help with lint in Chrome:', _LINT_MD_URL)
if is_debug:
print('- DEBUG MODE: Here is the project.xml: {}'.format(
_SrcRelative(project_xml_path)))
else:
print('- Run with LINT_DEBUG=1 to enable lint configuration debugging')
end = time.time() - start end = time.time() - start
logging.info('Lint command took %ss', end) logging.info('Lint command took %ss', end)
except build_utils.CalledProcessError as e: if not is_debug:
if not silent: shutil.rmtree(resource_root_dir, ignore_errors=True)
print('Lint found new issues.\n' shutil.rmtree(srcjar_root_dir, ignore_errors=True)
' - Here is the project.xml file passed to lint: {}\n' os.unlink(project_xml_path)
' - For more information about lint and how to fix lint issues,'
' please refer to {}\n'.format(_SrcRelative(project_xml_path),
_LINT_MD_URL))
if warnings_as_errors:
raise
else:
print(e)
else:
# Lint succeeded, no need to keep generated files for debugging purposes.
shutil.rmtree(resource_root_dir, ignore_errors=True)
shutil.rmtree(srcjar_root_dir, ignore_errors=True)
logging.info('Lint completed') logging.info('Lint completed')
...@@ -300,9 +300,6 @@ def _ParseArgs(argv): ...@@ -300,9 +300,6 @@ def _ParseArgs(argv):
parser.add_argument('--warnings-as-errors', parser.add_argument('--warnings-as-errors',
action='store_true', action='store_true',
help='Treat all warnings as errors.') help='Treat all warnings as errors.')
parser.add_argument('--silent',
action='store_true',
help='If set, script will not log anything.')
parser.add_argument('--java-sources', parser.add_argument('--java-sources',
help='File containing a list of java sources files.') help='File containing a list of java sources files.')
parser.add_argument('--srcjars', help='GN list of included srcjars.') parser.add_argument('--srcjars', help='GN list of included srcjars.')
...@@ -366,8 +363,7 @@ def main(): ...@@ -366,8 +363,7 @@ def main():
args.lint_gen_dir, args.lint_gen_dir,
args.baseline, args.baseline,
testonly_target=args.testonly, testonly_target=args.testonly,
warnings_as_errors=args.warnings_as_errors, warnings_as_errors=args.warnings_as_errors)
silent=args.silent)
logging.info('Creating stamp file') logging.info('Creating stamp file')
build_utils.Touch(args.stamp) build_utils.Touch(args.stamp)
......
...@@ -1079,7 +1079,6 @@ if (enable_java_templates) { ...@@ -1079,7 +1079,6 @@ if (enable_java_templates) {
# Putting the stamp file in the cache dir allows us to depend on ninja # Putting the stamp file in the cache dir allows us to depend on ninja
# to create the cache dir for us. # to create the cache dir for us.
_stamp_path = "$_cache_dir/build.lint.stamp" _stamp_path = "$_cache_dir/build.lint.stamp"
args += [ "--silent" ]
} else { } else {
_stamp_path = "$target_out_dir/$target_name/build.lint.stamp" _stamp_path = "$target_out_dir/$target_name/build.lint.stamp"
deps += [ deps += [
......
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