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:
parent
3c7c34769d
commit
03e7d0ca9c
|
@ -32,6 +32,14 @@ type ApexInfo struct {
|
|||
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
|
||||
// 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).
|
||||
|
@ -49,6 +57,8 @@ type ApexInfo struct {
|
|||
// respectively.
|
||||
type ApexModule interface {
|
||||
Module
|
||||
DepIsInSameApex
|
||||
|
||||
apexModuleBase() *ApexModuleBase
|
||||
|
||||
// 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"
|
||||
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.
|
||||
// For example, with maxSdkVersion is 10 and versionList is [9,11]
|
||||
// it returns 9 as string
|
||||
|
|
|
@ -22,17 +22,30 @@ import (
|
|||
"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
|
||||
// built with SDK
|
||||
type SdkAware interface {
|
||||
Module
|
||||
RequiredSdks
|
||||
|
||||
sdkBase() *SdkBase
|
||||
MakeMemberOf(sdk SdkRef)
|
||||
IsInAnySdk() bool
|
||||
ContainingSdk() SdkRef
|
||||
MemberName() string
|
||||
BuildWithSdks(sdks SdkRefs)
|
||||
RequiredSdks() SdkRefs
|
||||
}
|
||||
|
||||
// SdkRef refers to a version of an SDK
|
||||
|
|
|
@ -862,9 +862,7 @@ func apexDepsMutator(mctx android.TopDownMutatorContext) {
|
|||
return
|
||||
}
|
||||
|
||||
cur := mctx.Module().(interface {
|
||||
DepIsInSameApex(android.BaseModuleContext, android.Module) bool
|
||||
})
|
||||
cur := mctx.Module().(android.DepIsInSameApex)
|
||||
|
||||
mctx.VisitDirectDeps(func(child android.Module) {
|
||||
depName := mctx.OtherModuleName(child)
|
||||
|
|
|
@ -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
|
||||
func sdkRequirementsMutator(mctx android.TopDownMutatorContext) {
|
||||
if m, ok := mctx.Module().(interface {
|
||||
DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool
|
||||
RequiredSdks() android.SdkRefs
|
||||
android.DepIsInSameApex
|
||||
android.RequiredSdks
|
||||
}); ok {
|
||||
requiredSdks := m.RequiredSdks()
|
||||
if len(requiredSdks) == 0 {
|
||||
|
|
Loading…
Reference in New Issue