Prevent ApexInfoMutator from creating unnecessary variants
Adds the AlwaysRequireApexVariantTag interface to enable
ApexInfoMutator to differentiate between a tag that is excluded from
apex contents but still requires an apex variant and a tag that is
excluded from apex contents and does not require an apex variant.
That is needed to support the sdkMemberVersionedDepTag which excludes
the target from being added to the APEX but requires an APEX variant.
A more detailed explanation is in the comments.
The AlwaysRequireApexVariant() method follows the pattern used in
ReplaceSourceWithPrebuilt of having a method that returns a bool to
trigger the behavior and not say ExcludeFromApexContentsTag that simply
relies on the tag implementing an interface to trigger. That is because
the former is more flexible and allows a tag type to parameterize the
behavior if necessary.
The tags that this will exclude from creating an apex variant are:
* PrebuiltDepTag - by the time the apex variant has been created any
preferred prebuilts will have replaced the sources so there is no
need to create an APEX variant if the only dependency path from the
APEX to the prebuilt is via this tag.
* hiddenApiAnnotationsDependencyTag - the target of which is a purely
build time artifect and MUST NEVER end up in the APEX.
It will also stop calling DepIsInSameApex for any dependency created
by the sdkMemberVersionedDepTag. Which will fix the issue reported in
the bug.
Bug: 182992071
Test: m nothing
Change-Id: I9569e488d6446ca45d3ea8f32a9b74524eb865df
diff --git a/apex/apex.go b/apex/apex.go
index 119345a..d70d390 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -846,6 +846,19 @@
if !ok || !am.CanHaveApexVariants() {
return false
}
+ depTag := mctx.OtherModuleDependencyTag(child)
+
+ // Check to see if the tag always requires that the child module has an apex variant for every
+ // apex variant of the parent module. If it does not then it is still possible for something
+ // else, e.g. the DepIsInSameApex(...) method to decide that a variant is required.
+ if required, ok := depTag.(android.AlwaysRequireApexVariantTag); ok && required.AlwaysRequireApexVariant() {
+ return true
+ }
+ if _, ok := depTag.(android.ExcludeFromApexContentsTag); ok {
+ // The tag defines a dependency that never requires the child module to be part of the same
+ // apex as the parent so it does not need an apex variant created.
+ return false
+ }
if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) {
return false
}