Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an ability to exclude files from final binary produces by android_application #100

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion rules/android_application/android_application_rule.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,24 @@ def _impl(ctx):
metadata["com.google.play.apps.integrity/AppIntegrityConfig.pb"] = ctx.file.app_integrity_config

# Create .aab
base_aab = ctx.actions.declare_file("base_aab")
_bundletool.build(
ctx,
out = ctx.outputs.unsigned_aab,
out = base_aab,
modules = modules,
config = ctx.file.bundle_config_file,
metadata = metadata,
bundletool = get_android_toolchain(ctx).bundletool.files_to_run,
host_javabase = _common.get_host_javabase(ctx),
)

_common.filter_zip_exclude(
ctx = ctx,
input = base_aab,
output = ctx.outputs.unsigned_aab,
filters = ctx.attr.excludes,
)

# Create `blaze run` script
base_apk_info = ctx.attr.base_module[ApkInfo]
deploy_script_files = [base_apk_info.signing_keys[-1]]
Expand Down Expand Up @@ -380,6 +388,9 @@ def android_application_macro(_android_binary, **attrs):
module_targets = get_feature_module_paths(feature_module)
attrs["deps"].append(str(module_targets.title_lib))

# only supported in android_application rule
excludes = attrs.pop("excludes", [])

_android_binary(
name = base_split_name,
**attrs
Expand All @@ -397,4 +408,5 @@ def android_application_macro(_android_binary, **attrs):
feature_modules = feature_modules,
application_id = attrs["manifest_values"]["applicationId"],
visibility = attrs.get("visibility", None),
excludes = excludes,
)
4 changes: 4 additions & 0 deletions rules/android_application/attrs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ ANDROID_APPLICATION_ATTRS = _attrs.add(
),
custom_package = attr.string(),
feature_modules = attr.label_list(allow_files = False),
excludes = attr.string_list(
doc = "List of regex file patterns to exclude from the final binary. If you use excludes, make sure that" +
" you do not utilise any code path requiring the excluded dependency by sufficient test coverage."
),
_bundle_deploy = attr.label(
allow_single_file = True,
default = ":bundle_deploy.sh_template",
Expand Down