Merge "Update Soong docs generator for blueprint changes"
This commit is contained in:
commit
dfa4a486eb
|
@ -20,7 +20,7 @@ import (
|
||||||
|
|
||||||
type moduleType struct {
|
type moduleType struct {
|
||||||
name string
|
name string
|
||||||
factory blueprint.ModuleFactory
|
factory ModuleFactory
|
||||||
}
|
}
|
||||||
|
|
||||||
var moduleTypes []moduleType
|
var moduleTypes []moduleType
|
||||||
|
@ -40,8 +40,6 @@ type mutator struct {
|
||||||
parallel bool
|
parallel bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var mutators []*mutator
|
|
||||||
|
|
||||||
type ModuleFactory func() Module
|
type ModuleFactory func() Module
|
||||||
|
|
||||||
// ModuleFactoryAdaptor wraps a ModuleFactory into a blueprint.ModuleFactory by converting a 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) {
|
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) {
|
func RegisterSingletonType(name string, factory SingletonFactory) {
|
||||||
|
@ -90,7 +88,7 @@ func (ctx *Context) Register() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, t := range moduleTypes {
|
for _, t := range moduleTypes {
|
||||||
ctx.RegisterModuleType(t.name, t.factory)
|
ctx.RegisterModuleType(t.name, ModuleFactoryAdaptor(t.factory))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, t := range singletons {
|
for _, t := range singletons {
|
||||||
|
@ -105,3 +103,11 @@ func (ctx *Context) Register() {
|
||||||
// Register env last so that it can track all used environment variables
|
// Register env last so that it can track all used environment variables
|
||||||
ctx.RegisterSingletonType("env", SingletonFactoryAdaptor(EnvSingleton))
|
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)
|
bootstrap.Main(ctx.Context, configuration, configuration.ConfigFileName, configuration.ProductVariablesFileName)
|
||||||
|
|
||||||
if docFile != "" {
|
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"
|
"bytes"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"reflect"
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/google/blueprint/bootstrap"
|
"github.com/google/blueprint/bootstrap"
|
||||||
|
"github.com/google/blueprint/bootstrap/bpdoc"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeDocs(ctx *android.Context, filename string) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
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
|
unique := 0
|
||||||
|
|
||||||
tmpl, err := template.New("file").Funcs(map[string]interface{}{
|
tmpl, err := template.New("file").Funcs(map[string]interface{}{
|
||||||
|
|
Loading…
Reference in New Issue