diff --git a/android/override_module.go b/android/override_module.go index f946587c3..45f7be070 100644 --- a/android/override_module.go +++ b/android/override_module.go @@ -82,13 +82,16 @@ func InitOverrideModule(m OverrideModule) { // Interface for overridable module types, e.g. android_app, apex type OverridableModule interface { + Module + moduleBase() *OverridableModuleBase + setOverridableProperties(prop []interface{}) addOverride(o OverrideModule) getOverrides() []OverrideModule override(ctx BaseModuleContext, o OverrideModule) - getOverriddenBy() string + GetOverriddenBy() string setOverridesProperty(overridesProperties *[]string) @@ -97,6 +100,10 @@ type OverridableModule interface { OverridablePropertiesDepsMutator(ctx BottomUpMutatorContext) } +type overridableModuleProperties struct { + OverriddenBy string `blueprint:"mutated"` +} + // Base module struct for overridable module types type OverridableModuleBase struct { // List of OverrideModules that override this base module @@ -114,12 +121,17 @@ type OverridableModuleBase struct { // override information is propagated and aggregated correctly. overridesProperty *[]string - overriddenBy string + properties overridableModuleProperties } func InitOverridableModule(m OverridableModule, overridesProperty *[]string) { m.setOverridableProperties(m.(Module).GetProperties()) m.setOverridesProperty(overridesProperty) + m.AddProperties(&m.moduleBase().properties) +} + +func (o *OverridableModuleBase) moduleBase() *OverridableModuleBase { + return o } func (b *OverridableModuleBase) setOverridableProperties(prop []interface{}) { @@ -162,11 +174,15 @@ func (b *OverridableModuleBase) override(ctx BaseModuleContext, o OverrideModule } } } - b.overriddenBy = o.Name() + b.properties.OverriddenBy = o.Name() } -func (b *OverridableModuleBase) getOverriddenBy() string { - return b.overriddenBy +// GetOverriddenBy returns the name of the override module that has overridden this module. +// For example, if an override module foo has its 'base' property set to bar, then another local variant +// of bar is created and its properties are overriden by foo. This method returns bar when called from +// the new local variant. It returns "" when called from the original variant of bar. +func (b *OverridableModuleBase) GetOverriddenBy() string { + return b.properties.OverriddenBy } func (b *OverridableModuleBase) OverridablePropertiesDepsMutator(ctx BottomUpMutatorContext) { @@ -247,7 +263,7 @@ func overridableModuleDepsMutator(ctx BottomUpMutatorContext) { func replaceDepsOnOverridingModuleMutator(ctx BottomUpMutatorContext) { if b, ok := ctx.Module().(OverridableModule); ok { - if o := b.getOverriddenBy(); o != "" { + if o := b.GetOverriddenBy(); o != "" { // Redirect dependencies on the overriding module to this overridden module. Overriding // modules are basically pseudo modules, and all build actions are associated to overridden // modules. Therefore, dependencies on overriding modules need to be forwarded there as well. diff --git a/apex/apex_test.go b/apex/apex_test.go index 509d76039..c5aeb8df0 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -2977,6 +2977,15 @@ func TestOverrideApex(t *testing.T) { } `) + originalVariant := ctx.ModuleForTests("myapex", "android_common_myapex_image").Module().(android.OverridableModule) + overriddenVariant := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image").Module().(android.OverridableModule) + if originalVariant.GetOverriddenBy() != "" { + t.Errorf("GetOverriddenBy should be empty, but was %q", originalVariant.GetOverriddenBy()) + } + if overriddenVariant.GetOverriddenBy() != "override_myapex" { + t.Errorf("GetOverriddenBy should be \"override_myapex\", but was %q", overriddenVariant.GetOverriddenBy()) + } + module := ctx.ModuleForTests("myapex", "android_common_override_myapex_myapex_image") apexRule := module.Rule("apexRule") copyCmds := apexRule.Args["copy_commands"] diff --git a/apex/builder.go b/apex/builder.go index f199bd4be..0232c1e4e 100644 --- a/apex/builder.go +++ b/apex/builder.go @@ -476,7 +476,7 @@ func (a *apexBundle) buildFlattenedApex(ctx android.ModuleContext) { apexName := proptools.StringDefault(a.properties.Apex_name, ctx.ModuleName()) a.outputFile = android.PathForModuleInstall(&factx, "apex", apexName) - if a.installable() { + if a.installable() && a.GetOverriddenBy() == "" { installPath := android.PathForModuleInstall(ctx, "apex", apexName) devicePath := android.InstallPathToOnDevicePath(ctx, installPath) addFlattenedFileContextsInfos(ctx, apexName+":"+devicePath+":"+a.fileContexts.String())