aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'android/override_module.go')
-rw-r--r--android/override_module.go35
1 files changed, 34 insertions, 1 deletions
diff --git a/android/override_module.go b/android/override_module.go
index 119bca1c..5a57c937 100644
--- a/android/override_module.go
+++ b/android/override_module.go
@@ -84,8 +84,13 @@ type OverridableModule interface {
84 getOverrides() []OverrideModule 84 getOverrides() []OverrideModule
85 85
86 override(ctx BaseModuleContext, o OverrideModule) 86 override(ctx BaseModuleContext, o OverrideModule)
87 getOverriddenBy() string
87 88
88 setOverridesProperty(overridesProperties *[]string) 89 setOverridesProperty(overridesProperties *[]string)
90
91 // Due to complications with incoming dependencies, overrides are processed after DepsMutator.
92 // So, overridable properties need to be handled in a separate, dedicated deps mutator.
93 OverridablePropertiesDepsMutator(ctx BottomUpMutatorContext)
89} 94}
90 95
91// Base module struct for overridable module types 96// Base module struct for overridable module types
@@ -106,6 +111,8 @@ type OverridableModuleBase struct {
106 // set this to a pointer to the property through the InitOverridableModule function, so that 111 // set this to a pointer to the property through the InitOverridableModule function, so that
107 // override information is propagated and aggregated correctly. 112 // override information is propagated and aggregated correctly.
108 overridesProperty *[]string 113 overridesProperty *[]string
114
115 overriddenBy string
109} 116}
110 117
111func InitOverridableModule(m OverridableModule, overridesProperty *[]string) { 118func InitOverridableModule(m OverridableModule, overridesProperty *[]string) {
@@ -153,14 +160,23 @@ func (b *OverridableModuleBase) override(ctx BaseModuleContext, o OverrideModule
153 } 160 }
154 } 161 }
155 } 162 }
163 b.overriddenBy = o.Name()
164}
165
166func (b *OverridableModuleBase) getOverriddenBy() string {
167 return b.overriddenBy
168}
169
170func (b *OverridableModuleBase) OverridablePropertiesDepsMutator(ctx BottomUpMutatorContext) {
156} 171}
157 172
158// Mutators for override/overridable modules. All the fun happens in these functions. It is critical 173// Mutators for override/overridable modules. All the fun happens in these functions. It is critical
159// to keep them in this order and not put any order mutators between them. 174// to keep them in this order and not put any order mutators between them.
160func RegisterOverridePreArchMutators(ctx RegisterMutatorsContext) { 175func RegisterOverridePostDepsMutators(ctx RegisterMutatorsContext) {
161 ctx.BottomUp("override_deps", overrideModuleDepsMutator).Parallel() 176 ctx.BottomUp("override_deps", overrideModuleDepsMutator).Parallel()
162 ctx.TopDown("register_override", registerOverrideMutator).Parallel() 177 ctx.TopDown("register_override", registerOverrideMutator).Parallel()
163 ctx.BottomUp("perform_override", performOverrideMutator).Parallel() 178 ctx.BottomUp("perform_override", performOverrideMutator).Parallel()
179 ctx.BottomUp("overridable_deps", overridableModuleDepsMutator).Parallel()
164} 180}
165 181
166type overrideBaseDependencyTag struct { 182type overrideBaseDependencyTag struct {
@@ -207,5 +223,22 @@ func performOverrideMutator(ctx BottomUpMutatorContext) {
207 for i, o := range overrides { 223 for i, o := range overrides {
208 mods[i+1].(OverridableModule).override(ctx, o) 224 mods[i+1].(OverridableModule).override(ctx, o)
209 } 225 }
226 } else if o, ok := ctx.Module().(OverrideModule); ok {
227 // Create a variant of the overriding module with its own name. This matches the above local
228 // variant name rule for overridden modules, and thus allows ReplaceDependencies to match the
229 // two.
230 ctx.CreateLocalVariations(o.Name())
231 }
232}
233
234func overridableModuleDepsMutator(ctx BottomUpMutatorContext) {
235 if b, ok := ctx.Module().(OverridableModule); ok {
236 if o := b.getOverriddenBy(); o != "" {
237 // Redirect dependencies on the overriding module to this overridden module. Overriding
238 // modules are basically pseudo modules, and all build actions are associated to overridden
239 // modules. Therefore, dependencies on overriding modules need to be forwarded there as well.
240 ctx.ReplaceDependencies(o)
241 }
242 b.OverridablePropertiesDepsMutator(ctx)
210 } 243 }
211} 244}