Fall back to the source module for variants that the corresponding
prebuilt doesn't define. Test: m Test: "m" on a platform tree with prebuilts/runtime in the manifest Bug: 151303681 Change-Id: I8e10579c5daa79e82009a0c3060cde76cdf520e9
This commit is contained in:
parent
f455d1fb0a
commit
009a9dc4ac
|
@ -111,6 +111,8 @@ type BaseModuleContext interface {
|
||||||
OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
|
OtherModuleErrorf(m blueprint.Module, fmt string, args ...interface{})
|
||||||
OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
|
OtherModuleDependencyTag(m blueprint.Module) blueprint.DependencyTag
|
||||||
OtherModuleExists(name string) bool
|
OtherModuleExists(name string) bool
|
||||||
|
OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool
|
||||||
|
OtherModuleReverseDependencyVariantExists(name string) bool
|
||||||
OtherModuleType(m blueprint.Module) string
|
OtherModuleType(m blueprint.Module) string
|
||||||
|
|
||||||
GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
|
GetDirectDepsWithTag(tag blueprint.DependencyTag) []Module
|
||||||
|
@ -1433,6 +1435,12 @@ func (b *baseModuleContext) OtherModuleDependencyTag(m blueprint.Module) bluepri
|
||||||
return b.bp.OtherModuleDependencyTag(m)
|
return b.bp.OtherModuleDependencyTag(m)
|
||||||
}
|
}
|
||||||
func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
|
func (b *baseModuleContext) OtherModuleExists(name string) bool { return b.bp.OtherModuleExists(name) }
|
||||||
|
func (b *baseModuleContext) OtherModuleDependencyVariantExists(variations []blueprint.Variation, name string) bool {
|
||||||
|
return b.bp.OtherModuleDependencyVariantExists(variations, name)
|
||||||
|
}
|
||||||
|
func (b *baseModuleContext) OtherModuleReverseDependencyVariantExists(name string) bool {
|
||||||
|
return b.bp.OtherModuleReverseDependencyVariantExists(name)
|
||||||
|
}
|
||||||
func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string {
|
func (b *baseModuleContext) OtherModuleType(m blueprint.Module) string {
|
||||||
return b.bp.OtherModuleType(m)
|
return b.bp.OtherModuleType(m)
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,9 @@ type PrebuiltProperties struct {
|
||||||
|
|
||||||
SourceExists bool `blueprint:"mutated"`
|
SourceExists bool `blueprint:"mutated"`
|
||||||
UsePrebuilt bool `blueprint:"mutated"`
|
UsePrebuilt bool `blueprint:"mutated"`
|
||||||
|
|
||||||
|
// Set if the module has been renamed to remove the "prebuilt_" prefix.
|
||||||
|
PrebuiltRenamedToSource bool `blueprint:"mutated"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Prebuilt struct {
|
type Prebuilt struct {
|
||||||
|
@ -188,25 +191,38 @@ type PrebuiltInterface interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterPrebuiltsPreArchMutators(ctx RegisterMutatorsContext) {
|
func RegisterPrebuiltsPreArchMutators(ctx RegisterMutatorsContext) {
|
||||||
ctx.BottomUp("prebuilts", PrebuiltMutator).Parallel()
|
ctx.BottomUp("prebuilt_rename", PrebuiltRenameMutator).Parallel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterPrebuiltsPostDepsMutators(ctx RegisterMutatorsContext) {
|
func RegisterPrebuiltsPostDepsMutators(ctx RegisterMutatorsContext) {
|
||||||
|
ctx.BottomUp("prebuilt_source", PrebuiltSourceDepsMutator).Parallel()
|
||||||
ctx.TopDown("prebuilt_select", PrebuiltSelectModuleMutator).Parallel()
|
ctx.TopDown("prebuilt_select", PrebuiltSelectModuleMutator).Parallel()
|
||||||
ctx.BottomUp("prebuilt_postdeps", PrebuiltPostDepsMutator).Parallel()
|
ctx.BottomUp("prebuilt_postdeps", PrebuiltPostDepsMutator).Parallel()
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrebuiltMutator ensures that there is always a module with an undecorated name, and marks
|
// PrebuiltRenameMutator ensures that there always is a module with an
|
||||||
// prebuilt modules that have both a prebuilt and a source module.
|
// undecorated name.
|
||||||
func PrebuiltMutator(ctx BottomUpMutatorContext) {
|
func PrebuiltRenameMutator(ctx BottomUpMutatorContext) {
|
||||||
|
if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil {
|
||||||
|
name := m.base().BaseModuleName()
|
||||||
|
if !ctx.OtherModuleExists(name) {
|
||||||
|
ctx.Rename(name)
|
||||||
|
m.Prebuilt().properties.PrebuiltRenamedToSource = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrebuiltSourceDepsMutator adds dependencies to the prebuilt module from the
|
||||||
|
// corresponding source module, if one exists for the same variant.
|
||||||
|
func PrebuiltSourceDepsMutator(ctx BottomUpMutatorContext) {
|
||||||
if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil {
|
if m, ok := ctx.Module().(PrebuiltInterface); ok && m.Prebuilt() != nil {
|
||||||
p := m.Prebuilt()
|
p := m.Prebuilt()
|
||||||
name := m.base().BaseModuleName()
|
if !p.properties.PrebuiltRenamedToSource {
|
||||||
if ctx.OtherModuleExists(name) {
|
name := m.base().BaseModuleName()
|
||||||
ctx.AddReverseDependency(ctx.Module(), PrebuiltDepTag, name)
|
if ctx.OtherModuleReverseDependencyVariantExists(name) {
|
||||||
p.properties.SourceExists = true
|
ctx.AddReverseDependency(ctx.Module(), PrebuiltDepTag, name)
|
||||||
} else {
|
p.properties.SourceExists = true
|
||||||
ctx.Rename(name)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ import (
|
||||||
var prebuiltsTests = []struct {
|
var prebuiltsTests = []struct {
|
||||||
name string
|
name string
|
||||||
modules string
|
modules string
|
||||||
prebuilt bool
|
prebuilt []OsClass
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "no prebuilt",
|
name: "no prebuilt",
|
||||||
|
@ -32,7 +32,7 @@ var prebuiltsTests = []struct {
|
||||||
source {
|
source {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
}`,
|
}`,
|
||||||
prebuilt: false,
|
prebuilt: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "no source prebuilt not preferred",
|
name: "no source prebuilt not preferred",
|
||||||
|
@ -42,7 +42,7 @@ var prebuiltsTests = []struct {
|
||||||
prefer: false,
|
prefer: false,
|
||||||
srcs: ["prebuilt_file"],
|
srcs: ["prebuilt_file"],
|
||||||
}`,
|
}`,
|
||||||
prebuilt: true,
|
prebuilt: []OsClass{Device, Host},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "no source prebuilt preferred",
|
name: "no source prebuilt preferred",
|
||||||
|
@ -52,7 +52,7 @@ var prebuiltsTests = []struct {
|
||||||
prefer: true,
|
prefer: true,
|
||||||
srcs: ["prebuilt_file"],
|
srcs: ["prebuilt_file"],
|
||||||
}`,
|
}`,
|
||||||
prebuilt: true,
|
prebuilt: []OsClass{Device, Host},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "prebuilt not preferred",
|
name: "prebuilt not preferred",
|
||||||
|
@ -60,13 +60,13 @@ var prebuiltsTests = []struct {
|
||||||
source {
|
source {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
}
|
}
|
||||||
|
|
||||||
prebuilt {
|
prebuilt {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
prefer: false,
|
prefer: false,
|
||||||
srcs: ["prebuilt_file"],
|
srcs: ["prebuilt_file"],
|
||||||
}`,
|
}`,
|
||||||
prebuilt: false,
|
prebuilt: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "prebuilt preferred",
|
name: "prebuilt preferred",
|
||||||
|
@ -74,13 +74,13 @@ var prebuiltsTests = []struct {
|
||||||
source {
|
source {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
}
|
}
|
||||||
|
|
||||||
prebuilt {
|
prebuilt {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
prefer: true,
|
prefer: true,
|
||||||
srcs: ["prebuilt_file"],
|
srcs: ["prebuilt_file"],
|
||||||
}`,
|
}`,
|
||||||
prebuilt: true,
|
prebuilt: []OsClass{Device, Host},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "prebuilt no file not preferred",
|
name: "prebuilt no file not preferred",
|
||||||
|
@ -88,12 +88,12 @@ var prebuiltsTests = []struct {
|
||||||
source {
|
source {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
}
|
}
|
||||||
|
|
||||||
prebuilt {
|
prebuilt {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
prefer: false,
|
prefer: false,
|
||||||
}`,
|
}`,
|
||||||
prebuilt: false,
|
prebuilt: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "prebuilt no file preferred",
|
name: "prebuilt no file preferred",
|
||||||
|
@ -101,12 +101,12 @@ var prebuiltsTests = []struct {
|
||||||
source {
|
source {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
}
|
}
|
||||||
|
|
||||||
prebuilt {
|
prebuilt {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
prefer: true,
|
prefer: true,
|
||||||
}`,
|
}`,
|
||||||
prebuilt: false,
|
prebuilt: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "prebuilt file from filegroup preferred",
|
name: "prebuilt file from filegroup preferred",
|
||||||
|
@ -120,7 +120,40 @@ var prebuiltsTests = []struct {
|
||||||
prefer: true,
|
prefer: true,
|
||||||
srcs: [":fg"],
|
srcs: [":fg"],
|
||||||
}`,
|
}`,
|
||||||
prebuilt: true,
|
prebuilt: []OsClass{Device, Host},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "prebuilt module for device only",
|
||||||
|
modules: `
|
||||||
|
source {
|
||||||
|
name: "bar",
|
||||||
|
}
|
||||||
|
|
||||||
|
prebuilt {
|
||||||
|
name: "bar",
|
||||||
|
host_supported: false,
|
||||||
|
prefer: true,
|
||||||
|
srcs: ["prebuilt_file"],
|
||||||
|
}`,
|
||||||
|
prebuilt: []OsClass{Device},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "prebuilt file for host only",
|
||||||
|
modules: `
|
||||||
|
source {
|
||||||
|
name: "bar",
|
||||||
|
}
|
||||||
|
|
||||||
|
prebuilt {
|
||||||
|
name: "bar",
|
||||||
|
prefer: true,
|
||||||
|
target: {
|
||||||
|
linux_glibc: {
|
||||||
|
srcs: ["prebuilt_file"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}`,
|
||||||
|
prebuilt: []OsClass{Host},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,9 +171,9 @@ func TestPrebuilts(t *testing.T) {
|
||||||
deps: [":bar"],
|
deps: [":bar"],
|
||||||
}
|
}
|
||||||
` + test.modules
|
` + test.modules
|
||||||
config := TestConfig(buildDir, nil, bp, fs)
|
config := TestArchConfig(buildDir, nil, bp, fs)
|
||||||
|
|
||||||
ctx := NewTestContext()
|
ctx := NewTestArchContext()
|
||||||
registerTestPrebuiltBuildComponents(ctx)
|
registerTestPrebuiltBuildComponents(ctx)
|
||||||
ctx.RegisterModuleType("filegroup", FileGroupFactory)
|
ctx.RegisterModuleType("filegroup", FileGroupFactory)
|
||||||
ctx.Register(config)
|
ctx.Register(config)
|
||||||
|
@ -150,61 +183,71 @@ func TestPrebuilts(t *testing.T) {
|
||||||
_, errs = ctx.PrepareBuildActions(config)
|
_, errs = ctx.PrepareBuildActions(config)
|
||||||
FailIfErrored(t, errs)
|
FailIfErrored(t, errs)
|
||||||
|
|
||||||
foo := ctx.ModuleForTests("foo", "")
|
for _, variant := range ctx.ModuleVariantsForTests("foo") {
|
||||||
|
foo := ctx.ModuleForTests("foo", variant)
|
||||||
|
t.Run(foo.Module().Target().Os.Class.String(), func(t *testing.T) {
|
||||||
|
var dependsOnSourceModule, dependsOnPrebuiltModule bool
|
||||||
|
ctx.VisitDirectDeps(foo.Module(), func(m blueprint.Module) {
|
||||||
|
if _, ok := m.(*sourceModule); ok {
|
||||||
|
dependsOnSourceModule = true
|
||||||
|
}
|
||||||
|
if p, ok := m.(*prebuiltModule); ok {
|
||||||
|
dependsOnPrebuiltModule = true
|
||||||
|
if !p.Prebuilt().properties.UsePrebuilt {
|
||||||
|
t.Errorf("dependency on prebuilt module not marked used")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
var dependsOnSourceModule, dependsOnPrebuiltModule bool
|
deps := foo.Module().(*sourceModule).deps
|
||||||
ctx.VisitDirectDeps(foo.Module(), func(m blueprint.Module) {
|
if deps == nil || len(deps) != 1 {
|
||||||
if _, ok := m.(*sourceModule); ok {
|
t.Errorf("deps does not have single path, but is %v", deps)
|
||||||
dependsOnSourceModule = true
|
}
|
||||||
}
|
var usingSourceFile, usingPrebuiltFile bool
|
||||||
if p, ok := m.(*prebuiltModule); ok {
|
if deps[0].String() == "source_file" {
|
||||||
dependsOnPrebuiltModule = true
|
usingSourceFile = true
|
||||||
if !p.Prebuilt().properties.UsePrebuilt {
|
}
|
||||||
t.Errorf("dependency on prebuilt module not marked used")
|
if deps[0].String() == "prebuilt_file" {
|
||||||
|
usingPrebuiltFile = true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
deps := foo.Module().(*sourceModule).deps
|
prebuilt := false
|
||||||
if deps == nil || len(deps) != 1 {
|
for _, os := range test.prebuilt {
|
||||||
t.Errorf("deps does not have single path, but is %v", deps)
|
if os == foo.Module().Target().Os.Class {
|
||||||
}
|
prebuilt = true
|
||||||
var usingSourceFile, usingPrebuiltFile bool
|
}
|
||||||
if deps[0].String() == "source_file" {
|
}
|
||||||
usingSourceFile = true
|
|
||||||
}
|
|
||||||
if deps[0].String() == "prebuilt_file" {
|
|
||||||
usingPrebuiltFile = true
|
|
||||||
}
|
|
||||||
|
|
||||||
if test.prebuilt {
|
if prebuilt {
|
||||||
if !dependsOnPrebuiltModule {
|
if !dependsOnPrebuiltModule {
|
||||||
t.Errorf("doesn't depend on prebuilt module")
|
t.Errorf("doesn't depend on prebuilt module")
|
||||||
}
|
}
|
||||||
if !usingPrebuiltFile {
|
if !usingPrebuiltFile {
|
||||||
t.Errorf("doesn't use prebuilt_file")
|
t.Errorf("doesn't use prebuilt_file")
|
||||||
}
|
}
|
||||||
|
|
||||||
if dependsOnSourceModule {
|
if dependsOnSourceModule {
|
||||||
t.Errorf("depends on source module")
|
t.Errorf("depends on source module")
|
||||||
}
|
}
|
||||||
if usingSourceFile {
|
if usingSourceFile {
|
||||||
t.Errorf("using source_file")
|
t.Errorf("using source_file")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if dependsOnPrebuiltModule {
|
if dependsOnPrebuiltModule {
|
||||||
t.Errorf("depends on prebuilt module")
|
t.Errorf("depends on prebuilt module")
|
||||||
}
|
}
|
||||||
if usingPrebuiltFile {
|
if usingPrebuiltFile {
|
||||||
t.Errorf("using prebuilt_file")
|
t.Errorf("using prebuilt_file")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !dependsOnSourceModule {
|
if !dependsOnSourceModule {
|
||||||
t.Errorf("doesn't depend on source module")
|
t.Errorf("doesn't depend on source module")
|
||||||
}
|
}
|
||||||
if !usingSourceFile {
|
if !usingSourceFile {
|
||||||
t.Errorf("doesn't use source_file")
|
t.Errorf("doesn't use source_file")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -221,7 +264,7 @@ type prebuiltModule struct {
|
||||||
ModuleBase
|
ModuleBase
|
||||||
prebuilt Prebuilt
|
prebuilt Prebuilt
|
||||||
properties struct {
|
properties struct {
|
||||||
Srcs []string `android:"path"`
|
Srcs []string `android:"path,arch_variant"`
|
||||||
}
|
}
|
||||||
src Path
|
src Path
|
||||||
}
|
}
|
||||||
|
@ -230,7 +273,7 @@ func newPrebuiltModule() Module {
|
||||||
m := &prebuiltModule{}
|
m := &prebuiltModule{}
|
||||||
m.AddProperties(&m.properties)
|
m.AddProperties(&m.properties)
|
||||||
InitPrebuiltModule(m, &m.properties.Srcs)
|
InitPrebuiltModule(m, &m.properties.Srcs)
|
||||||
InitAndroidModule(m)
|
InitAndroidArchModule(m, HostAndDeviceDefault, MultilibCommon)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -260,7 +303,7 @@ func (p *prebuiltModule) OutputFiles(tag string) (Paths, error) {
|
||||||
type sourceModule struct {
|
type sourceModule struct {
|
||||||
ModuleBase
|
ModuleBase
|
||||||
properties struct {
|
properties struct {
|
||||||
Deps []string `android:"path"`
|
Deps []string `android:"path,arch_variant"`
|
||||||
}
|
}
|
||||||
dependsOnSourceModule, dependsOnPrebuiltModule bool
|
dependsOnSourceModule, dependsOnPrebuiltModule bool
|
||||||
deps Paths
|
deps Paths
|
||||||
|
@ -270,7 +313,7 @@ type sourceModule struct {
|
||||||
func newSourceModule() Module {
|
func newSourceModule() Module {
|
||||||
m := &sourceModule{}
|
m := &sourceModule{}
|
||||||
m.AddProperties(&m.properties)
|
m.AddProperties(&m.properties)
|
||||||
InitAndroidModule(m)
|
InitAndroidArchModule(m, HostAndDeviceDefault, MultilibCommon)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue