Handle selects in explicit profile output.

This needs a similar workaround to _generate_proguard_outputs

PiperOrigin-RevId: 846394932
Change-Id: I34160ec06feab66a19c70f2ce2e35009355806f4
diff --git a/rules/android_binary/attrs.bzl b/rules/android_binary/attrs.bzl
index 9620890..9ffed2a 100644
--- a/rules/android_binary/attrs.bzl
+++ b/rules/android_binary/attrs.bzl
@@ -197,8 +197,10 @@
             ),
             _defined_resource_files = attr.bool(default = False),
             _package_name = attr.string(),  # for sending the package name to the outputs callback
-            # This is for only generating proguard outputs when proguard_specs is not empty or of type select.
+            # For generating proguard outputs when proguard_specs is not empty or a select.
             _generate_proguard_outputs = attr.bool(),
+            # For generating art profile outputs when generate_art_profile is true or a select.
+            _generate_art_profile_outputs = attr.bool(),
             _enable_manifest_merging = attr.bool(default = True),
             _cc_toolchain_split = attr.label(
                 cfg = android_split_transition,
diff --git a/rules/android_binary/impl.bzl b/rules/android_binary/impl.bzl
index 5c84dc8..c13bec3 100644
--- a/rules/android_binary/impl.bzl
+++ b/rules/android_binary/impl.bzl
@@ -739,7 +739,7 @@
             )
             providers.append(art_profile_info)
 
-    if ctx.attr.generate_art_profile and not art_profile_info:
+    if ctx.attr._generate_art_profile_outputs and not art_profile_info:
         # There are a lot of ways baseline profiles could fail, and thus art profile generation also
         # fails. For example, if the baseline profile is not included as a dependency, if the
         # baseline profile is empty, or if you're attempting to use R8.
diff --git a/rules/android_binary/rule.bzl b/rules/android_binary/rule.bzl
index 8c6060d..7bc0cb5 100644
--- a/rules/android_binary/rule.bzl
+++ b/rules/android_binary/rule.bzl
@@ -31,7 +31,7 @@
 
 _DEFAULT_PROVIDES = [ApkInfo, JavaInfo]
 
-def _outputs(name, proguard_generate_mapping, _package_name, _generate_proguard_outputs, generate_art_profile):
+def _outputs(name, proguard_generate_mapping, _package_name, _generate_proguard_outputs, _generate_art_profile_outputs):
     label = "//" + _package_name + ":" + name
 
     outputs = dict(
@@ -51,7 +51,7 @@
         if proguard_generate_mapping:
             outputs["proguard_map"] = "%{name}_proguard.map"
 
-    if generate_art_profile:
+    if _generate_art_profile_outputs:
         outputs["primary_profile"] = "%{name}_primary.prof"
 
     return outputs
@@ -130,4 +130,8 @@
     if type(attrs.get("proguard_specs", None)) == "select" or attrs.get("proguard_specs", None):
         attrs["$generate_proguard_outputs"] = True
 
+    # Default value of generate_art_profile is True
+    if type(attrs.get("generate_art_profile", None)) == "select" or attrs.get("generate_art_profile", True):
+        attrs["$generate_art_profile_outputs"] = True
+
     android_binary(**sanitize_attrs(attrs))