Merge "Update Soong docs generator for blueprint changes"

This commit is contained in:
Jaewoong Jung 2019-02-14 01:51:04 +00:00 committed by Gerrit Code Review
commit dfa4a486eb
3 changed files with 32 additions and 7 deletions

View File

@ -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
}

View File

@ -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)
}
}
}

View File

@ -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{}{