From 2465c3d99833988c726a145896bf180f304de18b Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 28 Sep 2018 10:19:18 -0700 Subject: [PATCH] Add phony targets for go binary modules Add custom handling to androidmk.go for the bootstrap.GoBinaryTool interface in order to create .PHONY targets for each tool written in go. Bug: 64539926 Test: m checkbuild Test: m androidmk Test: m multiproduct_kati Change-Id: Ic65faa27a6ee4dfbd54ed6d208091db7c1d657a2 --- android/androidmk.go | 36 ++++++++++++++++++++++++++++-------- android/module.go | 10 +++++----- android/singleton.go | 5 +++++ 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/android/androidmk.go b/android/androidmk.go index 44c266ad3..5df4a8560 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -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() diff --git a/android/module.go b/android/module.go index 4dc4e9c32..92b11ed0d 100644 --- a/android/module.go +++ b/android/module.go @@ -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 { diff --git a/android/singleton.go b/android/singleton.go index fa1efdc0f..f926435b1 100644 --- a/android/singleton.go +++ b/android/singleton.go @@ -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)) }