From 7089c27c07afef014b49455e41dc586f6d418b3f Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 25 Jan 2019 22:43:35 -0800 Subject: [PATCH] Update Soong docs generator for blueprint changes bootstrap.ModuleTypeDocs needs a mapping of module types to factories to support factories that are wrapped in ModuleFactoryAdapter closures. It also returns ModuleType objects grouped into Package objects. Bug: 67909957 Test: m soong_docs Change-Id: I70eac9f0f0e13075580da92d4219792ca0b18fbf --- android/register.go | 16 +++++++++++----- cmd/soong_build/main.go | 6 +++++- cmd/soong_build/writedocs.go | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/android/register.go b/android/register.go index 10e14fe02..19745fedb 100644 --- a/android/register.go +++ b/android/register.go @@ -20,7 +20,7 @@ import ( type moduleType struct { name string - factory blueprint.ModuleFactory + factory ModuleFactory } var moduleTypes []moduleType @@ -40,8 +40,6 @@ type mutator struct { parallel bool } -var mutators []*mutator - type ModuleFactory func() Module // ModuleFactoryAdaptor wraps a ModuleFactory into a blueprint.ModuleFactory by converting a Module @@ -65,7 +63,7 @@ func SingletonFactoryAdaptor(factory SingletonFactory) blueprint.SingletonFactor } func RegisterModuleType(name string, factory ModuleFactory) { - moduleTypes = append(moduleTypes, moduleType{name, ModuleFactoryAdaptor(factory)}) + moduleTypes = append(moduleTypes, moduleType{name, factory}) } func RegisterSingletonType(name string, factory SingletonFactory) { @@ -90,7 +88,7 @@ func (ctx *Context) Register() { } for _, t := range moduleTypes { - ctx.RegisterModuleType(t.name, t.factory) + ctx.RegisterModuleType(t.name, ModuleFactoryAdaptor(t.factory)) } for _, t := range singletons { @@ -105,3 +103,11 @@ func (ctx *Context) Register() { // Register env last so that it can track all used environment variables ctx.RegisterSingletonType("env", SingletonFactoryAdaptor(EnvSingleton)) } + +func ModuleTypeFactories() map[string]ModuleFactory { + ret := make(map[string]ModuleFactory) + for _, t := range moduleTypes { + ret[t.name] = t.factory + } + return ret +} diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go index a4c6898d5..1f6002ee2 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -75,6 +75,10 @@ func main() { bootstrap.Main(ctx.Context, configuration, configuration.ConfigFileName, configuration.ProductVariablesFileName) if docFile != "" { - writeDocs(ctx, docFile) + err := writeDocs(ctx, docFile) + if err != nil { + fmt.Fprintf(os.Stderr, "%s", err) + os.Exit(1) + } } } diff --git a/cmd/soong_build/writedocs.go b/cmd/soong_build/writedocs.go index a6686c0db..8f86b3321 100644 --- a/cmd/soong_build/writedocs.go +++ b/cmd/soong_build/writedocs.go @@ -19,18 +19,33 @@ import ( "bytes" "html/template" "io/ioutil" + "reflect" + "sort" "github.com/google/blueprint/bootstrap" + "github.com/google/blueprint/bootstrap/bpdoc" ) func writeDocs(ctx *android.Context, filename string) error { - moduleTypeList, err := bootstrap.ModuleTypeDocs(ctx.Context) + moduleTypeFactories := android.ModuleTypeFactories() + bpModuleTypeFactories := make(map[string]reflect.Value) + for moduleType, factory := range moduleTypeFactories { + bpModuleTypeFactories[moduleType] = reflect.ValueOf(factory) + } + + packages, err := bootstrap.ModuleTypeDocs(ctx.Context, bpModuleTypeFactories) if err != nil { return err } buf := &bytes.Buffer{} + var moduleTypeList []*bpdoc.ModuleType + for _, pkg := range packages { + moduleTypeList = append(moduleTypeList, pkg.ModuleTypes...) + } + sort.Slice(moduleTypeList, func(i, j int) bool { return moduleTypeList[i].Name < moduleTypeList[j].Name }) + unique := 0 tmpl, err := template.New("file").Funcs(map[string]interface{}{