Refactor SdkMemberType.AddDependencies()

Replaces the BottomUpMutatorContext parameter with a new
SdkDependencyContext type that extends BottomUpMutatorContext. This is
to allow the sdk to pass additional information to the implementations
of that method to allow the behavior to be more finely tuned.

Bug: 195754365
Test: m nothing
Change-Id: I69c6d2c523934eb67d7a7e6c55c241e9b8a81773
This commit is contained in:
Paul Duffin
2021-07-14 10:29:36 +01:00
parent 45de13f93d
commit 296701e35b
10 changed files with 46 additions and 26 deletions

View File

@@ -31,9 +31,9 @@ type licenseSdkMemberType struct {
SdkMemberTypeBase SdkMemberTypeBase
} }
func (l *licenseSdkMemberType) AddDependencies(mctx BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { func (l *licenseSdkMemberType) AddDependencies(ctx SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
// Add dependencies onto the license module from the sdk module. // Add dependencies onto the license module from the sdk module.
mctx.AddDependency(mctx.Module(), dependencyTag, names...) ctx.AddDependency(ctx.Module(), dependencyTag, names...)
} }
func (l *licenseSdkMemberType) IsInstance(module Module) bool { func (l *licenseSdkMemberType) IsInstance(module Module) bool {

View File

@@ -475,7 +475,7 @@ type SdkMemberType interface {
// properties. The dependencies must be added with the supplied tag. // properties. The dependencies must be added with the supplied tag.
// //
// The BottomUpMutatorContext provided is for the SDK module. // The BottomUpMutatorContext provided is for the SDK module.
AddDependencies(mctx BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) AddDependencies(ctx SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string)
// Return true if the supplied module is an instance of this member type. // Return true if the supplied module is an instance of this member type.
// //
@@ -529,6 +529,12 @@ type SdkMemberType interface {
CreateVariantPropertiesStruct() SdkMemberProperties CreateVariantPropertiesStruct() SdkMemberProperties
} }
// SdkDependencyContext provides access to information needed by the SdkMemberType.AddDependencies()
// implementations.
type SdkDependencyContext interface {
BottomUpMutatorContext
}
// Base type for SdkMemberType implementations. // Base type for SdkMemberType implementations.
type SdkMemberTypeBase struct { type SdkMemberTypeBase struct {
PropertyName string PropertyName string

View File

@@ -38,16 +38,16 @@ type binarySdkMemberType struct {
android.SdkMemberTypeBase android.SdkMemberTypeBase
} }
func (mt *binarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { func (mt *binarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
targets := mctx.MultiTargets() targets := ctx.MultiTargets()
for _, bin := range names { for _, bin := range names {
for _, target := range targets { for _, target := range targets {
variations := target.Variations() variations := target.Variations()
if mctx.Device() { if ctx.Device() {
variations = append(variations, variations = append(variations,
blueprint.Variation{Mutator: "image", Variation: android.CoreVariation}) blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})
} }
mctx.AddFarVariationDependencies(variations, dependencyTag, bin) ctx.AddFarVariationDependencies(variations, dependencyTag, bin)
} }
} }
} }

View File

@@ -74,8 +74,8 @@ type librarySdkMemberType struct {
linkTypes []string linkTypes []string
} }
func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { func (mt *librarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
targets := mctx.MultiTargets() targets := ctx.MultiTargets()
for _, lib := range names { for _, lib := range names {
for _, target := range targets { for _, target := range targets {
name, version := StubsLibNameAndVersion(lib) name, version := StubsLibNameAndVersion(lib)
@@ -83,21 +83,21 @@ func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorCont
version = "latest" version = "latest"
} }
variations := target.Variations() variations := target.Variations()
if mctx.Device() { if ctx.Device() {
variations = append(variations, variations = append(variations,
blueprint.Variation{Mutator: "image", Variation: android.CoreVariation}) blueprint.Variation{Mutator: "image", Variation: android.CoreVariation})
} }
if mt.linkTypes == nil { if mt.linkTypes == nil {
mctx.AddFarVariationDependencies(variations, dependencyTag, name) ctx.AddFarVariationDependencies(variations, dependencyTag, name)
} else { } else {
for _, linkType := range mt.linkTypes { for _, linkType := range mt.linkTypes {
libVariations := append(variations, libVariations := append(variations,
blueprint.Variation{Mutator: "link", Variation: linkType}) blueprint.Variation{Mutator: "link", Variation: linkType})
if mctx.Device() && linkType == "shared" { if ctx.Device() && linkType == "shared" {
libVariations = append(libVariations, libVariations = append(libVariations,
blueprint.Variation{Mutator: "version", Variation: version}) blueprint.Variation{Mutator: "version", Variation: version})
} }
mctx.AddFarVariationDependencies(libVariations, dependencyTag, name) ctx.AddFarVariationDependencies(libVariations, dependencyTag, name)
} }
} }
} }

View File

@@ -718,8 +718,8 @@ type bootclasspathFragmentMemberType struct {
android.SdkMemberTypeBase android.SdkMemberTypeBase
} }
func (b *bootclasspathFragmentMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { func (b *bootclasspathFragmentMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
mctx.AddVariationDependencies(nil, dependencyTag, names...) ctx.AddVariationDependencies(nil, dependencyTag, names...)
} }
func (b *bootclasspathFragmentMemberType) IsInstance(module android.Module) bool { func (b *bootclasspathFragmentMemberType) IsInstance(module android.Module) bool {

View File

@@ -574,8 +574,8 @@ const (
copyEverythingToSnapshot = false copyEverythingToSnapshot = false
) )
func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { func (mt *librarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
mctx.AddVariationDependencies(nil, dependencyTag, names...) ctx.AddVariationDependencies(nil, dependencyTag, names...)
} }
func (mt *librarySdkMemberType) IsInstance(module android.Module) bool { func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
@@ -875,8 +875,8 @@ type testSdkMemberType struct {
android.SdkMemberTypeBase android.SdkMemberTypeBase
} }
func (mt *testSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { func (mt *testSdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
mctx.AddVariationDependencies(nil, dependencyTag, names...) ctx.AddVariationDependencies(nil, dependencyTag, names...)
} }
func (mt *testSdkMemberType) IsInstance(module android.Module) bool { func (mt *testSdkMemberType) IsInstance(module android.Module) bool {

View File

@@ -134,8 +134,8 @@ type compatConfigMemberType struct {
android.SdkMemberTypeBase android.SdkMemberTypeBase
} }
func (b *compatConfigMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { func (b *compatConfigMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
mctx.AddVariationDependencies(nil, dependencyTag, names...) ctx.AddVariationDependencies(nil, dependencyTag, names...)
} }
func (b *compatConfigMemberType) IsInstance(module android.Module) bool { func (b *compatConfigMemberType) IsInstance(module android.Module) bool {

View File

@@ -2471,8 +2471,8 @@ type sdkLibrarySdkMemberType struct {
android.SdkMemberTypeBase android.SdkMemberTypeBase
} }
func (s *sdkLibrarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { func (s *sdkLibrarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
mctx.AddVariationDependencies(nil, dependencyTag, names...) ctx.AddVariationDependencies(nil, dependencyTag, names...)
} }
func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool { func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool {

View File

@@ -245,8 +245,8 @@ type systemModulesSdkMemberType struct {
android.SdkMemberTypeBase android.SdkMemberTypeBase
} }
func (mt *systemModulesSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { func (mt *systemModulesSdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) {
mctx.AddVariationDependencies(nil, dependencyTag, names...) ctx.AddVariationDependencies(nil, dependencyTag, names...)
} }
func (mt *systemModulesSdkMemberType) IsInstance(module android.Module) bool { func (mt *systemModulesSdkMemberType) IsInstance(module android.Module) bool {

View File

@@ -341,6 +341,19 @@ func (s *sdk) AndroidMkEntries() []android.AndroidMkEntries {
}} }}
} }
// newDependencyContext creates a new SdkDependencyContext for this sdk.
func (s *sdk) newDependencyContext(mctx android.BottomUpMutatorContext) android.SdkDependencyContext {
return &dependencyContext{
BottomUpMutatorContext: mctx,
}
}
type dependencyContext struct {
android.BottomUpMutatorContext
}
var _ android.SdkDependencyContext = (*dependencyContext)(nil)
// RegisterPreDepsMutators registers pre-deps mutators to support modules implementing SdkAware // RegisterPreDepsMutators registers pre-deps mutators to support modules implementing SdkAware
// interface and the sdk module type. This function has been made public to be called by tests // interface and the sdk module type. This function has been made public to be called by tests
// outside of the sdk package // outside of the sdk package
@@ -410,6 +423,7 @@ func memberMutator(mctx android.BottomUpMutatorContext) {
if s, ok := mctx.Module().(*sdk); ok { if s, ok := mctx.Module().(*sdk); ok {
// Add dependencies from enabled and non CommonOS variants to the sdk member variants. // Add dependencies from enabled and non CommonOS variants to the sdk member variants.
if s.Enabled() && !s.IsCommonOSVariant() { if s.Enabled() && !s.IsCommonOSVariant() {
ctx := s.newDependencyContext(mctx)
for _, memberListProperty := range s.memberListProperties() { for _, memberListProperty := range s.memberListProperties() {
if memberListProperty.getter == nil { if memberListProperty.getter == nil {
continue continue
@@ -417,7 +431,7 @@ func memberMutator(mctx android.BottomUpMutatorContext) {
names := memberListProperty.getter(s.dynamicMemberTypeListProperties) names := memberListProperty.getter(s.dynamicMemberTypeListProperties)
if len(names) > 0 { if len(names) > 0 {
tag := memberListProperty.dependencyTag tag := memberListProperty.dependencyTag
memberListProperty.memberType.AddDependencies(mctx, tag, names) memberListProperty.memberType.AddDependencies(ctx, tag, names)
} }
} }
} }