| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2399899 commit 7b13ead
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,18 @@ def _tokenize_opts(opts_depset): | |||
| 22 | 22 | opts = reversed(opts_depset.to_list()) | |
| 23 | 23 | return semantics.tokenize_javacopts(opts) | |
| 24 | 24 | ||
| 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 = []): | ||
| 26 | 37 | """ | |
| 27 | 38 | Creates an action that runs Android lint against Java source files. | |
| 28 | 39 | ||
@@ -43,6 +54,7 @@ def _android_lint_action(ctx, source_files, source_jars, compilation_info, is_li | |||
| 43 | 54 | source files. It should also include generated source jars. | |
| 44 | 55 | compilation_info: (struct) Information about compilation. | |
| 45 | 56 | is_library: (bool) Whether the target is a library. | |
| 57 | + disable_lint_checks: (list[str]) A list of AndroidLint checks to be skipped. | ||
| 46 | 58 | ||
| 47 | 59 | Returns: | |
| 48 | 60 | (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 | |||
| 112 | 124 | ||
| 113 | 125 | args.add("--lintopts") | |
| 114 | 126 | args.add_all(linter.lint_opts) | |
| 127 | + _flags_from_disable_lint_checks(args, disable_lint_checks) | ||
| 115 | 128 | ||
| 116 | 129 | for package_config in linter.package_config: | |
| 117 | 130 | if package_config.matches(package_config.package_specs, ctx.label): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -72,7 +72,8 @@ def basic_java_library( | |||
| 72 | 72 | add_opens = [], | |
| 73 | 73 | bootclasspath = None, | |
| 74 | 74 | javabuilder_jvm_flags = None, | |
| 75 | - is_library = True): | ||
| 75 | + is_library = True, | ||
| 76 | + disable_lint_checks = []): | ||
| 76 | 77 | """ | |
| 77 | 78 | Creates actions that compile and lint Java sources, sets up coverage and returns JavaInfo, InstrumentedFilesInfo and output groups. | |
| 78 | 79 | ||
@@ -109,6 +110,7 @@ def basic_java_library( | |||
| 109 | 110 | bootclasspath: (Target) The JDK APIs to compile this library against. | |
| 110 | 111 | javabuilder_jvm_flags: (list[str]) Additional JVM flags to pass to JavaBuilder. | |
| 111 | 112 | 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. | ||
| 112 | 114 | Returns: | |
| 113 | 115 | (dict[str, Provider], | |
| 114 | 116 | {files_to_build: list[File], | |
@@ -172,6 +174,7 @@ def basic_java_library( | |||
| 172 | 174 | source_jars + generated_source_jars, | |
| 173 | 175 | compilation_info, | |
| 174 | 176 | is_library, | |
| 177 | + disable_lint_checks, | ||
| 175 | 178 | ) | |
| 176 | 179 | if lint_output: | |
| 177 | 180 | validation_outputs.append(depset([lint_output])) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,7 +35,8 @@ def bazel_java_library_rule( | |||
| 35 | 35 | add_exports = [], | |
| 36 | 36 | add_opens = [], | |
| 37 | 37 | bootclasspath = None, | |
| 38 | - javabuilder_jvm_flags = None): | ||
| 38 | + javabuilder_jvm_flags = None, | ||
| 39 | + disable_lint_checks = []): | ||
| 39 | 40 | """Implements java_library. | |
| 40 | 41 | ||
| 41 | 42 | Use this call when you need to produce a fully fledged java_library from | |
@@ -58,6 +59,7 @@ def bazel_java_library_rule( | |||
| 58 | 59 | add_opens: (list[str]) Allow this library to reflectively access the given <module>/<package>. | |
| 59 | 60 | bootclasspath: (Target) The JDK APIs to compile this library against. | |
| 60 | 61 | 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. | ||
| 61 | 63 | Returns: | |
| 62 | 64 | (dict[str, provider]) A list containing DefaultInfo, JavaInfo, | |
| 63 | 65 | InstrumentedFilesInfo, OutputGroupsInfo, ProguardSpecProvider providers. | |
@@ -83,6 +85,7 @@ def bazel_java_library_rule( | |||
| 83 | 85 | add_opens = add_opens, | |
| 84 | 86 | bootclasspath = bootclasspath, | |
| 85 | 87 | javabuilder_jvm_flags = javabuilder_jvm_flags, | |
| 88 | + disable_lint_checks = disable_lint_checks, | ||
| 86 | 89 | ) | |
| 87 | 90 | ||
| 88 | 91 | target["DefaultInfo"] = construct_defaultinfo( | |
| Back | FazBrowse Home | New Git URL |
0 commit comments