Extract DepIsInSameApex and RequiredSdks interfaces

The DepIsInSameApex() and RequiredSdks() methods were defined in a few
places to avoid having to depend on the whole ApexModule/SdkAware
interfaces directly. However, that has a couple of issues:
1) It duplicates functionality making it difficult to change, changes
   to the definitions outside the main interfaces do not cause compile
   time failures, instead they result in a runtime change in behavior
   which can be difficult to debug.
2) IDE navigation (specifically in Intellij) does not detect that the
   duplicate definitions can resolve to the definitions in the main
   interface.

This change extracts the methods into their own interfaces and reuses
those interfaces instead of duplicating the methods to fix both of
these issues.

Bug: 152878661
Bug: 153306490
Test: m nothing
Merged-In: I0cfdf342a14eb0bfb82b1bd17e0633d81c7facfb
Change-Id: I0cfdf342a14eb0bfb82b1bd17e0633d81c7facfb
This commit is contained in:
Paul Duffin
2020-03-30 15:33:32 +01:00
parent 3c7c34769d
commit 03e7d0ca9c
4 changed files with 27 additions and 10 deletions

View File

@@ -32,6 +32,14 @@ type ApexInfo struct {
MinSdkVersion int MinSdkVersion int
} }
// Extracted from ApexModule to make it easier to define custom subsets of the
// ApexModule interface and improve code navigation within the IDE.
type DepIsInSameApex interface {
// DepIsInSameApex tests if the other module 'dep' is installed to the same
// APEX as this module
DepIsInSameApex(ctx BaseModuleContext, dep Module) bool
}
// ApexModule is the interface that a module type is expected to implement if // ApexModule is the interface that a module type is expected to implement if
// the module has to be built differently depending on whether the module // the module has to be built differently depending on whether the module
// is destined for an apex or not (installed to one of the regular partitions). // is destined for an apex or not (installed to one of the regular partitions).
@@ -49,6 +57,8 @@ type ApexInfo struct {
// respectively. // respectively.
type ApexModule interface { type ApexModule interface {
Module Module
DepIsInSameApex
apexModuleBase() *ApexModuleBase apexModuleBase() *ApexModuleBase
// Marks that this module should be built for the specified APEXes. // Marks that this module should be built for the specified APEXes.
@@ -88,10 +98,6 @@ type ApexModule interface {
// Tests if this module is available for the specified APEX or ":platform" // Tests if this module is available for the specified APEX or ":platform"
AvailableFor(what string) bool AvailableFor(what string) bool
// DepIsInSameApex tests if the other module 'dep' is installed to the same
// APEX as this module
DepIsInSameApex(ctx BaseModuleContext, dep Module) bool
// Returns the highest version which is <= maxSdkVersion. // Returns the highest version which is <= maxSdkVersion.
// For example, with maxSdkVersion is 10 and versionList is [9,11] // For example, with maxSdkVersion is 10 and versionList is [9,11]
// it returns 9 as string // it returns 9 as string

View File

@@ -22,17 +22,30 @@ import (
"github.com/google/blueprint/proptools" "github.com/google/blueprint/proptools"
) )
// Extracted from SdkAware to make it easier to define custom subsets of the
// SdkAware interface and improve code navigation within the IDE.
//
// In addition to its use in SdkAware this interface must also be implemented by
// APEX to specify the SDKs required by that module and its contents. e.g. APEX
// is expected to implement RequiredSdks() by reading its own properties like
// `uses_sdks`.
type RequiredSdks interface {
// The set of SDKs required by an APEX and its contents.
RequiredSdks() SdkRefs
}
// SdkAware is the interface that must be supported by any module to become a member of SDK or to be // SdkAware is the interface that must be supported by any module to become a member of SDK or to be
// built with SDK // built with SDK
type SdkAware interface { type SdkAware interface {
Module Module
RequiredSdks
sdkBase() *SdkBase sdkBase() *SdkBase
MakeMemberOf(sdk SdkRef) MakeMemberOf(sdk SdkRef)
IsInAnySdk() bool IsInAnySdk() bool
ContainingSdk() SdkRef ContainingSdk() SdkRef
MemberName() string MemberName() string
BuildWithSdks(sdks SdkRefs) BuildWithSdks(sdks SdkRefs)
RequiredSdks() SdkRefs
} }
// SdkRef refers to a version of an SDK // SdkRef refers to a version of an SDK

View File

@@ -862,9 +862,7 @@ func apexDepsMutator(mctx android.TopDownMutatorContext) {
return return
} }
cur := mctx.Module().(interface { cur := mctx.Module().(android.DepIsInSameApex)
DepIsInSameApex(android.BaseModuleContext, android.Module) bool
})
mctx.VisitDirectDeps(func(child android.Module) { mctx.VisitDirectDeps(func(child android.Module) {
depName := mctx.OtherModuleName(child) depName := mctx.OtherModuleName(child)

View File

@@ -434,8 +434,8 @@ func sdkDepsReplaceMutator(mctx android.BottomUpMutatorContext) {
// Step 6: ensure that the dependencies from outside of the APEX are all from the required SDKs // Step 6: ensure that the dependencies from outside of the APEX are all from the required SDKs
func sdkRequirementsMutator(mctx android.TopDownMutatorContext) { func sdkRequirementsMutator(mctx android.TopDownMutatorContext) {
if m, ok := mctx.Module().(interface { if m, ok := mctx.Module().(interface {
DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool android.DepIsInSameApex
RequiredSdks() android.SdkRefs android.RequiredSdks
}); ok { }); ok {
requiredSdks := m.RequiredSdks() requiredSdks := m.RequiredSdks()
if len(requiredSdks) == 0 { if len(requiredSdks) == 0 {