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
diff --git a/android/androidmk.go b/android/androidmk.go
index 44c266a..5df4a85 100644
--- a/android/androidmk.go
+++ b/android/androidmk.go
@@ -25,6 +25,7 @@
"strings"
"github.com/google/blueprint"
+ "github.com/google/blueprint/bootstrap"
)
func init() {
@@ -64,13 +65,13 @@
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 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 @@
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 @@
}
}()
- 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 4dc4e9c..92b11ed 100644
--- a/android/module.go
+++ b/android/module.go
@@ -1527,16 +1527,16 @@
}
}
-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 @@
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 fa1efdc..f926435 100644
--- a/android/singleton.go
+++ b/android/singleton.go
@@ -48,6 +48,7 @@
// 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 (s singletonContextAdaptor) VisitAllModulesBlueprint(visit func(blueprint.Module)) {
+ s.SingletonContext.VisitAllModules(visit)
+}
+
func (s singletonContextAdaptor) VisitAllModules(visit func(Module)) {
s.SingletonContext.VisitAllModules(visitAdaptor(visit))
}