FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Support disable_lint_checks in java_library · bazelbuild/rules_java@7b13ead · GitHub

Repository navigation

Commit 7b13ead

Browse files
authored andcommitted
Support disable_lint_checks in java_library
PiperOrigin-RevId: 901279874 Change-Id: Icfebb038e6974b6d9dfc091cfd9e88a27de6aa68
1 parent 2399899 commit 7b13ead

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎java/common/rules/android_lint.bzl‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,18 @@ def _tokenize_opts(opts_depset):
2222
opts = reversed(opts_depset.to_list())
2323
return semantics.tokenize_javacopts(opts)
2424

25-
def _android_lint_action(ctx, source_files, source_jars, compilation_info, is_library):
25+
def _flags_from_disable_lint_checks(args, disable_lint_checks):
26+
invalid_ids = [check for check in disable_lint_checks if not _check_id_is_valid(check)]
27+
if invalid_ids:
28+
fail("Found not allowed character in disabled check ID(s) %s" % str(invalid_ids))
29+
args.add_joined("--disable", disable_lint_checks, join_with = ",")
30+
31+
# Returns whether the passed Android Lint check ID is valid
32+
def _check_id_is_valid(check):
33+
# We want to prevent whitespace so that extra flags can't be 'injected' into Android Lint
34+
return check.replace(".", "").replace("_", "").isalnum()
35+
36+
def _android_lint_action(ctx, source_files, source_jars, compilation_info, is_library, disable_lint_checks = []):
2637
"""
2738
Creates an action that runs Android lint against Java source files.
2839
@@ -43,6 +54,7 @@ def _android_lint_action(ctx, source_files, source_jars, compilation_info, is_li
4354
source files. It should also include generated source jars.
4455
compilation_info: (struct) Information about compilation.
4556
is_library: (bool) Whether the target is a library.
57+
disable_lint_checks: (list[str]) A list of AndroidLint checks to be skipped.
4658
4759
Returns:
4860
(None|File) The Android lint output file or None if no source files were
@@ -112,6 +124,7 @@ def _android_lint_action(ctx, source_files, source_jars, compilation_info, is_li
112124

113125
args.add("--lintopts")
114126
args.add_all(linter.lint_opts)
127+
_flags_from_disable_lint_checks(args, disable_lint_checks)
115128

116129
for package_config in linter.package_config:
117130
if package_config.matches(package_config.package_specs, ctx.label):

‎java/common/rules/impl/basic_java_library_impl.bzl‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ def basic_java_library(
7272
add_opens = [],
7373
bootclasspath = None,
7474
javabuilder_jvm_flags = None,
75-
is_library = True):
75+
is_library = True,
76+
disable_lint_checks = []):
7677
"""
7778
Creates actions that compile and lint Java sources, sets up coverage and returns JavaInfo, InstrumentedFilesInfo and output groups.
7879
@@ -109,6 +110,7 @@ def basic_java_library(
109110
bootclasspath: (Target) The JDK APIs to compile this library against.
110111
javabuilder_jvm_flags: (list[str]) Additional JVM flags to pass to JavaBuilder.
111112
is_library: (bool) Whether the target is a library. Primarily for static analysis purposes.
113+
disable_lint_checks: (list[str]) A list of AndroidLint checks to be skipped.
112114
Returns:
113115
(dict[str, Provider],
114116
{files_to_build: list[File],
@@ -172,6 +174,7 @@ def basic_java_library(
172174
source_jars + generated_source_jars,
173175
compilation_info,
174176
is_library,
177+
disable_lint_checks,
175178
)
176179
if lint_output:
177180
validation_outputs.append(depset([lint_output]))

‎java/common/rules/impl/bazel_java_library_impl.bzl‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def bazel_java_library_rule(
3535
add_exports = [],
3636
add_opens = [],
3737
bootclasspath = None,
38-
javabuilder_jvm_flags = None):
38+
javabuilder_jvm_flags = None,
39+
disable_lint_checks = []):
3940
"""Implements java_library.
4041
4142
Use this call when you need to produce a fully fledged java_library from
@@ -58,6 +59,7 @@ def bazel_java_library_rule(
5859
add_opens: (list[str]) Allow this library to reflectively access the given <module>/<package>.
5960
bootclasspath: (Target) The JDK APIs to compile this library against.
6061
javabuilder_jvm_flags: (list[str]) Additional JVM flags to pass to JavaBuilder.
62+
disable_lint_checks: (list[str]) A list of AndroidLint checks to be skipped.
6163
Returns:
6264
(dict[str, provider]) A list containing DefaultInfo, JavaInfo,
6365
InstrumentedFilesInfo, OutputGroupsInfo, ProguardSpecProvider providers.
@@ -83,6 +85,7 @@ def bazel_java_library_rule(
8385
add_opens = add_opens,
8486
bootclasspath = bootclasspath,
8587
javabuilder_jvm_flags = javabuilder_jvm_flags,
88+
disable_lint_checks = disable_lint_checks,
8689
)
8790

8891
target["DefaultInfo"] = construct_defaultinfo(

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL