Skip to content

Commit

Permalink
Integrate with rules_android_lint
Browse files Browse the repository at this point in the history
  • Loading branch information
arunkumar9t2 committed Dec 6, 2023
1 parent 69cbd1c commit 5271580
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ build --experimental_android_databinding_v2
build --android_databinding_use_v3_4_args
build --android_databinding_use_androidx

build --experimental_google_legacy_api
query --experimental_google_legacy_api
common --experimental_google_legacy_api

common --strategy=AndroidLint=sandboxed

Expand Down
9 changes: 9 additions & 0 deletions rules/android/android_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@grab_bazel_common//tools/res_value:res_value.bzl", "res_value")
load("@grab_bazel_common//tools/kotlin:android.bzl", "kt_android_library")
load("@grab_bazel_common//rules/android/databinding:databinding.bzl", "DATABINDING_DEPS")
load("@grab_bazel_common//rules/android/lint:defs.bzl", "lint_sources", "lint_test")
load("@rules_android_lint//rules:defs.bzl", "android_lint_test")
load(":resources.bzl", "build_resources")

"""Enhanced android_binary rule with support for build configs, res values, Kotlin compilation and databinding support"""
Expand Down Expand Up @@ -103,3 +104,11 @@ def android_binary(
name = name + ".lint",
target = name,
)

android_lint_test(
name = name + "_lint_test",
srcs = attrs.get("srcs", default = []),
resource_files = [file for file in resource_files if file.endswith(".xml")],
lib = name,
deps = android_binary_deps,
)
11 changes: 10 additions & 1 deletion rules/android/android_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ load("@grab_bazel_common//tools/build_config:build_config.bzl", _build_config =
load("@grab_bazel_common//tools/res_value:res_value.bzl", "res_value")
load("@grab_bazel_common//tools/kotlin:android.bzl", "kt_android_library")
load("@grab_bazel_common//rules/android/databinding:databinding.bzl", "kt_db_android_library")
load(":resources.bzl", "build_resources")
load("@grab_bazel_common//rules/android/lint:defs.bzl", "lint_sources", "lint_test")
load("@rules_android_lint//rules:defs.bzl", "android_lint_test")
load(":resources.bzl", "build_resources")

"""Enhanced android_library rule with support for build configs, res values, Kotlin compilation and databinding support"""

Expand Down Expand Up @@ -94,3 +95,11 @@ def android_library(
name = name + ".lint",
target = name,
)

android_lint_test(
name = name + "_lint_test",
srcs = attrs.get("srcs", default = []),
resource_files = [file for file in resource_files if file.endswith(".xml")],
lib = name,
deps = android_library_deps,
)
3 changes: 3 additions & 0 deletions rules/android/resources.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ def build_resources(
return merged_resources + generated_resources
else:
return resource_files + generated_resources

def resources_xml(resource_files):
return [file for file in resource_files if file.endswith(".xml")]
17 changes: 17 additions & 0 deletions rules/repositories.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

def http_archive(name, **kwargs):
maybe(_http_archive, name = name, **kwargs)
Expand Down Expand Up @@ -66,7 +67,23 @@ def _proto():
],
)

def _lint():
git_repository(
name = "rules_android_lint",
commit = "012f2b1b0a8ffcad878111d6e2e8b903bc29f985",
remote = "https://github.com/Bencodes/rules_android_lint.git",
workspace_file = "@grab_bazel_common//third_party/rules_android_lint:WORKSPACE.bazelignore",
patch_cmds = [
"rm WORKSPACE.bazel",
"echo \"common --experimental_google_legacy_api\" > .bazelrc",
],
repo_mapping = {
"@rules_kotlin": "@io_bazel_rules_kotlin",
},
)

def bazel_common_dependencies():
#_proto
_maven()
_kotlin()
_lint()
27 changes: 27 additions & 0 deletions rules/setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def bazel_common_setup(
),
)

native.register_toolchains("@rules_android_lint//toolchains:android_lint_default_toolchain")

repo_name = "bazel_common_maven"
maven_install_json = "@grab_bazel_common//:%s_install.json" % repo_name if pinned_maven_install else None

Expand Down Expand Up @@ -93,5 +95,30 @@ def bazel_common_setup(
fetch_sources = True,
)

maven_install(
name = "rules_android_lint_deps",
artifacts = [
# Testing
"org.assertj:assertj-core:3.24.2",
"junit:junit:4.13.2",
# Worker Dependencies
"com.squareup.moshi:moshi:1.15.0",
"com.squareup.moshi:moshi-kotlin:1.15.0",
"com.squareup.okio:okio-jvm:3.6.0",
"io.reactivex.rxjava3:rxjava:3.1.8",
"com.xenomachina:kotlin-argparser:2.0.7",
# Lint Dependencies
"com.android.tools.lint:lint:31.3.0-alpha09",
"com.android.tools.lint:lint-api:31.3.0-alpha09",
"com.android.tools.lint:lint-checks:31.3.0-alpha09",
"com.android.tools.lint:lint-model:31.3.0-alpha09",
],
#maven_install_json = "@rules_android_lint//:maven_install.json",
repositories = [
"https://maven.google.com",
"https://repo1.maven.org/maven2",
],
)

