From 296701e35b96c232bc4c0af69cfe0e367fd54ef4 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Wed, 14 Jul 2021 10:29:36 +0100 Subject: [PATCH] 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 --- android/license_sdk_member.go | 4 ++-- android/sdk.go | 8 +++++++- cc/binary_sdk_member.go | 8 ++++---- cc/library_sdk_member.go | 12 ++++++------ java/bootclasspath_fragment.go | 4 ++-- java/java.go | 8 ++++---- java/platform_compat_config.go | 4 ++-- java/sdk_library.go | 4 ++-- java/system_modules.go | 4 ++-- sdk/sdk.go | 16 +++++++++++++++- 10 files changed, 46 insertions(+), 26 deletions(-) diff --git a/android/license_sdk_member.go b/android/license_sdk_member.go index cd36ed6c5..2ce921bb0 100644 --- a/android/license_sdk_member.go +++ b/android/license_sdk_member.go @@ -31,9 +31,9 @@ type licenseSdkMemberType struct { 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. - mctx.AddDependency(mctx.Module(), dependencyTag, names...) + ctx.AddDependency(ctx.Module(), dependencyTag, names...) } func (l *licenseSdkMemberType) IsInstance(module Module) bool { diff --git a/android/sdk.go b/android/sdk.go index 5f4b387c2..cf434b01e 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -475,7 +475,7 @@ type SdkMemberType interface { // properties. The dependencies must be added with the supplied tag. // // 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. // @@ -529,6 +529,12 @@ type SdkMemberType interface { CreateVariantPropertiesStruct() SdkMemberProperties } +// SdkDependencyContext provides access to information needed by the SdkMemberType.AddDependencies() +// implementations. +type SdkDependencyContext interface { + BottomUpMutatorContext +} + // Base type for SdkMemberType implementations. type SdkMemberTypeBase struct { PropertyName string diff --git a/cc/binary_sdk_member.go b/cc/binary_sdk_member.go index ebf89eaec..71e0cd8ce 100644 --- a/cc/binary_sdk_member.go +++ b/cc/binary_sdk_member.go @@ -38,16 +38,16 @@ type binarySdkMemberType struct { android.SdkMemberTypeBase } -func (mt *binarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { - targets := mctx.MultiTargets() +func (mt *binarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { + targets := ctx.MultiTargets() for _, bin := range names { for _, target := range targets { variations := target.Variations() - if mctx.Device() { + if ctx.Device() { variations = append(variations, blueprint.Variation{Mutator: "image", Variation: android.CoreVariation}) } - mctx.AddFarVariationDependencies(variations, dependencyTag, bin) + ctx.AddFarVariationDependencies(variations, dependencyTag, bin) } } } diff --git a/cc/library_sdk_member.go b/cc/library_sdk_member.go index 9010a1a89..1866ff30b 100644 --- a/cc/library_sdk_member.go +++ b/cc/library_sdk_member.go @@ -74,8 +74,8 @@ type librarySdkMemberType struct { linkTypes []string } -func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { - targets := mctx.MultiTargets() +func (mt *librarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { + targets := ctx.MultiTargets() for _, lib := range names { for _, target := range targets { name, version := StubsLibNameAndVersion(lib) @@ -83,21 +83,21 @@ func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorCont version = "latest" } variations := target.Variations() - if mctx.Device() { + if ctx.Device() { variations = append(variations, blueprint.Variation{Mutator: "image", Variation: android.CoreVariation}) } if mt.linkTypes == nil { - mctx.AddFarVariationDependencies(variations, dependencyTag, name) + ctx.AddFarVariationDependencies(variations, dependencyTag, name) } else { for _, linkType := range mt.linkTypes { libVariations := append(variations, blueprint.Variation{Mutator: "link", Variation: linkType}) - if mctx.Device() && linkType == "shared" { + if ctx.Device() && linkType == "shared" { libVariations = append(libVariations, blueprint.Variation{Mutator: "version", Variation: version}) } - mctx.AddFarVariationDependencies(libVariations, dependencyTag, name) + ctx.AddFarVariationDependencies(libVariations, dependencyTag, name) } } } diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 757731632..f7561b439 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -718,8 +718,8 @@ type bootclasspathFragmentMemberType struct { android.SdkMemberTypeBase } -func (b *bootclasspathFragmentMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { - mctx.AddVariationDependencies(nil, dependencyTag, names...) +func (b *bootclasspathFragmentMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { + ctx.AddVariationDependencies(nil, dependencyTag, names...) } func (b *bootclasspathFragmentMemberType) IsInstance(module android.Module) bool { diff --git a/java/java.go b/java/java.go index 4c2ca9ba2..1a052b432 100644 --- a/java/java.go +++ b/java/java.go @@ -574,8 +574,8 @@ const ( copyEverythingToSnapshot = false ) -func (mt *librarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { - mctx.AddVariationDependencies(nil, dependencyTag, names...) +func (mt *librarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { + ctx.AddVariationDependencies(nil, dependencyTag, names...) } func (mt *librarySdkMemberType) IsInstance(module android.Module) bool { @@ -875,8 +875,8 @@ type testSdkMemberType struct { android.SdkMemberTypeBase } -func (mt *testSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { - mctx.AddVariationDependencies(nil, dependencyTag, names...) +func (mt *testSdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { + ctx.AddVariationDependencies(nil, dependencyTag, names...) } func (mt *testSdkMemberType) IsInstance(module android.Module) bool { diff --git a/java/platform_compat_config.go b/java/platform_compat_config.go index 712c2a203..0d8ebac02 100644 --- a/java/platform_compat_config.go +++ b/java/platform_compat_config.go @@ -134,8 +134,8 @@ type compatConfigMemberType struct { android.SdkMemberTypeBase } -func (b *compatConfigMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { - mctx.AddVariationDependencies(nil, dependencyTag, names...) +func (b *compatConfigMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { + ctx.AddVariationDependencies(nil, dependencyTag, names...) } func (b *compatConfigMemberType) IsInstance(module android.Module) bool { diff --git a/java/sdk_library.go b/java/sdk_library.go index c50e07779..ce8f179af 100644 --- a/java/sdk_library.go +++ b/java/sdk_library.go @@ -2471,8 +2471,8 @@ type sdkLibrarySdkMemberType struct { android.SdkMemberTypeBase } -func (s *sdkLibrarySdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { - mctx.AddVariationDependencies(nil, dependencyTag, names...) +func (s *sdkLibrarySdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { + ctx.AddVariationDependencies(nil, dependencyTag, names...) } func (s *sdkLibrarySdkMemberType) IsInstance(module android.Module) bool { diff --git a/java/system_modules.go b/java/system_modules.go index d0dc74adc..fec8ebaeb 100644 --- a/java/system_modules.go +++ b/java/system_modules.go @@ -245,8 +245,8 @@ type systemModulesSdkMemberType struct { android.SdkMemberTypeBase } -func (mt *systemModulesSdkMemberType) AddDependencies(mctx android.BottomUpMutatorContext, dependencyTag blueprint.DependencyTag, names []string) { - mctx.AddVariationDependencies(nil, dependencyTag, names...) +func (mt *systemModulesSdkMemberType) AddDependencies(ctx android.SdkDependencyContext, dependencyTag blueprint.DependencyTag, names []string) { + ctx.AddVariationDependencies(nil, dependencyTag, names...) } func (mt *systemModulesSdkMemberType) IsInstance(module android.Module) bool { diff --git a/sdk/sdk.go b/sdk/sdk.go index b1c8aebf9..a972f31da 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -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 // interface and the sdk module type. This function has been made public to be called by tests // outside of the sdk package @@ -410,6 +423,7 @@ func memberMutator(mctx android.BottomUpMutatorContext) { if s, ok := mctx.Module().(*sdk); ok { // Add dependencies from enabled and non CommonOS variants to the sdk member variants. if s.Enabled() && !s.IsCommonOSVariant() { + ctx := s.newDependencyContext(mctx) for _, memberListProperty := range s.memberListProperties() { if memberListProperty.getter == nil { continue @@ -417,7 +431,7 @@ func memberMutator(mctx android.BottomUpMutatorContext) { names := memberListProperty.getter(s.dynamicMemberTypeListProperties) if len(names) > 0 { tag := memberListProperty.dependencyTag - memberListProperty.memberType.AddDependencies(mctx, tag, names) + memberListProperty.memberType.AddDependencies(ctx, tag, names) } } }