4572edddfa
The primary builder will now generate a rule to call itself with --docs=.bootstrap/docs/<name>.html to produce an automatically generated documentation file. The documentation generation process is: - Call each factory once to get empty property structs associated with the module type - Use reflection to determine the names of the type of each property struct - Use the bootstrap_go_package modules from reading the Blueprints files to find the source files for each Go package used to build the primary builder - Use the go/parser module to find the type declaration for each property struct - Extract comments for the property struct and each property declaration - Format all the comments into HTML Change-Id: Icae9307cc10549a30bfc14d6922824099de5a9b0
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package bootstrap
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
|
|
"github.com/google/blueprint"
|
|
"github.com/google/blueprint/bootstrap/bpdoc"
|
|
"github.com/google/blueprint/pathtools"
|
|
)
|
|
|
|
func writeDocs(ctx *blueprint.Context, srcDir, filename string) error {
|
|
// Find the module that's marked as the "primary builder", which means it's
|
|
// creating the binary that we'll use to generate the non-bootstrap
|
|
// build.ninja file.
|
|
var primaryBuilders []*goBinary
|
|
var minibp *goBinary
|
|
ctx.VisitAllModulesIf(isBootstrapBinaryModule,
|
|
func(module blueprint.Module) {
|
|
binaryModule := module.(*goBinary)
|
|
if binaryModule.properties.PrimaryBuilder {
|
|
primaryBuilders = append(primaryBuilders, binaryModule)
|
|
}
|
|
if ctx.ModuleName(binaryModule) == "minibp" {
|
|
minibp = binaryModule
|
|
}
|
|
})
|
|
|
|
if minibp == nil {
|
|
panic("missing minibp")
|
|
}
|
|
|
|
var primaryBuilder *goBinary
|
|
switch len(primaryBuilders) {
|
|
case 0:
|
|
// If there's no primary builder module then that means we'll use minibp
|
|
// as the primary builder.
|
|
primaryBuilder = minibp
|
|
|
|
case 1:
|
|
primaryBuilder = primaryBuilders[0]
|
|
|
|
default:
|
|
return fmt.Errorf("multiple primary builder modules present")
|
|
}
|
|
|
|
pkgFiles := make(map[string][]string)
|
|
ctx.VisitDepsDepthFirst(primaryBuilder, func(module blueprint.Module) {
|
|
switch m := module.(type) {
|
|
case (*goPackage):
|
|
pkgFiles[m.properties.PkgPath] = pathtools.PrefixPaths(m.properties.Srcs,
|
|
filepath.Join(srcDir, ctx.ModuleDir(m)))
|
|
default:
|
|
panic(fmt.Errorf("unknown dependency type %T", module))
|
|
}
|
|
})
|
|
|
|
return bpdoc.Write(filename, pkgFiles, ctx.ModuleTypePropertyStructs())
|
|
}
|