Overridden APEX doesn't contribute to the file contexts
This change fixes the problem that when an apex module is overridden by another override_apex, the <apex_name>-file_contexts are duplicated when creating the system-level file-contexts. Fixing this by not emitting the file_context info for the overridden apex. In doing so, OverridableModule interface was extended to have GetOverriddenBy() method which can be used to test whether a module is an overridden one or not. Bug: 144338929 Test: m (apex_test amended) Test: add "override_apex {name:"com.googlge.android.tzdata", Change-Id: I5e9401c32899bb9987c90cba4185f571dc1a87f0 base:"com.android.tzdata"}" and the build is successful
This commit is contained in:
parent
7b34ebf447
commit
317645e84c
|
@ -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.
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue