Merge "Add phony targets for go binary modules"

This commit is contained in:
Treehugger Robot 2018-09-28 19:45:22 +00:00 committed by Gerrit Code Review
commit e9b16159d5
3 changed files with 38 additions and 13 deletions

View File

@ -25,6 +25,7 @@ import (
"strings"
"github.com/google/blueprint"
"github.com/google/blueprint/bootstrap"
)
func init() {
@ -64,13 +65,13 @@ func (c *androidMkSingleton) GenerateBuildActions(ctx SingletonContext) {
return
}
var androidMkModulesList []Module
var androidMkModulesList []blueprint.Module
ctx.VisitAllModules(func(module Module) {
ctx.VisitAllModulesBlueprint(func(module blueprint.Module) {
androidMkModulesList = append(androidMkModulesList, module)
})
sort.Sort(AndroidModulesByName{androidMkModulesList, ctx})
sort.Sort(ModulesByName{androidMkModulesList, ctx})
transMk := PathForOutput(ctx, "Android"+String(ctx.Config().productVariables.Make_suffix)+".mk")
if ctx.Failed() {
@ -88,7 +89,7 @@ func (c *androidMkSingleton) GenerateBuildActions(ctx SingletonContext) {
})
}
func translateAndroidMk(ctx SingletonContext, mkFile string, mods []Module) error {
func translateAndroidMk(ctx SingletonContext, mkFile string, mods []blueprint.Module) error {
buf := &bytes.Buffer{}
fmt.Fprintln(buf, "LOCAL_MODULE_MAKEFILE := $(lastword $(MAKEFILE_LIST))")
@ -101,8 +102,8 @@ func translateAndroidMk(ctx SingletonContext, mkFile string, mods []Module) erro
return err
}
if ctx.PrimaryModule(mod) == mod {
type_stats[ctx.ModuleType(mod)] += 1
if amod, ok := mod.(Module); ok && ctx.PrimaryModule(amod) == amod {
type_stats[ctx.ModuleType(amod)] += 1
}
}
@ -148,10 +149,29 @@ func translateAndroidMkModule(ctx SingletonContext, w io.Writer, mod blueprint.M
}
}()
provider, ok := mod.(AndroidMkDataProvider)
if !ok {
switch x := mod.(type) {
case AndroidMkDataProvider:
return translateAndroidModule(ctx, w, mod, x)
case bootstrap.GoBinaryTool:
return translateGoBinaryModule(ctx, w, mod, x)
default:
return nil
}
}
func translateGoBinaryModule(ctx SingletonContext, w io.Writer, mod blueprint.Module,
goBinary bootstrap.GoBinaryTool) error {
name := ctx.ModuleName(mod)
fmt.Fprintln(w, ".PHONY:", name)
fmt.Fprintln(w, name+":", goBinary.InstallPath())
fmt.Fprintln(w, "")
return nil
}
func translateAndroidModule(ctx SingletonContext, w io.Writer, mod blueprint.Module,
provider AndroidMkDataProvider) error {
name := provider.BaseModuleName()
amod := mod.(Module).base()

View File

@ -1527,16 +1527,16 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx SingletonContext) {
}
}
type AndroidModulesByName struct {
slice []Module
type ModulesByName struct {
slice []blueprint.Module
ctx interface {
ModuleName(blueprint.Module) string
ModuleSubDir(blueprint.Module) string
}
}
func (s AndroidModulesByName) Len() int { return len(s.slice) }
func (s AndroidModulesByName) Less(i, j int) bool {
func (s ModulesByName) Len() int { return len(s.slice) }
func (s ModulesByName) Less(i, j int) bool {
mi, mj := s.slice[i], s.slice[j]
ni, nj := s.ctx.ModuleName(mi), s.ctx.ModuleName(mj)
@ -1546,7 +1546,7 @@ func (s AndroidModulesByName) Less(i, j int) bool {
return s.ctx.ModuleSubDir(mi) < s.ctx.ModuleSubDir(mj)
}
}
func (s AndroidModulesByName) Swap(i, j int) { s.slice[i], s.slice[j] = s.slice[j], s.slice[i] }
func (s ModulesByName) Swap(i, j int) { s.slice[i], s.slice[j] = s.slice[j], s.slice[i] }
// Collect information for opening IDE project files in java/jdeps.go.
type IDEInfo interface {

View File

@ -48,6 +48,7 @@ type SingletonContext interface {
// are expanded in the scope of the PackageContext.
Eval(pctx PackageContext, ninjaStr string) (string, error)
VisitAllModulesBlueprint(visit func(blueprint.Module))
VisitAllModules(visit func(Module))
VisitAllModulesIf(pred func(Module) bool, visit func(Module))
// Deprecated: use WalkDeps instead to support multiple dependency tags on the same module
@ -138,6 +139,10 @@ func predAdaptor(pred func(Module) bool) func(blueprint.Module) bool {
}
}
func (s singletonContextAdaptor) VisitAllModulesBlueprint(visit func(blueprint.Module)) {
s.SingletonContext.VisitAllModules(visit)
}
func (s singletonContextAdaptor) VisitAllModules(visit func(Module)) {
s.SingletonContext.VisitAllModules(visitAdaptor(visit))
}