Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ maven_test.install(
artifacts = [
"org.assertj:assertj-core:3.24.2",
"junit:junit:4.13.2",
# Custom lint check used as a test fixture by //tests/scripts
"com.slack.lint.compose:compose-lint-checks:1.5.2",
],
lock_file = "//:maven_install_test.json",
repositories = [
Expand Down
55 changes: 52 additions & 3 deletions maven_install_test.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
{
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
"__INPUT_ARTIFACTS_HASH": 278678914,
"__RESOLVED_ARTIFACTS_HASH": 428393146,
"__INPUT_ARTIFACTS_HASH": 1988574746,
"__RESOLVED_ARTIFACTS_HASH": -626215935,
"artifacts": {
"com.google.auto.service:auto-service-annotations": {
"shasums": {
"jar": "16a76dd00a2650568447f5d6e3a9e2c809d9a42367d56b45215cfb89731f4d24"
},
"version": "1.1.1"
},
"com.slack.lint.compose:compose-lint-checks": {
"shasums": {
"jar": "1ad367bbf4794c3b2f90420bc3dc97ba9a7fbbe5f7a4f995811071daca44bb0b"
},
"version": "1.5.2"
},
"junit:junit": {
"shasums": {
"jar": "8e495b634469d64fb8acfa3495a065cbacc8a0fff55ce1e31007be4c16dc57d3"
Expand All @@ -29,6 +41,9 @@
}
},
"dependencies": {
"com.slack.lint.compose:compose-lint-checks": [
"com.google.auto.service:auto-service-annotations"
],
"junit:junit": [
"org.hamcrest:hamcrest-core"
],
Expand All @@ -37,6 +52,27 @@
]
},
"packages": {
"com.google.auto.service:auto-service-annotations": [
"com.google.auto.service"
],
"com.slack.lint.compose:compose-lint-checks": [
"slack.lint.compose",
"slack.lint.compose.shaded.kotlin.metadata",
"slack.lint.compose.shaded.kotlin.metadata.internal",
"slack.lint.compose.shaded.kotlin.metadata.internal.common",
"slack.lint.compose.shaded.kotlin.metadata.internal.extensions",
"slack.lint.compose.shaded.kotlin.metadata.internal.metadata",
"slack.lint.compose.shaded.kotlin.metadata.internal.metadata.builtins",
"slack.lint.compose.shaded.kotlin.metadata.internal.metadata.deserialization",
"slack.lint.compose.shaded.kotlin.metadata.internal.metadata.jvm",
"slack.lint.compose.shaded.kotlin.metadata.internal.metadata.jvm.deserialization",
"slack.lint.compose.shaded.kotlin.metadata.internal.metadata.jvm.serialization",
"slack.lint.compose.shaded.kotlin.metadata.internal.metadata.serialization",
"slack.lint.compose.shaded.kotlin.metadata.internal.protobuf",
"slack.lint.compose.shaded.kotlin.metadata.jvm",
"slack.lint.compose.shaded.kotlin.metadata.jvm.internal",
"slack.lint.compose.util"
],
"junit:junit": [
"junit.extensions",
"junit.framework",
Expand Down Expand Up @@ -148,18 +184,31 @@
},
"repositories": {
"https://maven.google.com/": [
"com.google.auto.service:auto-service-annotations",
"com.slack.lint.compose:compose-lint-checks",
"junit:junit",
"net.bytebuddy:byte-buddy",
"org.assertj:assertj-core",
"org.hamcrest:hamcrest-core"
],
"https://repo1.maven.org/maven2/": [
"com.google.auto.service:auto-service-annotations",
"com.slack.lint.compose:compose-lint-checks",
"junit:junit",
"net.bytebuddy:byte-buddy",
"org.assertj:assertj-core",
"org.hamcrest:hamcrest-core"
]
},
"services": {},
"services": {
"com.slack.lint.compose:compose-lint-checks": {
"com.android.tools.lint.client.api.IssueRegistry": [
"slack.lint.compose.ComposeLintsIssueRegistry"
],
"slack.lint.compose.shaded.kotlin.metadata.internal.extensions.MetadataExtensions": [
"slack.lint.compose.shaded.kotlin.metadata.jvm.internal.JvmMetadataExtensions"
]
}
},
"version": "2"
}
2 changes: 1 addition & 1 deletion src/cli/AndroidLintRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class AndroidLintRunner(
val aarLintRuleJars =
args.classpathAarPairs
.asSequence()
.map { it.first.resolve("lint.jar") }
.map { it.second.resolve("lint.jar") }

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an actual bug

.filter { it.exists() && it.isRegularFile() }

// Create the project configuration file for lint
Expand Down
25 changes: 25 additions & 0 deletions tests/scripts/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ load("@bazel_binaries//:defs.bzl", "bazel_binaries")
load("@rules_bazel_integration_test//bazel_integration_test:defs.bzl", "script_test")
load("@rules_shell//shell:sh_library.bzl", "sh_library")

# Copies the compose-lint-checks jar to a stable runfiles path so the helper can
# rlocation it without depending on rules_jvm_external's repository layout.
genrule(
name = "compose_lint_checks_jar",
testonly = True,
srcs = ["@rules_android_lint_test_deps//:com_slack_lint_compose_compose_lint_checks"],
outs = ["compose_lint_checks.jar"],
cmd = "cp $$(echo '$(SRCS)' | tr ' ' '\\n' | grep 'compose-lint-checks' | head -1) $@",
)

sh_library(
name = "lint_helper",
testonly = True,
srcs = ["lint_helper.sh"],
data = [
":compose_lint_checks_jar",
"//rules:all_files",
"//src:all_files",
"//src/cli:cli_deploy.jar",
Expand All @@ -27,3 +38,17 @@ script_test(
"//tests/bashunit",
],
)

script_test(
name = "android_lint_aar_scenarios_test",
size = "enormous",
srcs = ["android_lint_aar_scenarios_test.sh"],
additional_env_inherit = ["ANDROID_HOME"],
bazel_binaries = bazel_binaries,
bazel_version = bazel_binaries.versions.current,
tags = ["exclusive"],
deps = [
":lint_helper",
"//tests/bashunit",
],
)
50 changes: 50 additions & 0 deletions tests/scripts/android_lint_aar_scenarios_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/bin/bash
#
# Scenarios for custom lint checks embedded in AAR dependencies (lint.jar), exercising the
# collect_aar_outputs_aspect extraction and auto-discovery path. Requires ANDROID_HOME.

# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2.
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v2 ---

source "$(rlocation rules_android_lint/tests/bashunit/unittest.bash)" || \
(echo >&2 "Failed to locate unittest.bash" && exit 1)

source "$(rlocation rules_android_lint/tests/scripts/lint_helper.sh)" || \
(echo >&2 "Failed to locate lint_helper.sh" && exit 1)

function set_up() {
rm -rf -- * .bazelrc 2>/dev/null || true
set_up_lint_workspace
enable_android_in_workspace
}

function test_aar_embedded_lint_jar_flags_issue() {
write_composable_annotation_stub
write_dirty_composable
write_fixture_aar
write_aar_dep_lint_targets

"${BIT_BAZEL_BINARY}" test --test_output=all //:lib_lint_test >& "$TEST_log" \
&& fail "Expected lint test with AAR-embedded checks to fail" || true
expect_log "ComposeNamingUppercase"
}

function test_aar_embedded_lint_jar_accepts_clean_composable() {
write_composable_annotation_stub
write_clean_composable
write_fixture_aar
write_aar_dep_lint_targets

"${BIT_BAZEL_BINARY}" test --test_output=all //:lib_lint_test >& "$TEST_log" \
|| fail "Expected lint test with AAR-embedded checks to pass"
}

run_suite "android_lint AAR lint.jar discovery scenarios"
21 changes: 21 additions & 0 deletions tests/scripts/android_lint_scenarios_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,25 @@ function test_worker_and_local_strategies_agree() {
expect_log "DefaultLocale"
}

function test_custom_rules_jar_flags_compose_issue() {
write_composable_annotation_stub
write_dirty_composable
copy_compose_lint_checks
write_custom_rules_lint_targets

"${BIT_BAZEL_BINARY}" test --test_output=all //:lib_lint_test >& "$TEST_log" \
&& fail "Expected lint test with custom compose-lints rules to fail" || true
expect_log "ComposeNamingUppercase"
}

function test_custom_rules_jar_accepts_clean_composable() {
write_composable_annotation_stub
write_clean_composable
copy_compose_lint_checks
write_custom_rules_lint_targets

"${BIT_BAZEL_BINARY}" test --test_output=all //:lib_lint_test >& "$TEST_log" \
|| fail "Expected lint test with custom compose-lints rules to pass"
}

run_suite "android_lint rule behavior scenarios"
Loading
Loading