Merge "Make override modules compatible with prebuilts." am: 3d14ab7b2b
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1332075 Change-Id: I1a88cfc4807bc75d527d9b17541040fbad25094b
This commit is contained in:
commit
3bec2b0468
2 changed files with 81 additions and 5 deletions
|
@ -208,8 +208,22 @@ 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 {
|
||||||
|
// 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)
|
ctx.AddDependency(ctx.Module(), overrideBaseDepTag, *module.getOverrideModuleProperties().Base)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Visits the base module added as a dependency above, checks the module type, and registers the
|
// Visits the base module added as a dependency above, checks the module type, and registers the
|
||||||
|
|
|
@ -155,6 +155,44 @@ var prebuiltsTests = []struct {
|
||||||
}`,
|
}`,
|
||||||
prebuilt: []OsClass{Host},
|
prebuilt: []OsClass{Host},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "prebuilt override not preferred",
|
||||||
|
modules: `
|
||||||
|
source {
|
||||||
|
name: "baz",
|
||||||
|
}
|
||||||
|
|
||||||
|
override_source {
|
||||||
|
name: "bar",
|
||||||
|
base: "baz",
|
||||||
|
}
|
||||||
|
|
||||||
|
prebuilt {
|
||||||
|
name: "bar",
|
||||||
|
prefer: false,
|
||||||
|
srcs: ["prebuilt_file"],
|
||||||
|
}`,
|
||||||
|
prebuilt: nil,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "prebuilt override preferred",
|
||||||
|
modules: `
|
||||||
|
source {
|
||||||
|
name: "baz",
|
||||||
|
}
|
||||||
|
|
||||||
|
override_source {
|
||||||
|
name: "bar",
|
||||||
|
base: "baz",
|
||||||
|
}
|
||||||
|
|
||||||
|
prebuilt {
|
||||||
|
name: "bar",
|
||||||
|
prefer: true,
|
||||||
|
srcs: ["prebuilt_file"],
|
||||||
|
}`,
|
||||||
|
prebuilt: []OsClass{Device, Host},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrebuilts(t *testing.T) {
|
func TestPrebuilts(t *testing.T) {
|
||||||
|
@ -256,8 +294,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 {
|
||||||
|
@ -300,11 +340,15 @@ func (p *prebuiltModule) OutputFiles(tag string) (Paths, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type sourceModuleProperties struct {
|
||||||
|
Deps []string `android:"path,arch_variant"`
|
||||||
|
}
|
||||||
|
|
||||||
type sourceModule struct {
|
type sourceModule struct {
|
||||||
ModuleBase
|
ModuleBase
|
||||||
properties struct {
|
OverridableModuleBase
|
||||||
Deps []string `android:"path,arch_variant"`
|
|
||||||
}
|
properties sourceModuleProperties
|
||||||
dependsOnSourceModule, dependsOnPrebuiltModule bool
|
dependsOnSourceModule, dependsOnPrebuiltModule bool
|
||||||
deps Paths
|
deps Paths
|
||||||
src Path
|
src Path
|
||||||
|
@ -314,10 +358,11 @@ func newSourceModule() Module {
|
||||||
m := &sourceModule{}
|
m := &sourceModule{}
|
||||||
m.AddProperties(&m.properties)
|
m.AddProperties(&m.properties)
|
||||||
InitAndroidArchModule(m, HostAndDeviceDefault, MultilibCommon)
|
InitAndroidArchModule(m, HostAndDeviceDefault, MultilibCommon)
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
@ -330,3 +375,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{})
|
||||||
|
|
||||||
|
InitAndroidArchModule(m, HostAndDeviceDefault, MultilibCommon)
|
||||||
|
InitOverrideModule(m)
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue