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
This commit is contained in:
21
sdk/sdk.go
21
sdk/sdk.go
@@ -358,15 +358,36 @@ var _ android.ExcludeFromApexContentsTag = dependencyTag{}
|
||||
|
||||
// For dependencies from an in-development version of an SDK member to frozen versions of the same member
|
||||
// e.g. libfoo -> libfoo.mysdk.11 and libfoo.mysdk.12
|
||||
//
|
||||
// The dependency represented by this tag requires that for every APEX variant created for the
|
||||
// `from` module that an equivalent APEX variant is created for the 'to' module. This is because an
|
||||
// APEX that requires a specific version of an sdk (via the `uses_sdks` property will replace
|
||||
// dependencies on the unversioned sdk member with a dependency on the appropriate versioned sdk
|
||||
// member. In order for that to work the versioned sdk member needs to have a variant for that APEX.
|
||||
// As it is not known at the time that the APEX variants are created which specific APEX variants of
|
||||
// a versioned sdk members will be required it is necessary for the versioned sdk members to have
|
||||
// variants for any APEX that it could be used within.
|
||||
//
|
||||
// If the APEX selects a versioned sdk member then it will not have a dependency on the `from`
|
||||
// module at all so any dependencies of that module will not affect the APEX. However, if the APEX
|
||||
// selects the unversioned sdk member then it must exclude all the versioned sdk members. In no
|
||||
// situation would this dependency cause the `to` module to be added to the APEX hence why this tag
|
||||
// also excludes the `to` module from being added to the APEX contents.
|
||||
type sdkMemberVersionedDepTag struct {
|
||||
dependencyTag
|
||||
member string
|
||||
version string
|
||||
}
|
||||
|
||||
func (t sdkMemberVersionedDepTag) AlwaysRequireApexVariant() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// Mark this tag so dependencies that use it are excluded from visibility enforcement.
|
||||
func (t sdkMemberVersionedDepTag) ExcludeFromVisibilityEnforcement() {}
|
||||
|
||||
var _ android.AlwaysRequireApexVariantTag = sdkMemberVersionedDepTag{}
|
||||
|
||||
// Step 1: create dependencies from an SDK module to its members.
|
||||
func memberMutator(mctx android.BottomUpMutatorContext) {
|
||||
if s, ok := mctx.Module().(*sdk); ok {
|
||||
|
Reference in New Issue
Block a user