From 2db3d8fc28171b172c9bdafa1dffae9777f98c08 Mon Sep 17 00:00:00 2001 From: A Googler Date: Wed, 6 Nov 2024 21:23:17 -0800 Subject: [PATCH] Add optional DeviceGroupConfig.json metadata file. PiperOrigin-RevId: 693971789 Change-Id: Ifcee8975417c7aba0a31d3bf6640271c201e817d --- rules/android_application/android_application.bzl | 1 + rules/android_application/android_application_rule.bzl | 5 +++++ rules/android_application/attrs.bzl | 6 ++++++ 3 files changed, 12 insertions(+) diff --git a/rules/android_application/android_application.bzl b/rules/android_application/android_application.bzl index 156cd7468..d0dbe5ab5 100644 --- a/rules/android_application/android_application.bzl +++ b/rules/android_application/android_application.bzl @@ -42,6 +42,7 @@ def android_application(**attrs): `feature_modules` | New. List of labels to `android_feature_module`s to include as feature splits. Note: must be fully qualified paths (//some:target), not relative. `bundle_config_file` | New. String path to .pb.json file containing the bundle config. See the [bundletool docs](https://developer.android.com/studio/build/building-cmdline#bundleconfig) for format and examples. Note: this attribute is subject to changes which may require teams to migrate their configurations to a build target. `app_integrity_config` | Optional. String path to .binarypb file containing the play integrity config. See https://github.com/google/bundletool/blob/master/src/main/proto/app_integrity_config.proto. + `device_group_config` | Optional. String path to .json file containing the device targeting definitions. See https://github.com/google/bundletool/blob/master/src/main/proto/device_targeting_config.proto. `rotation_config` | Optional. String path to .textproto file containing the V3 rotation config. Args: diff --git a/rules/android_application/android_application_rule.bzl b/rules/android_application/android_application_rule.bzl index eb95f2a87..898ab0163 100644 --- a/rules/android_application/android_application_rule.bzl +++ b/rules/android_application/android_application_rule.bzl @@ -356,6 +356,9 @@ def _impl(ctx): if ProguardMappingInfo in ctx.attr.base_module: metadata["com.android.tools.build.obfuscation/proguard.map"] = ctx.attr.base_module[ProguardMappingInfo].proguard_mapping + if ctx.file.device_group_config: + metadata["com.android.tools.build.bundletool/DeviceGroupConfig.pb"] = ctx.file.device_group_config + if ctx.file.rotation_config: metadata["com.google.play.apps.signing/RotationConfig.textproto"] = ctx.file.rotation_config @@ -449,6 +452,7 @@ def android_application_macro(_android_binary, **attrs): # Must pop these because android_binary does not have these attributes. app_integrity_config = attrs.pop("app_integrity_config", None) + device_group_config = attrs.pop("device_group_config", None) rotation_config = attrs.pop("rotation_config", None) # default to [] if feature_modules = None is passed @@ -502,6 +506,7 @@ def android_application_macro(_android_binary, **attrs): base_module = ":%s" % base_split_name, bundle_config_file = bundle_config_file, app_integrity_config = app_integrity_config, + device_group_config = device_group_config, rotation_config = rotation_config, custom_package = attrs.get("custom_package", None), testonly = attrs.get("testonly"), diff --git a/rules/android_application/attrs.bzl b/rules/android_application/attrs.bzl index 51d71700c..5cd7382f6 100644 --- a/rules/android_application/attrs.bzl +++ b/rules/android_application/attrs.bzl @@ -45,6 +45,12 @@ ANDROID_APPLICATION_ATTRS = _attrs.add( "Provide a path to a binary .binarypb instance of " + "https://github.com/google/bundletool/blob/master/src/main/proto/app_integrity_config.proto", ), + device_group_config = attr.label( + allow_single_file = [".json"], + doc = "Path to the device targeting configuration json file. " + + "See " + + "https://github.com/google/bundletool/blob/master/src/main/proto/device_targeting_config.proto", + ), rotation_config = attr.label( allow_single_file = [".textproto"], default = None,