Merge "Make override modules compatible with prebuilts." into rvc-dev

This commit is contained in:
TreeHugger Robot 2020-06-12 03:44:53 +00:00 committed by Android (Google) Code Review
commit ddac56e375
2 changed files with 85 additions and 9 deletions

View File

@ -208,7 +208,21 @@ var overrideBaseDepTag overrideBaseDependencyTag
// next phase. // next phase.
func overrideModuleDepsMutator(ctx BottomUpMutatorContext) { func overrideModuleDepsMutator(ctx BottomUpMutatorContext) {
if module, ok := ctx.Module().(OverrideModule); ok { if module, ok := ctx.Module().(OverrideModule); ok {
ctx.AddDependency(ctx.Module(), overrideBaseDepTag, *module.getOverrideModuleProperties().Base) // Skip this overriding module if there's a prebuilt module that overrides it with prefer flag.
overriddenByPrebuilt := false
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
return
}
})
if !overriddenByPrebuilt {
ctx.AddDependency(ctx.Module(), overrideBaseDepTag, *module.getOverrideModuleProperties().Base)
}
} }
} }

View File

@ -122,6 +122,44 @@ var prebuiltsTests = []struct {
}`, }`,
prebuilt: true, prebuilt: true,
}, },
{
name: "prebuilt override not preferred",
modules: `
source {
name: "baz",
}
override_source {
name: "bar",
base: "baz",
}
prebuilt {
name: "bar",
prefer: false,
srcs: ["prebuilt_file"],
}`,
prebuilt: false,
},
{
name: "prebuilt override preferred",
modules: `
source {
name: "baz",
}
override_source {
name: "bar",
base: "baz",
}
prebuilt {
name: "bar",
prefer: true,
srcs: ["prebuilt_file"],
}`,
prebuilt: true,
},
} }
func TestPrebuilts(t *testing.T) { func TestPrebuilts(t *testing.T) {
@ -213,8 +251,10 @@ func TestPrebuilts(t *testing.T) {
func registerTestPrebuiltBuildComponents(ctx RegistrationContext) { func registerTestPrebuiltBuildComponents(ctx RegistrationContext) {
ctx.RegisterModuleType("prebuilt", newPrebuiltModule) ctx.RegisterModuleType("prebuilt", newPrebuiltModule)
ctx.RegisterModuleType("source", newSourceModule) ctx.RegisterModuleType("source", newSourceModule)
ctx.RegisterModuleType("override_source", newOverrideSourceModule)
RegisterPrebuiltMutators(ctx) RegisterPrebuiltMutators(ctx)
ctx.PostDepsMutators(RegisterOverridePostDepsMutators)
} }
type prebuiltModule struct { type prebuiltModule struct {
@ -257,11 +297,15 @@ func (p *prebuiltModule) OutputFiles(tag string) (Paths, error) {
} }
} }
type sourceModuleProperties struct {
Deps []string `android:"path"`
}
type sourceModule struct { type sourceModule struct {
ModuleBase ModuleBase
properties struct { OverridableModuleBase
Deps []string `android:"path"`
} properties sourceModuleProperties
dependsOnSourceModule, dependsOnPrebuiltModule bool dependsOnSourceModule, dependsOnPrebuiltModule bool
deps Paths deps Paths
src Path src Path
@ -271,10 +315,11 @@ func newSourceModule() Module {
m := &sourceModule{} m := &sourceModule{}
m.AddProperties(&m.properties) m.AddProperties(&m.properties)
InitAndroidModule(m) InitAndroidModule(m)
InitOverridableModule(m, nil)
return m return m
} }
func (s *sourceModule) DepsMutator(ctx BottomUpMutatorContext) { func (s *sourceModule) OverridablePropertiesDepsMutator(ctx BottomUpMutatorContext) {
// s.properties.Deps are annotated with android:path, so they are // s.properties.Deps are annotated with android:path, so they are
// automatically added to the dependency by pathDeps mutator // automatically added to the dependency by pathDeps mutator
} }
@ -287,3 +332,20 @@ func (s *sourceModule) GenerateAndroidBuildActions(ctx ModuleContext) {
func (s *sourceModule) Srcs() Paths { func (s *sourceModule) Srcs() Paths {
return Paths{s.src} return Paths{s.src}
} }
type overrideSourceModule struct {
ModuleBase
OverrideModuleBase
}
func (o *overrideSourceModule) GenerateAndroidBuildActions(_ ModuleContext) {
}
func newOverrideSourceModule() Module {
m := &overrideSourceModule{}
m.AddProperties(&sourceModuleProperties{})
InitAndroidModule(m)
InitOverrideModule(m)
return m
}