Skip to content

Commit

Permalink
Migrate instrumentation filter method from Native to Starlark
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 554947093
Change-Id: Ic7112e5a3b643c46937dc55a5e21dbfc07ad456e
  • Loading branch information
Zhaoqing Xu authored and copybara-github committed Aug 8, 2023
1 parent 51b688d commit df22114
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion rules/android_binary_internal/impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,21 @@ def _process_deploy_jar(ctx, stamp_ctx, packaged_resources_ctx, jvm_ctx, build_i
deploy_manifest_lines = build_info_ctx.deploy_manifest_lines,
)

if _is_instrumentation(ctx):
filtered_deploy_jar = ctx.actions.declare_file(ctx.label.name + "_migrated_filtered.jar")
filter_jar = ctx.attr.instruments[AndroidPreDexJarInfo].pre_dex_jar
common.filter_zip_exclude(
ctx,
output = filtered_deploy_jar,
input = deploy_jar,
filter_zips = [filter_jar],
filter_types = [".class"],
# These files are generated by databinding in both the target and the instrumentation
# app with different contents. We want to keep the one from the target app.
filters = ["/BR\\.class$", "/databinding/[^/]+Binding\\.class$"],
)
deploy_jar = filtered_deploy_jar

return ProviderInfo(
name = "deploy_ctx",
value = struct(
Expand Down Expand Up @@ -378,7 +393,19 @@ def _is_test_binary(ctx):
Returns:
Boolean indicating whether the target is a test target.
"""
return ctx.attr.testonly or ctx.attr.instruments or str(ctx.label).find("/javatests/") >= 0
return ctx.attr.testonly or _is_instrumentation(ctx) or str(ctx.label).find("/javatests/") >= 0

def _is_instrumentation(ctx):
"""Whether this android_binary target is an instrumentation binary.
Args:
ctx: The context.
Returns:
Boolean indicating whether the target is an instrumentation target.
"""
return bool(ctx.attr.instruments)

def _process_baseline_profiles(ctx, dex_ctx, **_unused_ctxs):
providers = []
Expand Down

0 comments on commit df22114

Please sign in to comment.