_android(patched_android_tools)
_kotlin()
Empty file.
164 changes: 164 additions & 0 deletions third_party/rules_android_lint/WORKSPACE.bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
workspace(name = "rules_android_lint")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "cgrindel_bazel_starlib",
sha256 = "9090280a9cff7322e7c22062506b3273a2e880ca464e520b5c77fdfbed4e8805",
urls = [
"https://github.com/cgrindel/bazel-starlib/releases/download/v0.18.1/bazel-starlib.v0.18.1.tar.gz",
],
)

load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies")

bazel_starlib_dependencies()

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

http_archive(
name = "rules_java",
sha256 = "e81e9deaae0d9d99ef3dd5f6c1b32338447fe16d5564155531ea4eb7ef38854b",
urls = [
"https://github.com/bazelbuild/rules_java/releases/download/7.0.6/rules_java-7.0.6.tar.gz",
],
)

http_archive(
name = "rules_proto",
sha256 = "e017528fd1c91c5a33f15493e3a398181a9e821a804eb7ff5acdd1d2d6c2b18d",
strip_prefix = "rules_proto-4.0.0-3.20.0",
urls = [
"https://github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0-3.20.0.tar.gz",
],
)

load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")

rules_java_dependencies()

rules_java_toolchains()
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

RULES_JVM_EXTERNAL_TAG = "5.3"
RULES_JVM_EXTERNAL_SHA ="d31e369b854322ca5098ea12c69d7175ded971435e55c18dd9dd5f29cc5249ac"

http_archive(
name = "rules_jvm_external",
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
sha256 = RULES_JVM_EXTERNAL_SHA,
url = "https://github.com/bazelbuild/rules_jvm_external/releases/download/%s/rules_jvm_external-%s.tar.gz" % (RULES_JVM_EXTERNAL_TAG, RULES_JVM_EXTERNAL_TAG)
)

load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")

rules_jvm_external_deps()

load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")

rules_jvm_external_setup()

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

rules_kotlin_version = "1.9.0"
rules_kotlin_sha = "5766f1e599acf551aa56f49dab9ab9108269b03c557496c54acaf41f98e2b8d6"
http_archive(
name = "rules_kotlin",
urls = ["https://github.com/bazelbuild/rules_kotlin/releases/download/v%s/rules_kotlin-v%s.tar.gz" % (rules_kotlin_version, rules_kotlin_version)],
sha256 = rules_kotlin_sha,
)

load("@rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories")
kotlin_repositories()

load("@rules_kotlin//kotlin:core.bzl", "kt_register_toolchains")
kt_register_toolchains()

http_archive(
name = "bazel_skylib",
sha256 = "66ffd9315665bfaafc96b52278f57c7e2dd09f5ede279ea6d39b2be471e7e3aa",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.2/bazel-skylib-1.4.2.tar.gz",
],
)

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

http_archive(
name = "platforms",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.8/platforms-0.0.8.tar.gz",
"https://github.com/bazelbuild/platforms/releases/download/0.0.8/platforms-0.0.8.tar.gz",
],
sha256 = "8150406605389ececb6da07cbcb509d5637a3ab9a24bc69b1101531367d89d74",
)

register_toolchains("//toolchains:android_lint_default_toolchain")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "aspect_bazel_lib",
sha256 = "e3151d87910f69cf1fc88755392d7c878034a69d6499b287bcfc00b1cf9bb415",
strip_prefix = "bazel-lib-1.32.1",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.32.1/bazel-lib-v1.32.1.tar.gz",
)

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")

aspect_bazel_lib_dependencies()

http_archive(
name = "buildifier_prebuilt",
sha256 = "72b5bb0853aac597cce6482ee6c62513318e7f2c0050bc7c319d75d03d8a3875",
strip_prefix = "buildifier-prebuilt-6.3.3",
urls = [
"http://github.com/keith/buildifier-prebuilt/archive/6.3.3.tar.gz",
],
)

load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")

buildifier_prebuilt_deps()

load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")

buildifier_prebuilt_register_toolchains()

load("@rules_jvm_external//:defs.bzl", "maven_install")
load("@rules_jvm_external//:specs.bzl", "maven")

maven_install(
name = "rules_android_lint_deps",
artifacts = [
# Testing
"org.assertj:assertj-core:3.24.2",
"junit:junit:4.13.2",
# Worker Dependencies
# TODO(bencodes) Remove these and use the worker impl. that Bazel defines internally
"com.squareup.moshi:moshi:1.15.0",
"com.squareup.moshi:moshi-kotlin:1.15.0",
"com.squareup.okio:okio-jvm:3.6.0",
"io.reactivex.rxjava3:rxjava:3.1.8",
"com.xenomachina:kotlin-argparser:2.0.7",
# Lint Dependencies
"com.android.tools.lint:lint:31.3.0-alpha09",
"com.android.tools.lint:lint-api:31.3.0-alpha09",
"com.android.tools.lint:lint-checks:31.3.0-alpha09",
"com.android.tools.lint:lint-model:31.3.0-alpha09",
],
#maven_install_json = "@rules_android_lint//:maven_install.json",
repositories = [
"https://maven.google.com",
"https://repo1.maven.org/maven2",
],
)

#load("@rules_android_lint_deps//:defs.bzl", rules_android_lint_deps_pinned_maven_install = "pinned_maven_install")

#rules_android_lint_deps_pinned_maven_install()

0 comments on commit 5271580

Please sign in to comment.