Convert trivial TopDown mutators to BottomUp

Many TopDown mutators can be easily converted to BottomUp mutators,
which are easier to handle for incremental and partial analysis.

Bug: 367784740
Test: all soong tests pass
Test: no change to build.ninja
Flag: EXEMPT refactor
Change-Id: I82955e844ed0eb6680854678c0744ac5398eb7ba
This commit is contained in:
Colin Cross
2024-09-17 14:25:45 -07:00
parent 167230037c
commit da279cfba4
9 changed files with 61 additions and 55 deletions

View File

@@ -69,7 +69,7 @@ type Defaultable interface {
// Apply defaults from the supplied Defaults to the property structures supplied to
// setProperties(...).
applyDefaults(TopDownMutatorContext, []Defaults)
applyDefaults(BottomUpMutatorContext, []Defaults)
// Set the hook to be called after any defaults have been applied.
//
@@ -209,7 +209,7 @@ func InitDefaultsModule(module DefaultsModule) {
var _ Defaults = (*DefaultsModuleBase)(nil)
func (defaultable *DefaultableModuleBase) applyDefaults(ctx TopDownMutatorContext,
func (defaultable *DefaultableModuleBase) applyDefaults(ctx BottomUpMutatorContext,
defaultsList []Defaults) {
for _, defaults := range defaultsList {
@@ -226,7 +226,7 @@ func (defaultable *DefaultableModuleBase) applyDefaults(ctx TopDownMutatorContex
// Product variable properties need special handling, the type of the filtered product variable
// property struct may not be identical between the defaults module and the defaultable module.
// Use PrependMatchingProperties to apply whichever properties match.
func (defaultable *DefaultableModuleBase) applyDefaultVariableProperties(ctx TopDownMutatorContext,
func (defaultable *DefaultableModuleBase) applyDefaultVariableProperties(ctx BottomUpMutatorContext,
defaults Defaults, defaultableProp interface{}) {
if defaultableProp == nil {
return
@@ -254,7 +254,7 @@ func (defaultable *DefaultableModuleBase) applyDefaultVariableProperties(ctx Top
}
}
func (defaultable *DefaultableModuleBase) applyDefaultProperties(ctx TopDownMutatorContext,
func (defaultable *DefaultableModuleBase) applyDefaultProperties(ctx BottomUpMutatorContext,
defaults Defaults, defaultableProp interface{}) {
for _, def := range defaults.properties() {
@@ -273,7 +273,7 @@ func (defaultable *DefaultableModuleBase) applyDefaultProperties(ctx TopDownMuta
func RegisterDefaultsPreArchMutators(ctx RegisterMutatorsContext) {
ctx.BottomUp("defaults_deps", defaultsDepsMutator).Parallel()
ctx.TopDown("defaults", defaultsMutator).Parallel()
ctx.BottomUp("defaults", defaultsMutator).Parallel()
}
func defaultsDepsMutator(ctx BottomUpMutatorContext) {
@@ -282,8 +282,12 @@ func defaultsDepsMutator(ctx BottomUpMutatorContext) {
}
}
func defaultsMutator(ctx TopDownMutatorContext) {
func defaultsMutator(ctx BottomUpMutatorContext) {
if defaultable, ok := ctx.Module().(Defaultable); ok {
if _, isDefaultsModule := ctx.Module().(Defaults); isDefaultsModule {
// Don't squash transitive defaults into defaults modules
return
}
defaults := defaultable.defaults().Defaults
if len(defaults) > 0 {
var defaultsList []Defaults