aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornickreid <nickreid@google.com>2023-10-09 10:00:10 -0700
committerCopybara-Service <copybara-worker@google.com>2023-10-09 10:00:42 -0700
commit53879a257620503971d5474b61581aa8749fd9c3 (patch)
tree9f5972b37b974c25d7250843fb173fdf3656b439
parentaf85c80b1e10d66494b2cd84d131b11d3336a1f0 (diff)
downloadbazelbuild-kotlin-rules-53879a257620503971d5474b61581aa8749fd9c3.tar.gz
Run Android Lint iff there are files that need to be checked.
PiperOrigin-RevId: 571967677 Change-Id: Id9fc00bd965877531eb617b11677a5dba7c7360d
-rw-r--r--bazel/stubs.bzl2
-rw-r--r--copy.bara.sky2
-rw-r--r--kotlin/common.bzl7
-rw-r--r--kotlin/jvm_compile.bzl3
-rw-r--r--tests/analysis/jvm_library_test.bzl48
5 files changed, 51 insertions, 11 deletions
diff --git a/bazel/stubs.bzl b/bazel/stubs.bzl
index 33e6d9e..b0e857a 100644
--- a/bazel/stubs.bzl
+++ b/bazel/stubs.bzl
@@ -25,6 +25,8 @@ is_forbidden_dep = _empty_fn
is_exempt_dep = _empty_fn
+is_android_lint_exempt = _empty_fn
+
DEFAULT_BUILTIN_PROCESSORS = [
"com.google.android.apps.play.store.plugins.injectionentrypoint.InjectionEntryPointProcessor",
"com.google.android.apps.play.store.plugins.interfaceaggregator.InterfaceAggregationProcessor",
diff --git a/copy.bara.sky b/copy.bara.sky
index 13546c4..766f63b 100644
--- a/copy.bara.sky
+++ b/copy.bara.sky
@@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-1486640829 \ No newline at end of file
+994712279 \ No newline at end of file
diff --git a/kotlin/common.bzl b/kotlin/common.bzl
index 23ddd41..27097aa 100644
--- a/kotlin/common.bzl
+++ b/kotlin/common.bzl
@@ -15,8 +15,6 @@
"""Common Kotlin definitions."""
load("//:visibility.bzl", "RULES_DEFS_THAT_COMPILE_KOTLIN")
-
-# go/keep-sorted start
load("//kotlin/jvm/internal_do_not_use/util:file_factory.bzl", "FileFactory")
load("//kotlin/jvm/internal_do_not_use/util:srcjars.bzl", "kt_srcjars")
load("//toolchains/kotlin_jvm:androidlint_toolchains.bzl", "androidlint_toolchains")
@@ -24,8 +22,8 @@ load("//toolchains/kotlin_jvm:kt_jvm_toolchains.bzl", "kt_jvm_toolchains")
load("@bazel_skylib//lib:sets.bzl", "sets")
load("//bazel:stubs.bzl", "lint_actions")
load("//bazel:stubs.bzl", "jspecify_flags")
+load("//bazel:stubs.bzl", "is_android_lint_exempt")
load("//bazel:stubs.bzl", "BASE_JVMOPTS")
-# go/keep-sorted end
# TODO: Remove the _ALLOWED_*_RULES lists to determine which rules
# are accepted dependencies to Kotlin rules as the approach does not scale
@@ -504,7 +502,6 @@ def _kt_jvm_library(
common_srcs = [],
coverage_srcs = [],
java_android_lint_config = None,
- force_android_lint = False, # TODO Remove this param
manifest = None, # set for Android libs, otherwise None.
merged_manifest = None, # set for Android libs, otherwise None.
resource_files = [], # set for Android libs, otherwise empty.
@@ -718,7 +715,7 @@ def _kt_jvm_library(
# TODO: Remove the is_android_library_without_kt_srcs condition once KtAndroidLint
# uses the same lint checks with AndroidLint
- if force_android_lint or not is_android_library_without_kt_srcs:
+ if (srcs or common_srcs or resource_files) and not is_android_lint_exempt(ctx):
lint_flags = [
"--java-language-level", # b/159950410
kt_toolchain.java_language_version,
diff --git a/kotlin/jvm_compile.bzl b/kotlin/jvm_compile.bzl
index a0f3f4e..46a46af 100644
--- a/kotlin/jvm_compile.bzl
+++ b/kotlin/jvm_compile.bzl
@@ -39,7 +39,6 @@ def kt_jvm_compile(
resource_files,
exported_plugins,
java_android_lint_config = None,
- force_android_lint = False, # TODO Remove this param
manifest = None,
merged_manifest = None,
classpath_resources = [],
@@ -75,7 +74,6 @@ def kt_jvm_compile(
resource_files: List of Files. The list of Android Resource files.
exported_plugins: List of exported javac/kotlinc plugins
java_android_lint_config: Android Lint XML config file to use if there are no Kotlin srcs
- force_android_lint: Force AndroidLint action
manifest: A File. The raw Android manifest. Optional.
merged_manifest: A File. The merged Android manifest. Optional.
classpath_resources: List of Files. The list of classpath resources (kt_jvm_library only).
@@ -187,7 +185,6 @@ def kt_jvm_compile(
),
),
java_android_lint_config = java_android_lint_config,
- force_android_lint = force_android_lint,
resource_files = resource_files,
runtime_deps = [d[JavaInfo] for d in runtime_deps if JavaInfo in d],
srcs = srcs,
diff --git a/tests/analysis/jvm_library_test.bzl b/tests/analysis/jvm_library_test.bzl
index 1627c5f..c72aff0 100644
--- a/tests/analysis/jvm_library_test.bzl
+++ b/tests/analysis/jvm_library_test.bzl
@@ -93,6 +93,21 @@ def _test_impl(ctx):
"Mismatch: Expected transitive_runtime_jars iff (neverlink == False)",
)
+ for mnemonic in ctx.attr.required_mnemonics:
+ if mnemonic.startswith("-"):
+ mnemonic = mnemonic.removeprefix("-")
+ asserts.false(
+ env,
+ mnemonic in [a.mnemonic for a in actions],
+ "Found action with forbidden mnemonic " + mnemonic,
+ )
+ else:
+ asserts.true(
+ env,
+ mnemonic in [a.mnemonic for a in actions],
+ "Missing action with required mnemonic " + mnemonic,
+ )
+
return analysistest.end(env)
_test = analysistest.make(
@@ -124,8 +139,16 @@ _test = analysistest.make(
doc = "Names of all runfiles",
default = _DEFAULT_LIST,
),
+ expect_jdeps = attr.bool(default = True),
expect_processor_classpath = attr.bool(),
expect_neverlink = attr.bool(),
+ required_mnemonics = attr.string_list(
+ doc = """
+ Mnemonics that must be registered (or must not be, if starting with '-').
+
+ No assertions are made about mnemonics absent from this list.
+ """,
+ ),
),
)
@@ -581,11 +604,31 @@ def _test_kt_jvm_library_with_no_sources():
"nobuilder",
],
)
- tut_label = str(Label("//tests/analysis:kt_jvm_library_with_no_sources_test_tut"))
assert_failure_test(
name = test_name,
target_under_test = test_name + "_tut",
- msg_contains = "One of {srcs, common_srcs, exports, exported_plugins} of target " + tut_label + " must be non empty",
+ msg_contains = "One of {srcs, common_srcs, exports, exported_plugins} of target ",
+ )
+ return test_name
+
+def _test_kt_jvm_library_with_no_sources_with_exports():
+ test_name = "kt_jvm_library_with_no_sources_test_with_exports"
+
+ kt_jvm_library(
+ name = test_name + "_exp",
+ srcs = ["testinputs/Foo.java"],
+ tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
+ )
+ kt_jvm_library(
+ name = test_name + "_tut",
+ tags = ONLY_FOR_ANALYSIS_TEST_TAGS,
+ exports = [test_name + "_exp"],
+ )
+ _test(
+ name = test_name,
+ target_under_test = test_name + "_tut",
+ expect_jdeps = False,
+ required_mnemonics = ["-KtAndroidLint"],
)
return test_name
@@ -655,6 +698,7 @@ def test_suite(name):
_test_kt_jvm_library_with_plugin(),
_test_kt_jvm_library_with_proguard_specs(),
_test_kt_jvm_library_with_resources(),
+ _test_kt_jvm_library_with_no_sources_with_exports(),
_test_kt_jvm_library_coverage(),
],
)