Fall back to prebuilts if source modules are disabled

In lieu of having an environment variable to override prebuilts
preferences (for now), fall back to prebuilts whenever the source
module is disabled.  Complicated source modules (like LLVM) that
already have Go logic can then use an environment variariable to
disable their source module whenever they want to use prebuilts.

Computes UsePrebuilt once using information from both the source
and prebuilt modules, and stores the result in the prebuilt module.

Test: m -j libLLVM
Test: m -j libLLVM FORCE_BUILD_LLVM_COMPONENTS=true
Change-Id: Ib0819a03e9492e55f55de3402e05b3a043644a39
This commit is contained in:
Colin Cross 2016-11-29 15:16:18 -08:00
parent 99d7c23006
commit a2f296f054
3 changed files with 31 additions and 36 deletions

View File

@ -100,6 +100,7 @@ type Module interface {
Enabled() bool Enabled() bool
Target() Target Target() Target
InstallInData() bool InstallInData() bool
SkipInstall()
} }
type nameProperties struct { type nameProperties struct {

View File

@ -46,8 +46,8 @@ func registerMutators() {
ctx.BottomUp("deps", depsMutator).Parallel() ctx.BottomUp("deps", depsMutator).Parallel()
ctx.TopDown("prebuilt_select", PrebuiltSelectModuleMutator).Parallel()
ctx.BottomUp("prebuilt_replace", PrebuiltReplaceMutator).Parallel() ctx.BottomUp("prebuilt_replace", PrebuiltReplaceMutator).Parallel()
ctx.TopDown("prebuilt_disable", PrebuiltDisableMutator).Parallel()
register(postDeps) register(postDeps)
} }

View File

@ -21,20 +21,6 @@ import "github.com/google/blueprint"
var prebuiltDependencyTag blueprint.BaseDependencyTag var prebuiltDependencyTag blueprint.BaseDependencyTag
func SourceModuleHasPrebuilt(ctx ModuleContext) OptionalPath {
var path Path
ctx.VisitDirectDeps(func(m blueprint.Module) {
if ctx.OtherModuleDependencyTag(m) == prebuiltDependencyTag {
p := m.(PrebuiltInterface).Prebuilt()
if p.usePrebuilt(ctx) {
path = p.Path(ctx)
}
}
})
return OptionalPathForPath(path)
}
type Prebuilt struct { type Prebuilt struct {
Properties struct { Properties struct {
Srcs []string `android:"arch_variant"` Srcs []string `android:"arch_variant"`
@ -43,6 +29,7 @@ type Prebuilt struct {
Prefer bool `android:"arch_variant"` Prefer bool `android:"arch_variant"`
SourceExists bool `blueprint:"mutated"` SourceExists bool `blueprint:"mutated"`
UsePrebuilt bool `blueprint:"mutated"`
} }
module Module module Module
} }
@ -68,11 +55,6 @@ func (p *Prebuilt) Path(ctx ModuleContext) Path {
type PrebuiltInterface interface { type PrebuiltInterface interface {
Module Module
Prebuilt() *Prebuilt Prebuilt() *Prebuilt
SkipInstall()
}
type PrebuiltSourceInterface interface {
SkipInstall()
} }
// prebuiltMutator ensures that there is always a module with an undecorated name, and marks // prebuiltMutator ensures that there is always a module with an undecorated name, and marks
@ -90,6 +72,22 @@ func prebuiltMutator(ctx BottomUpMutatorContext) {
} }
} }
// PrebuiltSelectModuleMutator marks prebuilts that are overriding source modules, and disables
// installing the source module.
func PrebuiltSelectModuleMutator(ctx TopDownMutatorContext) {
if s, ok := ctx.Module().(Module); ok {
ctx.VisitDirectDeps(func(m blueprint.Module) {
if ctx.OtherModuleDependencyTag(m) == prebuiltDependencyTag {
p := m.(PrebuiltInterface).Prebuilt()
if p.usePrebuilt(ctx, s) {
p.Properties.UsePrebuilt = true
s.SkipInstall()
}
}
})
}
}
// PrebuiltReplaceMutator replaces dependencies on the source module with dependencies on the // PrebuiltReplaceMutator replaces dependencies on the source module with dependencies on the
// prebuilt when both modules exist and the prebuilt should be used. When the prebuilt should not // prebuilt when both modules exist and the prebuilt should be used. When the prebuilt should not
// be used, disable installing it. // be used, disable installing it.
@ -97,7 +95,7 @@ func PrebuiltReplaceMutator(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() name := m.base().BaseModuleName()
if p.usePrebuilt(ctx) { if p.Properties.UsePrebuilt {
if p.Properties.SourceExists { if p.Properties.SourceExists {
ctx.ReplaceDependencies(name) ctx.ReplaceDependencies(name)
} }
@ -107,21 +105,17 @@ func PrebuiltReplaceMutator(ctx BottomUpMutatorContext) {
} }
} }
// PrebuiltDisableMutator disables source modules that have prebuilts that should be used instead. // usePrebuilt returns true if a prebuilt should be used instead of the source module. The prebuilt
func PrebuiltDisableMutator(ctx TopDownMutatorContext) { // will be used if it is marked "prefer" or if the source module is disabled.
if s, ok := ctx.Module().(PrebuiltSourceInterface); ok { func (p *Prebuilt) usePrebuilt(ctx TopDownMutatorContext, source Module) bool {
ctx.VisitDirectDeps(func(m blueprint.Module) { if len(p.Properties.Srcs) == 0 {
if ctx.OtherModuleDependencyTag(m) == prebuiltDependencyTag { return false
p := m.(PrebuiltInterface).Prebuilt()
if p.usePrebuilt(ctx) {
s.SkipInstall()
}
}
})
} }
}
func (p *Prebuilt) usePrebuilt(ctx BaseContext) bool { // TODO: use p.Properties.Name and ctx.ModuleDir to override preference
// TODO: use p.Properties.Name and ctx.ModuleDir to override prefer if p.Properties.Prefer {
return p.Properties.Prefer && len(p.Properties.Srcs) > 0 return true
}
return !source.Enabled()
} }