Change how override_modules work with prebuilts.

If an override module is overridden by a prebuilt, only skip its
installation instead of completely ignoring it, so that other modules
rely on it can still get configured and built properly.

Fixes: 159694118
Test: m checkbuild
Merged-In: I96d24f1440ff8a8aa8b1253fc22fd532b5588339
Change-Id: I96d24f1440ff8a8aa8b1253fc22fd532b5588339
This commit is contained in:
Jaewoong Jung 2020-06-23 07:58:13 -07:00
parent 0e63a8e761
commit 1e362dade7

View file

@ -42,6 +42,11 @@ type OverrideModule interface {
setOverridingProperties(properties []interface{})
getOverrideModuleProperties() *OverrideModuleProperties
// Internal funcs to handle interoperability between override modules and prebuilts.
// i.e. cases where an overriding module, too, is overridden by a prebuilt module.
setOverriddenByPrebuilt(overridden bool)
getOverriddenByPrebuilt() bool
}
// Base module struct for override module types
@ -49,6 +54,8 @@ type OverrideModuleBase struct {
moduleProperties OverrideModuleProperties
overridingProperties []interface{}
overriddenByPrebuilt bool
}
type OverrideModuleProperties struct {
@ -74,6 +81,14 @@ func (o *OverrideModuleBase) GetOverriddenModuleName() string {
return proptools.String(o.moduleProperties.Base)
}
func (o *OverrideModuleBase) setOverriddenByPrebuilt(overridden bool) {
o.overriddenByPrebuilt = overridden
}
func (o *OverrideModuleBase) getOverriddenByPrebuilt() bool {
return o.overriddenByPrebuilt
}
func InitOverrideModule(m OverrideModule) {
m.setOverridingProperties(m.GetProperties())
@ -208,21 +223,19 @@ var overrideBaseDepTag overrideBaseDependencyTag
// next phase.
func overrideModuleDepsMutator(ctx BottomUpMutatorContext) {
if module, ok := ctx.Module().(OverrideModule); ok {
// Skip this overriding module if there's a prebuilt module that overrides it with prefer flag.
overriddenByPrebuilt := false
// See if there's a prebuilt module that overrides this override module with prefer flag,
// in which case we call SkipInstall on the corresponding variant later.
ctx.VisitDirectDepsWithTag(PrebuiltDepTag, func(dep Module) {
prebuilt, ok := dep.(PrebuiltInterface)
if !ok {
panic("PrebuiltDepTag leads to a non-prebuilt module " + dep.Name())
}
if prebuilt.Prebuilt().UsePrebuilt() {
overriddenByPrebuilt = true
module.setOverriddenByPrebuilt(true)
return
}
})
if !overriddenByPrebuilt {
ctx.AddDependency(ctx.Module(), overrideBaseDepTag, *module.getOverrideModuleProperties().Base)
}
ctx.AddDependency(ctx.Module(), overrideBaseDepTag, *module.getOverrideModuleProperties().Base)
}
}
@ -258,6 +271,10 @@ func performOverrideMutator(ctx BottomUpMutatorContext) {
ctx.AliasVariation(variants[0])
for i, o := range overrides {
mods[i+1].(OverridableModule).override(ctx, o)
if o.getOverriddenByPrebuilt() {
// The overriding module itself, too, is overridden by a prebuilt. Skip its installation.
mods[i+1].SkipInstall()
}
}
} else if o, ok := ctx.Module().(OverrideModule); ok {
// Create a variant of the overriding module with its own name. This matches the above local