Commit 7b39bed1 authored by Peter Wen's avatar Peter Wen Committed by Commit Bot

Android: Generate project.xml for lint

Use --project to pass in a generated project.xml file for each lint
target instead of passing each argument through the command line. This
allows the lint checks to function more correctly and thoroughly than
before.

Currently lint does not fully support srcjars (fix is in ToT but not yet
in our lint version), so we extract generated sources and generated
resources in a consistent temporary location under their lint target's
gen dir, removing them if lint succeeds and leaving them in place if
lint fails in order to make it easier to debug lint failures.

Clean up and remove various options that are no longer used or needed.
e.g. display lint errors directly rather than parsing an xml file from
lint's results.

Simplify suppressions file comments and remove unnecessary ones. Ignore
common failures for translations since we have a dedicated translation
team.

Remove an unused dimens and fix a few issues. Suppress additional issues
found by this lint improvement.

Bug: 1082743
Change-Id: I67147e582bd904308fe6a5fc5a11baebd60db41b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2212550
Commit-Queue: Peter Wen <wnwen@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Auto-Submit: Peter Wen <wnwen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772301}
parent 7829cbdd
......@@ -3,10 +3,8 @@
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Runs Android's lint tool."""
from __future__ import print_function
import argparse
......@@ -24,7 +22,7 @@ from util import build_utils
from util import manifest_utils
from util import resource_utils
_LINT_MD_URL = 'https://chromium.googlesource.com/chromium/src/+/master/build/android/docs/lint.md' # pylint: disable=line-too-long
_LINT_MD_URL = 'https://chromium.googlesource.com/chromium/src/+/master/build/android/docs/lint.md' # pylint: disable=line-too-long
# These checks are not useful for test targets and adds an unnecessary burden
# to suppress them.
......@@ -41,12 +39,83 @@ _DISABLED_FOR_TESTS = [
"UnusedResources",
]
def _RunLint(lint_path,
_RES_ZIP_DIR = 'RESZIPS'
_SRCJAR_DIR = 'SRCJARS'
def _SrcRelative(path):
"""Returns relative path to top-level src dir."""
return os.path.relpath(path, build_utils.DIR_SOURCE_ROOT)
def _GenerateProjectFile(android_manifest,
android_sdk_root,
cache_dir,
sources=None,
srcjar_sources=None,
resource_sources=None,
android_sdk_version=None):
project = ElementTree.Element('project')
root = ElementTree.SubElement(project, 'root')
# An absolute path helps error paths to be shorter.
root.set('dir', os.path.abspath(build_utils.DIR_SOURCE_ROOT))
sdk = ElementTree.SubElement(project, 'sdk')
# Lint requires that the sdk path be an absolute path.
sdk.set('dir', os.path.abspath(android_sdk_root))
cache = ElementTree.SubElement(project, 'cache')
cache.set('dir', _SrcRelative(cache_dir))
main_module = ElementTree.SubElement(project, 'module')
main_module.set('name', 'main')
main_module.set('android', 'true')
main_module.set('library', 'false')
if android_sdk_version:
main_module.set('compile_sdk_version', android_sdk_version)
manifest = ElementTree.SubElement(main_module, 'manifest')
manifest.set('file', _SrcRelative(android_manifest))
if srcjar_sources:
for srcjar_file in srcjar_sources:
src = ElementTree.SubElement(main_module, 'src')
src.set('file', _SrcRelative(srcjar_file))
if sources:
for source in sources:
src = ElementTree.SubElement(main_module, 'src')
src.set('file', _SrcRelative(source))
if resource_sources:
for resource_file in resource_sources:
resource = ElementTree.SubElement(main_module, 'resource')
resource.set('file', _SrcRelative(resource_file))
return project
def _GenerateAndroidManifest(original_manifest_path,
min_sdk_version,
manifest_package=None):
# Set minSdkVersion and package in the manifest to the correct values.
doc, manifest, _ = manifest_utils.ParseManifest(original_manifest_path)
uses_sdk = manifest.find('./uses-sdk')
if uses_sdk is None:
uses_sdk = ElementTree.Element('uses-sdk')
manifest.insert(0, uses_sdk)
uses_sdk.set('{%s}minSdkVersion' % manifest_utils.ANDROID_NAMESPACE,
min_sdk_version)
if manifest_package:
manifest.set('package', manifest_package)
return doc
def _WriteXmlFile(root, path):
build_utils.MakeDirectory(os.path.dirname(path))
with build_utils.AtomicOutput(path) as f:
# Although we can write it just with ElementTree.tostring, using minidom
# makes it a lot easier to read as a human (also on code search).
f.write(
minidom.parseString(ElementTree.tostring(
root, encoding='utf-8')).toprettyxml(indent=' '))
def _RunLint(lint_binary_path,
config_path,
manifest_path,
result_path,
product_dir,
sources,
cache_dir,
android_sdk_version,
......@@ -56,268 +125,137 @@ def _RunLint(lint_path,
resource_sources,
resource_zips,
android_sdk_root,
lint_gen_dir,
testonly_target=False,
can_fail_build=False,
include_unexpected=False,
silent=False):
logging.info('Lint starting')
def _RebasePath(path):
"""Returns relative path to top-level src dir.
Args:
path: A path relative to cwd.
"""
ret = os.path.relpath(os.path.abspath(path), build_utils.DIR_SOURCE_ROOT)
# If it's outside of src/, just use abspath.
if ret.startswith('..'):
ret = os.path.abspath(path)
return ret
def _ProcessResultFile():
with open(result_path, 'rb') as f:
content = f.read().replace(
_RebasePath(product_dir), 'PRODUCT_DIR')
with open(result_path, 'wb') as f:
f.write(content)
def _ParseAndShowResultFile():
dom = minidom.parse(result_path)
issues = dom.getElementsByTagName('issue')
cmd = [
_SrcRelative(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.
]
if config_path:
cmd.extend(['--config', _SrcRelative(config_path)])
if testonly_target:
cmd.extend(['--disable', ','.join(_DISABLED_FOR_TESTS)])
if not manifest_path:
manifest_path = os.path.join(build_utils.DIR_SOURCE_ROOT, 'build',
'android', 'AndroidManifest.xml')
logging.info('Generating Android manifest file')
android_manifest_tree = _GenerateAndroidManifest(manifest_path,
min_sdk_version,
manifest_package)
# Include the rebased manifest_path in the lint generated path so that it is
# clear in error messages where the original AndroidManifest.xml came from.
lint_android_manifest_path = os.path.join(lint_gen_dir,
_SrcRelative(manifest_path))
logging.info('Writing xml file %s', lint_android_manifest_path)
_WriteXmlFile(android_manifest_tree.getroot(), lint_android_manifest_path)
resource_root_dir = os.path.join(lint_gen_dir, _RES_ZIP_DIR)
# These are zip files with generated resources (e. g. strings from GRD).
logging.info('Extracting resource zips')
for resource_zip in resource_zips:
# Use a consistent root and name rather than a temporary file so that
# suppressions can be local to the lint target and the resource target.
resource_dir = os.path.join(resource_root_dir, resource_zip)
shutil.rmtree(resource_dir, True)
os.makedirs(resource_dir)
resource_sources.extend(
build_utils.ExtractAll(resource_zip, path=resource_dir))
logging.info('Extracting srcjars')
srcjar_root_dir = os.path.join(lint_gen_dir, _SRCJAR_DIR)
srcjar_sources = []
if srcjars:
for srcjar in srcjars:
# Use path without extensions since otherwise the file name includes
# .srcjar and lint treats it as a srcjar.
srcjar_dir = os.path.join(srcjar_root_dir, os.path.splitext(srcjar)[0])
shutil.rmtree(srcjar_dir, True)
os.makedirs(srcjar_dir)
# Sadly lint's srcjar support is broken since it only considers the first
# srcjar. Until we roll a lint version with that fixed, we need to extract
# it ourselves.
srcjar_sources.extend(build_utils.ExtractAll(srcjar, path=srcjar_dir))
logging.info('Generating project file')
project_file_root = _GenerateProjectFile(lint_android_manifest_path,
android_sdk_root, cache_dir, sources,
srcjar_sources, resource_sources,
android_sdk_version)
project_xml_path = os.path.join(lint_gen_dir, 'project.xml')
logging.info('Writing xml file %s', project_xml_path)
_WriteXmlFile(project_file_root, project_xml_path)
cmd += ['--project', _SrcRelative(project_xml_path)]
logging.info('Preparing environment variables')
env = os.environ.copy()
# It is important that lint uses the checked-in JDK11 as it is almost 50%
# faster than JDK8.
env['JAVA_HOME'] = os.path.relpath(build_utils.JAVA_HOME,
build_utils.DIR_SOURCE_ROOT)
# This filter is necessary for JDK11.
stderr_filter = build_utils.FilterReflectiveAccessJavaWarnings
try:
logging.debug('Lint command %s', cmd)
start = time.time()
# Lint outputs "No issues found" if it succeeds, and uses stderr when it
# fails, so we can safely ignore stdout.
build_utils.CheckOutput(cmd,
cwd=build_utils.DIR_SOURCE_ROOT,
env=env,
stderr_filter=stderr_filter)
end = time.time() - start
logging.info('Lint command took %ss', end)
except build_utils.CalledProcessError:
if not silent:
print(file=sys.stderr)
for issue in issues:
issue_id = issue.attributes['id'].value
message = issue.attributes['message'].value
location_elem = issue.getElementsByTagName('location')[0]
path = location_elem.attributes['file'].value
line = location_elem.getAttribute('line')
error = '%s:%s %s: %s [warning]' % (path, line, message, issue_id)
print(error.encode('utf-8'), file=sys.stderr)
for attr in ['errorLine1', 'errorLine2']:
error_line = issue.getAttribute(attr)
if error_line:
print(error_line.encode('utf-8'), file=sys.stderr)
return len(issues)
with build_utils.TempDir() as temp_dir:
cmd = [
_RebasePath(lint_path),
'-Werror',
'--exitcode',
'--showall',
'--xml',
_RebasePath(result_path),
# An explicit sdk root needs to be specified since we have an extra
# intermediate 'lastest' directory under cmdline-tools which prevents
# lint from automatically deducing the location of the sdk. The sdk is
# required for many checks (e.g. NewApi). Lint also requires absolute
# paths.
'--sdk-home',
os.path.abspath(android_sdk_root),
]
if config_path:
cmd.extend(['--config', _RebasePath(config_path)])
if testonly_target:
cmd.extend(['--disable', ','.join(_DISABLED_FOR_TESTS)])
tmp_dir_counter = [0]
def _NewTempSubdir(prefix, append_digit=True):
# Helper function to create a new sub directory based on the number of
# subdirs created earlier.
if append_digit:
tmp_dir_counter[0] += 1
prefix += str(tmp_dir_counter[0])
new_dir = os.path.join(temp_dir, prefix)
os.makedirs(new_dir)
return new_dir
resource_dirs = resource_utils.DeduceResourceDirsFromFileList(
resource_sources)
# These are zip files with generated resources (e. g. strings from GRD).
for resource_zip in resource_zips:
resource_dir = _NewTempSubdir(resource_zip, append_digit=False)
resource_dirs.append(resource_dir)
build_utils.ExtractAll(resource_zip, path=resource_dir)
for resource_dir in resource_dirs:
cmd.extend(['--resources', _RebasePath(resource_dir)])
# There may be multiple source files with the same basename (but in
# different directories). It is difficult to determine what part of the path
# corresponds to the java package, and so instead just link the source files
# into temporary directories (creating a new one whenever there is a name
# conflict).
def PathInDir(d, src):
subpath = os.path.join(d, _RebasePath(src))
subdir = os.path.dirname(subpath)
if not os.path.exists(subdir):
os.makedirs(subdir)
return subpath
src_dirs = []
for src in sources:
src_dir = None
for d in src_dirs:
if not os.path.exists(PathInDir(d, src)):
src_dir = d
break
if not src_dir:
src_dir = _NewTempSubdir('SRC_ROOT')
src_dirs.append(src_dir)
cmd.extend(['--sources', _RebasePath(src_dir)])
# In cases where the build dir is outside of the src dir, this can
# result in trying to symlink a file to itself for this file:
# gen/components/version_info/android/java/org/chromium/
# components/version_info/VersionConstants.java
src = os.path.abspath(src)
dst = PathInDir(src_dir, src)
if src == dst:
continue
os.symlink(src, dst)
if srcjars:
srcjar_dir = _NewTempSubdir('GENERATED_SRC_ROOT', append_digit=False)
cmd.extend(['--sources', _RebasePath(srcjar_dir)])
for srcjar in srcjars:
# We choose to allow srcjars that contain java files which have the
# same package and name to clobber each other. This happens for
# generated files like BuildConfig.java. It is generated for
# targets like base_build_config_gen as well as targets like
# chrome_modern_public_base_bundle_module__build_config_srcjar.
# Although we could extract each srcjar to a separate folder, that
# slows down some invocations of lint by 20 seconds or more.
# TODO(wnwen): Switch lint.py to generate a project.xml file which
# supports srcjar inputs by default.
build_utils.ExtractAll(srcjar, path=srcjar_dir, no_clobber=False)
project_dir = _NewTempSubdir('PROJECT_ROOT', append_digit=False)
if android_sdk_version:
# Create dummy project.properies file in a temporary "project" directory.
# It is the only way to add Android SDK to the Lint's classpath. Proper
# classpath is necessary for most source-level checks.
with open(os.path.join(project_dir, 'project.properties'), 'w') \
as propfile:
print('target=android-{}'.format(android_sdk_version), file=propfile)
# Put the manifest in a temporary directory in order to avoid lint detecting
# sibling res/ and src/ directories (which should be pass explicitly if they
# are to be included).
if not manifest_path:
manifest_path = os.path.join(
build_utils.DIR_SOURCE_ROOT, 'build', 'android',
'AndroidManifest.xml')
lint_manifest_path = os.path.join(project_dir, 'AndroidManifest.xml')
shutil.copyfile(os.path.abspath(manifest_path), lint_manifest_path)
# Check that minSdkVersion and package is correct and add it to the manifest
# in case it does not exist.
doc, manifest, _ = manifest_utils.ParseManifest(lint_manifest_path)
manifest_utils.AssertUsesSdk(manifest, min_sdk_version)
manifest_utils.AssertPackage(manifest, manifest_package)
uses_sdk = manifest.find('./uses-sdk')
if uses_sdk is None:
uses_sdk = ElementTree.Element('uses-sdk')
manifest.insert(0, uses_sdk)
uses_sdk.set('{%s}minSdkVersion' % manifest_utils.ANDROID_NAMESPACE,
min_sdk_version)
if manifest_package:
manifest.set('package', manifest_package)
manifest_utils.SaveManifest(doc, lint_manifest_path)
cmd.append(project_dir)
if os.path.exists(result_path):
os.remove(result_path)
env = os.environ.copy()
stderr_filter = build_utils.FilterReflectiveAccessJavaWarnings
if cache_dir:
env['_JAVA_OPTIONS'] = '-Duser.home=%s' % _RebasePath(cache_dir)
# When _JAVA_OPTIONS is set, java prints to stderr:
# Picked up _JAVA_OPTIONS: ...
#
# We drop all lines that contain _JAVA_OPTIONS from the output
stderr_filter = lambda l: re.sub(
r'.*_JAVA_OPTIONS.*\n?',
'',
build_utils.FilterReflectiveAccessJavaWarnings(l))
def fail_func(returncode, stderr):
if returncode != 0:
return True
if (include_unexpected and
'Unexpected failure during lint analysis' in stderr):
return True
return False
try:
env['JAVA_HOME'] = os.path.relpath(build_utils.JAVA_HOME,
build_utils.DIR_SOURCE_ROOT)
logging.debug('Lint command %s', cmd)
start = time.time()
build_utils.CheckOutput(cmd, cwd=build_utils.DIR_SOURCE_ROOT,
env=env or None, stderr_filter=stderr_filter,
fail_func=fail_func)
end = time.time() - start
logging.info('Lint command took %ss', end)
except build_utils.CalledProcessError:
# There is a problem with lint usage
if not os.path.exists(result_path):
raise
# Sometimes produces empty (almost) files:
if os.path.getsize(result_path) < 10:
if can_fail_build:
raise
elif not silent:
traceback.print_exc()
return
# There are actual lint issues
try:
num_issues = _ParseAndShowResultFile()
except Exception: # pylint: disable=broad-except
if not silent:
print('Lint created unparseable xml file...')
print('File contents:')
with open(result_path) as f:
print(f.read())
if can_fail_build:
traceback.print_exc()
if can_fail_build:
raise
else:
return
_ProcessResultFile()
if num_issues == 0 and include_unexpected:
msg = 'Please refer to output above for unexpected lint failures.\n'
else:
msg = ('\nLint found %d new issues.\n'
' - For full explanation, please refer to %s\n'
' - For more information about lint and how to fix lint issues,'
' please refer to %s\n' %
(num_issues, _RebasePath(result_path), _LINT_MD_URL))
if not silent:
print(msg, file=sys.stderr)
if can_fail_build:
raise Exception('Lint failed.')
logging.error(
'Lint found new issues.\n'
' - Here is the project.xml file passed to lint: %s\n'
' - For more information about lint and how to fix lint issues,'
' please refer to %s\n', _SrcRelative(project_xml_path), _LINT_MD_URL)
if can_fail_build:
raise
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')
def _FindInDirectories(directories, filename_filter):
all_files = []
for directory in directories:
all_files.extend(build_utils.FindInDirectory(directory, filename_filter))
return all_files
def _ParseArgs(argv):
parser = argparse.ArgumentParser()
build_utils.AddDepfileOption(parser)
parser.add_argument('--lint-binary-path',
required=True,
help='Path to lint executable.')
parser.add_argument('--cache-dir',
required=True,
help='Path to the directory in which the android cache '
'directory tree should be stored.')
parser.add_argument('--config-path', help='Path to lint suppressions file.')
parser.add_argument('--lint-gen-dir',
required=True,
help='Path to store generated xml files.')
parser.add_argument('--stamp', help='Path to stamp upon success.')
parser.add_argument('--android-sdk-version',
help='Version (API level) of the Android SDK used for '
'building.')
parser.add_argument('--min-sdk-version',
required=True,
help='Minimal SDK version to lint against.')
parser.add_argument('--android-sdk-root',
required=True,
help='Lint needs an explicit path to the android sdk.')
......@@ -326,32 +264,20 @@ def _ParseArgs(argv):
help='If set, some checks like UnusedResources will be '
'disabled since they are not helpful for test '
'targets.')
parser.add_argument('--lint-path', required=True,
help='Path to lint executable.')
parser.add_argument('--product-dir', required=True,
help='Path to product dir.')
parser.add_argument('--result-path', required=True,
help='Path to XML lint result file.')
parser.add_argument('--cache-dir', required=True,
help='Path to the directory in which the android cache '
'directory tree should be stored.')
parser.add_argument('--platform-xml-path', required=True,
help='Path to api-platforms.xml')
parser.add_argument('--android-sdk-version',
help='Version (API level) of the Android SDK used for '
'building.')
parser.add_argument('--can-fail-build', action='store_true',
help='If set, script will exit with nonzero exit status'
' if lint errors are present')
parser.add_argument('--include-unexpected-failures', action='store_true',
parser.add_argument('--manifest-package',
help='Package name of the AndroidManifest.xml.')
parser.add_argument('--can-fail-build',
action='store_true',
help='If set, script will exit with nonzero exit status'
' if lint itself crashes with unexpected failures.')
parser.add_argument('--config-path',
help='Path to lint suppressions file.')
' if lint errors are present')
parser.add_argument('--silent',
action='store_true',
help='If set, script will not log anything.')
parser.add_argument('--java-sources',
help='File containing a list of java sources files.')
parser.add_argument('--srcjars', help='GN list of included srcjars.')
parser.add_argument('--manifest-path',
help='Path to AndroidManifest.xml')
help='Path to original AndroidManifest.xml')
parser.add_argument('--resource-sources',
default=[],
action='append',
......@@ -362,25 +288,12 @@ def _ParseArgs(argv):
action='append',
help='GYP-list of resource zips, zip files of generated '
'resource files.')
parser.add_argument('--silent', action='store_true',
help='If set, script will not log anything.')
parser.add_argument('--srcjars',
help='GN list of included srcjars.')
parser.add_argument('--stamp', help='Path to stamp upon success.')
parser.add_argument(
'--min-sdk-version',
required=True,
help='Minimal SDK version to lint against.')
parser.add_argument(
'--manifest-package', help='Package name of the AndroidManifest.xml.')
args = parser.parse_args(build_utils.ExpandFileArgs(argv))
args.java_sources = build_utils.ParseGnList(args.java_sources)
args.srcjars = build_utils.ParseGnList(args.srcjars)
args.resource_sources = build_utils.ParseGnList(args.resource_sources)
args.resource_zips = build_utils.ParseGnList(args.resource_zips)
return args
......@@ -391,7 +304,6 @@ def main():
sources = []
for java_sources_file in args.java_sources:
sources.extend(build_utils.ReadSourcesList(java_sources_file))
resource_sources = []
for resource_sources_file in args.resource_sources:
resource_sources.extend(build_utils.ReadSourcesList(resource_sources_file))
......@@ -400,14 +312,11 @@ def main():
resource_sources + [
args.manifest_path,
])
depfile_deps = [p for p in possible_depfile_deps if p]
_RunLint(args.lint_path,
_RunLint(args.lint_binary_path,
args.config_path,
args.manifest_path,
args.result_path,
args.product_dir,
sources,
args.cache_dir,
args.android_sdk_version,
......@@ -417,9 +326,9 @@ def main():
resource_sources,
args.resource_zips,
args.android_sdk_root,
args.lint_gen_dir,
testonly_target=args.testonly,
can_fail_build=args.can_fail_build,
include_unexpected=args.include_unexpected_failures,
silent=args.silent)
logging.info('Creating stamp file')
build_utils.Touch(args.stamp)
......
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<lint>
<!--
STOP! It looks like you want to suppress some lint errors:
......@@ -6,19 +6,12 @@ STOP! It looks like you want to suppress some lint errors:
Ask the author for a fix and/or revert the patch.
- It is preferred to add suppressions in the code instead of
sweeping it under the rug here. See:
http://developer.android.com/tools/debugging/improving-w-lint.html
Still reading?
- You can edit this file manually to suppress an issue
globally if it is not applicable to the project. When inserting new tags,
keep this file in sorted order.
- You can also automatically add issues found so for in the
build process by running:
build/android/lint/suppress.py
which will generate this file (Comments are not preserved).
- Edit this file manually to suppress an issue. Please make the suppression as
local as possible, i.e. by warning message or by file.
- When adding new issues, please keep the issue ids in sorted order.
-->
<issue id="AcceptsUserCertificates">
<!-- See https://crbug.com/827265 and comment in the file for context. -->
......@@ -26,10 +19,7 @@ Still reading?
<ignore regexp="android_webview/tools/system_webview_shell/apk/res/xml/network_security_config.xml"/>
<ignore regexp="test"/>
</issue>
<!-- AllowBackup defaults to true, and causes a lint warning if not explicitly set. -->
<issue id="AllowBackup">
<ignore path="AndroidManifest.xml"/>
</issue>
<issue id="AllowBackup" severity="ignore"/>
<!-- TODO(crbug.com/804427): Remove this suppression or add rationale. -->
<issue id="AppCompatResource" severity="ignore"/>
<!-- We use asserts in Chromium. See https://chromium.googlesource.com/chromium/src/+/master/styleguide/java/java.md#Asserts -->
......@@ -72,7 +62,6 @@ Still reading?
<issue id="DefaultLocale">
<ignore regexp="clank"/>
<ignore regexp="com/android/tv"/>
<ignore regexp="org/chromium/chrome/browser/payments/PaymentRequestMetricsTest.class"/>
<ignore regexp="third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/contrib/AndroidListenerState.java"/>
<!-- TODO(crbug.com/1081240): Fix -->
<ignore regexp="chrome/android/feed/core/java/src/org/chromium/chrome/browser/feed/FeedSurfaceMediator.java"/>
......@@ -101,38 +90,24 @@ Still reading?
<!-- TODO(crbug.com/804438): Cannot update until android.media.ExifInterface supports file descriptors -->
<ignore regexp="chrome/android/java/src/org/chromium/chrome/browser/photo_picker/BitmapUtils.java"/>
</issue>
<issue id="ExportedContentProvider">
<ignore path="AndroidManifest.xml"/>
</issue>
<issue id="ExportedService" severity="Error">
<ignore regexp="AndroidManifest.xml"/>
</issue>
<issue id="ExportedContentProvider" severity="ignore"/>
<issue id="ExportedService" severity="ignore"/>
<!-- TODO(crbug.com/635567): Fix this properly. -->
<issue id="GoogleAppIndexingUrlError" severity="Error">
<ignore regexp="AndroidManifest.xml"/>
</issue>
<issue id="GoogleAppIndexingUrlError" severity="ignore"/>
<!-- TODO(crbug.com/635567): Fix this properly. -->
<issue id="GoogleAppIndexingWarning" severity="Error">
<ignore regexp="AndroidManifest.xml"/>
</issue>
<issue id="GoogleAppIndexingWarning" severity="ignore"/>
<issue id="HandlerLeak">
<ignore regexp="android_webview/glue/java/src/com/android/webview/chromium/WebViewContentsClientAdapter.java"/>
<ignore regexp="chromecast/internal"/>
<ignore regexp="remoting/android/java/src/org/chromium/chromoting/TapGestureDetector.java"/>
</issue>
<issue id="HardcodedDebugMode" severity="Fatal">
<ignore path="AndroidManifest.xml"/>
</issue>
<issue id="HardcodedDebugMode" severity="ignore"/>
<issue id="HardcodedText" severity="Error">
<ignore regexp="chromecast/internal"/>
<ignore regexp="remoting/android/host/res/layout/main.xml"/>
</issue>
<issue id="IconColors" severity="Error">
<ignore regexp="tools/android/audio_focus_grabber/java/res/drawable-hdpi/notification_icon.png"/>
<ignore regexp="tools/android/audio_focus_grabber/java/res/drawable-mdpi/notification_icon.png"/>
<ignore regexp="tools/android/audio_focus_grabber/java/res/drawable-xhdpi/notification_icon.png"/>
<ignore regexp="tools/android/audio_focus_grabber/java/res/drawable-xxhdpi/notification_icon.png"/>
<ignore regexp="tools/android/audio_focus_grabber/java/res/drawable-xxxhdpi/notification_icon.png"/>
<ignore regexp="tools/android/audio_focus_grabber/java/res/drawable-.*/notification_icon.png"/>
</issue>
<issue id="IconDensities">
<!-- This is intentional to reduce APK size. See: http://crrev/c/1352161 -->
......@@ -247,12 +222,7 @@ Still reading?
<issue id="MissingPermission" severity="ignore"/>
<!-- TODO(yolandyan) remove this once all tests are converted to junit4 -->
<issue id="MissingPrefix" severity="ignore"/>
<issue id="MissingQuantity">
<ignore regexp="android_chrome_strings.xml"/>
<ignore regexp="android_chrome_tab_ui_strings.xml"/>
<ignore regexp="components/browser_ui/strings/android/browser_ui_strings_grd"/>
<ignore regexp="clank/third_party/chime/chime_systemtray_strings_grd.resources.zip"/>
</issue>
<issue id="MissingQuantity" severity="ignore"/>
<issue id="MissingRegistered" severity="ignore"/>
<issue id="MissingSuperCall" severity="Error">
<ignore regexp="chrome/android/java/src/org/chromium/chrome/browser/widget/selection/SelectionToolbar.java"/>
......@@ -263,9 +233,7 @@ Still reading?
<ignore regexp="restriction_values.xml.*"/>
<ignore regexp="remoting/resources/strings_java.resources.zip"/>
</issue>
<issue id="MissingVersion">
<ignore path="AndroidManifest.xml"/>
</issue>
<issue id="MissingVersion" severity="ignore"/>
<issue id="NewApi">
<!-- Do not add new suppressions without rationale. -->
<!-- 2: We support these via desugar. -->
......@@ -277,13 +245,15 @@ Still reading?
<ignore regexp="third_party/android_sdk/public/extras/chromium/support/src/org/chromium/android/support/PackageManagerWrapper.java"/>
<!-- 1: TODO(crbug.com/1082222): Fix -->
<ignore regexp="chrome/android/java/src/org/chromium/chrome/browser/omnibox/suggestions/header/HeaderView.java"/>
<!-- 1: TODO(crbug.com/1085410): Fix -->
<ignore regexp="components/content_capture/android/java/src/org/chromium/components/content_capture"/>
<!-- 1: TODO(crbug.com/1085487): Fix -->
<ignore regexp="chrome/android/javatests/src/org/chromium/chrome/browser/directactions/DirectActionTestRule.java"/>
<!-- Endnote: Please specify number of suppressions when adding more -->
</issue>
<!-- This warning just adds a lot of false positives. -->
<issue id="ObsoleteSdkInt" severity="ignore"/>
<issue id="OldTargetApi">
<ignore path="AndroidManifest.xml"/>
</issue>
<issue id="OldTargetApi" severity="ignore"/>
<issue id="OnClick">
<!-- False positive, see: http://issuetracker.google.com/148523770 for similar issue. -->
<ignore regexp="tools/android/audio_focus_grabber/java/res/layout/audio_focus_grabber_activity.xml"/>
......@@ -330,20 +300,12 @@ Still reading?
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-fr/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-pl/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values/android_chrome_strings.xml"/>
<!-- This string has a % in it. -->
<ignore regexp="data_reduction_promo_infobar_title"/>
</issue>
<!-- Most .xtb files in this group have a % that is not part of a formatted string. https://crbug.com/941164 -->
<issue id="StringFormatInvalid" severity="Error">
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-cs/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-da/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-et/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-is/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-pl/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-pt-rBR/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-sq/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-sv/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-tl/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-uz/android_chrome_strings.xml"/>
</issue>
<!-- Many .xtb files have a % that is not part of a formatted string. https://crbug.com/941164 -->
<issue id="StringFormatInvalid" severity="ignore"/>
<issue id="StringFormatMatches" severity="ignore"/>
<!-- We have many C++ enums that we don't care about in java -->
<issue id="SwitchIntDef" severity="ignore"/>
<issue id="TextFields" severity="Error">
......@@ -358,63 +320,27 @@ Still reading?
<issue id="UniqueConstants" severity="ignore"/>
<issue id="UnusedAttribute" severity="ignore"/>
<issue id="UnusedIds" severity="ignore"/>
<issue id="UnusedQuantity" severity="Error">
<!-- This is needed for suppressing warnings on upstream and downstream build bots -->
<ignore regexp="chrome/android/features/tab_ui/java_strings_grd.resources.zip/values-cs/android_chrome_tab_ui_strings.xml"/>
<ignore regexp="chrome/android/features/tab_ui/java_strings_grd.resources.zip/values-in/android_chrome_tab_ui_strings.xml"/>
<ignore regexp="chrome/android/features/tab_ui/java_strings_grd.resources.zip/values-ja/android_chrome_tab_ui_strings.xml"/>
<ignore regexp="chrome/android/features/tab_ui/java_strings_grd.resources.zip/values-km/android_chrome_tab_ui_strings.xml"/>
<ignore regexp="chrome/android/features/tab_ui/java_strings_grd.resources.zip/values-ko/android_chrome_tab_ui_strings.xml"/>
<ignore regexp="chrome/android/features/tab_ui/java_strings_grd.resources.zip/values-lo/android_chrome_tab_ui_strings.xml"/>
<ignore regexp="chrome/android/features/tab_ui/java_strings_grd.resources.zip/values-lt/android_chrome_tab_ui_strings.xml"/>
<ignore regexp="chrome/android/features/tab_ui/java_strings_grd.resources.zip/values-ms/android_chrome_tab_ui_strings.xml"/>
<ignore regexp="chrome/android/features/tab_ui/java_strings_grd.resources.zip/values-my/android_chrome_tab_ui_strings.xml"/>
<ignore regexp="chrome/android/features/tab_ui/java_strings_grd.resources.zip/values-sk/android_chrome_tab_ui_strings.xml"/>
<ignore regexp="chrome/android/features/tab_ui/java_strings_grd.resources.zip/values-th/android_chrome_tab_ui_strings.xml"/>
<ignore regexp="chrome/android/features/tab_ui/java_strings_grd.resources.zip/values-vi/android_chrome_tab_ui_strings.xml"/>
<ignore regexp="chrome/android/features/tab_ui/java_strings_grd.resources.zip/values-zh-rCN/android_chrome_tab_ui_strings.xml"/>
<ignore regexp="chrome/android/features/tab_ui/java_strings_grd.resources.zip/values-zh-rHK/android_chrome_tab_ui_strings.xml"/>
<ignore regexp="chrome/android/features/tab_ui/java_strings_grd.resources.zip/values-zh-rTW/android_chrome_tab_ui_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-cs/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-in/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-ja/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-km/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-ko/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-lo/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-lt/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-ms/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-my/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-sk/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-th/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-vi/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-zh-rCN/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-zh-rHK/android_chrome_strings.xml"/>
<ignore regexp="chrome/browser/ui/android/strings/ui_strings_grd.resources.zip/values-zh-rTW/android_chrome_strings.xml"/>
<ignore regexp="clank/third_party/chime/chime_systemtray_strings_grd.resources.zip"/>
<ignore regexp="components/browser_ui/strings/android/browser_ui_strings_grd"/>
</issue>
<issue id="UnusedQuantity" severity="ignore"/>
<issue id="UnusedResources">
<!-- Do not add new suppressions without rationale. -->
<!-- 3 raw resources are accessed by URL in various places -->
<ignore regexp="gen/remoting/android/.*/res/raw/credits.html"/>
<ignore regexp="gen/remoting/android/.*/res/raw/credits_css.css"/>
<ignore regexp="gen/remoting/android/.*/res/raw/credits_js.js"/>
<!-- 1 all resources in remoting internal -->
<!-- 1: raw resources are accessed by URL in various places -->
<ignore regexp="gen/remoting/android/.*/res/raw/credits.*"/>
<!-- 1: all resources in remoting internal -->
<ignore regexp="remoting/android/internal"/>
<!-- 1 string test only, used in CronetSmokeTestCase dynamically -->
<!-- 1: string test only, used in CronetSmokeTestCase dynamically -->
<ignore regexp="R.string.TestSupportImplClass"/>
<!-- 1 resource used by android webview glue layer, could be refactored -->
<!-- 1: resource used by android webview glue layer, could be refactored -->
<ignore regexp="R.string.private_browsing_warning"/>
<!-- 4 The WAM server currently has 2 codes paths for minting a WebAPK, and
<!-- 4: The WAM server currently has 2 codes paths for minting a WebAPK, and
it needs these "unused" resources.
TODO(crbug.com/1001115): Remove suppression once 2 code paths are merged -->
<ignore regexp="The resource `R.mipmap.ic_launcher_background` appears to be unused"/>
<ignore regexp="The resource `R.mipmap.ic_launcher_foreground` appears to be unused"/>
<ignore regexp="The resource `R.mipmap.maskable_splash_icon_xxhdpi` appears to be unused"/>
<ignore regexp="The resource `R.mipmap.maskable_splash_icon_xxxhdpi` appears to be unused"/>
<!-- 1 Module titles may only be used by the Play Store. -->
<!-- 1: Module titles may only be used by the Play Store. -->
<ignore regexp="The resource `R.string.*_module_title` appears to be unused"/>
<!-- 2 resource sets used by clank widgets for each channel -->
<!-- 2: resource sets used by clank widgets for each channel -->
<ignore regexp="The resource `R.string.bookmark_widget_title.*` appears to be unused"/>
<ignore regexp="The resource `R.string.search_widget_title.*` appears to be unused"/>
<!-- crbug.com/1004570 remove this line and the following seven lines after the bug resolved -->
......@@ -493,6 +419,8 @@ Still reading?
<ignore regexp="The resource `R.plurals.public_notification_text` appears to be unused"/>
<ignore regexp="The resource `R.mipmap.app_shortcut_icon` appears to be unused"/>
<ignore regexp="The resource `R.mipmap.app_single_page_icon` appears to be unused"/>
<!-- 1: Some strings in components_strings_grd are not used in other targets. -->
<ignore regexp="webview_.*__lint.*components_strings_grd"/>
<!-- Endnote: Please specify number of suppressions when adding more -->
</issue>
<issue id="UsableSpace">
......@@ -516,9 +444,7 @@ Still reading?
<ignore regexp="chromecast/internal"/>
<ignore regexp="tools/android/kerberos/SpnegoAuthenticator/res/layout/activity_account_authenticator.xml"/>
</issue>
<issue id="UsesMinSdkAttributes" severity="Error">
<ignore regexp="AndroidManifest.xml"/>
</issue>
<issue id="UsesMinSdkAttributes" severity="ignore"/>
<issue id="ValidFragment" severity="Error">
<ignore regexp="chrome/android/java/src/org/chromium/chrome/browser/media/router/BaseMediaRouteDialogManager.java"/>
<ignore regexp="chrome/android/java/src/org/chromium/chrome/browser/media/router/MediaRouteChooserDialogManager.java"/>
......@@ -546,6 +472,8 @@ Still reading?
<ignore regexp="chrome/android/java/src/org/chromium/chrome/browser/instantapps/InstantAppsHandler.java"/>
<ignore regexp="chrome/android/java/src/org/chromium/chrome/browser/widget/prefeditor/EditorDialog.java"/>
<ignore regexp="third_party/android_data_chart/java/src/org/chromium/third_party/android/datausagechart/ChartDataUsageView.java"/>
<!-- 1: TODO(crbug.com/1085411): Fix -->
<ignore regexp="media/base/android/java/src/org/chromium/media/MediaCodecEncoder.java"/>
<!-- Discussed in crbug.com/1069204, ignoring this class of errors since these are Q+ constants. -->
<ignore regexp="Must be one of: LineBreaker.BREAK_STRATEGY_SIMPLE, LineBreaker.BREAK_STRATEGY_HIGH_QUALITY, LineBreaker.BREAK_STRATEGY_BALANCED"/>
</issue>
......
......@@ -867,8 +867,6 @@ template("test_runner_script") {
}
if (enable_java_templates) {
android_sdk_jar = "$android_sdk/android.jar"
template("android_lint") {
action_with_pydeps(target_name) {
forward_variables_from(invoker,
......@@ -878,59 +876,45 @@ if (enable_java_templates) {
"public_deps",
"testonly",
])
_suppressions_file = "//build/android/lint/suppressions.xml"
if (defined(invoker.lint_suppressions_file)) {
lint_suppressions_file = invoker.lint_suppressions_file
} else if (!defined(lint_suppressions_file)) {
_suppressions_file = invoker.lint_suppressions_file
} else if (defined(lint_suppressions_file)) {
# WebRTC defines its own lint_suppressions_file:
# //tools_webrtc/android/suppressions.xml
lint_suppressions_file = "//build/android/lint/suppressions.xml"
_suppressions_file = lint_suppressions_file
}
_min_sdk_version = default_min_sdk_version
if (defined(invoker.min_sdk_version)) {
_min_sdk_version = invoker.min_sdk_version
}
_lint_path = "$lint_android_sdk_root/cmdline-tools/latest/bin/lint"
_lint_binary_path = "$lint_android_sdk_root/cmdline-tools/latest/bin/lint"
_cache_dir = "$root_build_dir/android_lint_cache"
_result_path = "$target_out_dir/$target_name/result.xml"
_config_path = "$target_out_dir/$target_name/config.xml"
_stamp_path = "$target_out_dir/$target_name/build.lint.stamp"
_suppressions_file = lint_suppressions_file
_platform_xml_path =
"$lint_android_sdk_root/platform-tools/api/api-versions.xml"
# Save these generated xml files in a consistent location for debugging.
_lint_gen_dir = "$target_gen_dir/$target_name"
script = "//build/android/gyp/lint.py"
depfile = "$target_gen_dir/$target_name.d"
inputs = [
_lint_path,
_platform_xml_path,
_lint_binary_path,
_suppressions_file,
]
# _result_path is also an output, but do not list it in order to avoid it
# being uploaded to swarming as part of isolates. This happens as a
# side-effect of lint targets being listed as "data_deps" in order to
# have them run concurrently with other targets.
outputs = [ _stamp_path ]
args = [
"--depfile",
rebase_path(depfile, root_build_dir),
"--lint-path",
rebase_path(_lint_path, root_build_dir),
"--lint-binary-path",
rebase_path(_lint_binary_path, root_build_dir),
"--cache-dir",
rebase_path(_cache_dir, root_build_dir),
"--platform-xml-path",
rebase_path(_platform_xml_path, root_build_dir),
"--android-sdk-version=${lint_android_sdk_version}",
"--config-path",
rebase_path(_suppressions_file, root_build_dir),
"--product-dir=.",
"--result-path",
rebase_path(_result_path, root_build_dir),
"--stamp",
rebase_path(_stamp_path, root_build_dir),
"--include-unexpected-failures",
"--lint-gen-dir",
rebase_path(_lint_gen_dir, root_build_dir),
"--android-sdk-version=${lint_android_sdk_version}",
"--min-sdk-version=$_min_sdk_version",
"--android-sdk-root",
rebase_path(lint_android_sdk_root, root_build_dir),
......@@ -941,11 +925,24 @@ if (enable_java_templates) {
args += [ "--testonly" ]
}
if (defined(invoker.manifest_package)) {
args += [ "--manifest-package=${invoker.manifest_package}" ]
}
if (java_warnings_as_errors) {
args += [ "--can-fail-build" ]
}
_stamp_path = "$target_out_dir/$target_name/build.lint.stamp"
if (defined(invoker.create_cache) && invoker.create_cache) {
args += [ "--silent" ]
# Putting the stamp file in the cache dir allows us to depend on ninja
# to create the cache dir for us.
_stamp_path = "$_cache_dir/build.lint.stamp"
} else {
inputs += [ invoker.build_config ]
deps += [ "//build/android:prepare_android_lint_cache" ]
inputs += [ invoker.build_config ]
_rebased_build_config =
rebase_path(invoker.build_config, root_build_dir)
args += [
......@@ -955,14 +952,13 @@ if (enable_java_templates) {
"--resource-sources=@FileArg($_rebased_build_config:deps_info:lint_resource_sources)",
"--resource-zips=@FileArg($_rebased_build_config:deps_info:lint_resource_zips)",
]
if (java_warnings_as_errors) {
args += [ "--can-fail-build" ]
}
}
if (defined(invoker.manifest_package)) {
args += [ "--manifest-package=${invoker.manifest_package}" ]
}
outputs = [ _stamp_path ]
args += [
"--stamp",
rebase_path(_stamp_path, root_build_dir),
]
}
}
......
......@@ -28,7 +28,6 @@
<dimen name="location_bar_action_icon_width">40dp</dimen>
<dimen name="location_bar_url_action_offset">0dp</dimen>
<dimen name="omnibox_suggestion_start_offset_without_icon">@dimen/location_bar_icon_width</dimen>
<dimen name="omnibox_suggestion_start_offset_with_icon">@dimen/omnibox_suggestion_start_offset_without_icon</dimen>
<dimen name="omnibox_suggestion_icon_area_size">40dp</dimen>
<dimen name="omnibox_suggestion_36dp_icon_margin_start">0dp</dimen>
......
......@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.toolbar.bottom;
import android.annotation.SuppressLint;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
......@@ -75,6 +76,7 @@ public class BottomControlsCoordinator {
* whether the bar should be focused, and the second is the OmniboxFocusReason.
* @param overviewModeBehaviorSupplier Supplier for the overview mode manager.
*/
@SuppressLint("CutPasteId") // Not actually cut and paste since it's View vs ViewGroup.
public BottomControlsCoordinator(ChromeFullscreenManager fullscreenManager, ViewStub stub,
ActivityTabProvider tabProvider, OnLongClickListener tabSwitcherLongclickListener,
ThemeColorProvider themeColorProvider,
......
......@@ -7,7 +7,6 @@ package org.chromium.components.browser_ui.widget;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
import android.util.LayoutDirection;
import android.view.View;
import android.view.View.MeasureSpec;
......@@ -525,7 +524,7 @@ public class WrappingLayoutTest {
ViewExpectation expectationB, ViewExpectation expectationC) {
WrappingLayoutSubclass layout = WrappingLayoutSubclass.create(
mContext, leftTopPadding, bottomRightPadding, spacing);
layout.setLayoutDirection(LayoutDirection.RTL);
layout.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
layout.addTestViews(margin);
layout.layoutAtSize(width, height, specWidth, specHeight, 0, 0);
......
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