Skip to content

Commit

Permalink
Move instrumentation rules to rules/defs.bzl (#116)
Browse files Browse the repository at this point in the history
Fixes #116
  • Loading branch information
arunkumar9t2 committed Oct 19, 2023
1 parent d5dd9cd commit 5d70380
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 37 deletions.
Empty file removed android/test/BUILD.bazel
Empty file.
6 changes: 0 additions & 6 deletions android/test/instrumentation.bzl

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@grab_bazel_common//tools/kotlin:android.bzl", "kt_android_library")
load("@grab_bazel_common//rules/android/private:test_manifest.bzl", "generate_manifest_xml")

def android_instrumentation_binary(
name,
Expand Down Expand Up @@ -30,7 +31,7 @@ def android_instrumentation_binary(
package_name = manifest_values["applicationId"]

test_manifest = name + "_manifest"
_generate_manifest_xml(
generate_manifest_xml(
name = test_manifest,
output = name + ".AndroidTestManifest.xml",
package_name = package_name,
Expand All @@ -39,6 +40,8 @@ def android_instrumentation_binary(
)

android_library_name = name + "_lib"

# TODO: Migrate to android_library
kt_android_library(
name = android_library_name,
srcs = srcs,
Expand All @@ -56,6 +59,7 @@ def android_instrumentation_binary(
deps = deps,
)

# TODO: Migrate to android_library
native.android_binary(
name = name,
instruments = instruments,
Expand All @@ -71,32 +75,3 @@ def android_instrumentation_binary(
deps = [android_library_name],
**kwargs
)

def _generate_manifest_xml_impl(ctx):
ctx.actions.expand_template(
template = ctx.file._template,
output = ctx.outputs.output,
substitutions = {
"{{.PACKAGE_NAME}}": ctx.attr.package_name,
"{{.TARGET_PACKAGE_NAME}}": ctx.attr.target_package_name,
"{{.INSTRUMENTATION_RUNNER}}": ctx.attr.test_instrumentation_runner,
},
)
return [
DefaultInfo(files = depset([ctx.outputs.output])),
]

_generate_manifest_xml = rule(
implementation = _generate_manifest_xml_impl,
attrs = {
"package_name": attr.string(mandatory = True),
"target_package_name": attr.string(mandatory = True),
"test_instrumentation_runner": attr.string(mandatory = True),
"output": attr.output(mandatory = True),
"_template": attr.label(
doc = "Android Test Manifest template",
default = ":AndroidTestManifest.xml.tpl",
allow_single_file = True,
),
},
)
1 change: 1 addition & 0 deletions rules/android/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exports_files(["AndroidTestManifest.xml.tpl"])
28 changes: 28 additions & 0 deletions rules/android/private/test_manifest.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
def _generate_manifest_xml_impl(ctx):
ctx.actions.expand_template(
template = ctx.file._template,
output = ctx.outputs.output,
substitutions = {
"{{.PACKAGE_NAME}}": ctx.attr.package_name,
"{{.TARGET_PACKAGE_NAME}}": ctx.attr.target_package_name,
"{{.INSTRUMENTATION_RUNNER}}": ctx.attr.test_instrumentation_runner,
},
)
return [
DefaultInfo(files = depset([ctx.outputs.output])),
]

generate_manifest_xml = rule(
implementation = _generate_manifest_xml_impl,
attrs = {
"package_name": attr.string(mandatory = True),
"target_package_name": attr.string(mandatory = True),
"test_instrumentation_runner": attr.string(mandatory = True),
"output": attr.output(mandatory = True),
"_template": attr.label(
doc = "Android Test Manifest template",
default = ":AndroidTestManifest.xml.tpl",
allow_single_file = True,
),
},
)
2 changes: 2 additions & 0 deletions rules/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@grab_bazel_common//rules/android:android_binary.bzl", _android_binary = "android_binary")
load("@grab_bazel_common//rules/android:android_library.bzl", _android_library = "android_library")
load("@grab_bazel_common//rules/android:android_instrumentation.bzl", _android_instrumentation_binary = "android_instrumentation_binary")
load(
"@grab_bazel_common//rules/kotlin:kotlin.bzl",
_kt_compiler_plugin = "kt_compiler_plugin",
Expand All @@ -9,6 +10,7 @@ load(
# Android
android_binary = _android_binary
android_library = _android_library
android_instrumentation_binary = _android_instrumentation_binary

# Kotlin
kt_jvm_library = _kt_jvm_library
Expand Down
1 change: 0 additions & 1 deletion src/main/starlark/test/BUILD.bazel

This file was deleted.

0 comments on commit 5d70380

Please sign in to comment.