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
This commit is contained in:
committed by
Jaewoong Jung
parent
1b16b0e031
commit
7089c27c07
@@ -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
|
||||
}
|
||||
|
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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{}{
|
||||
|
Reference in New Issue
Block a user