7089c27c07
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
144 lines
4.4 KiB
Go
144 lines
4.4 KiB
Go
// Copyright 2017 Google Inc. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package main
|
|
|
|
import (
|
|
"android/soong/android"
|
|
"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 {
|
|
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{}{
|
|
"unique": func() int {
|
|
unique++
|
|
return unique
|
|
}}).Parse(fileTemplate)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = tmpl.Execute(buf, moduleTypeList)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = ioutil.WriteFile(filename, buf.Bytes(), 0666)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
const (
|
|
fileTemplate = `
|
|
<html>
|
|
<head>
|
|
<title>Build Docs</title>
|
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
|
|
</head>
|
|
<body>
|
|
<h1>Build Docs</h1>
|
|
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
|
|
{{range .}}
|
|
{{ $collapseIndex := unique }}
|
|
<div class="panel panel-default">
|
|
<div class="panel-heading" role="tab" id="heading{{$collapseIndex}}">
|
|
<h2 class="panel-title">
|
|
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse{{$collapseIndex}}" aria-expanded="false" aria-controls="collapse{{$collapseIndex}}">
|
|
{{.Name}}
|
|
</a>
|
|
</h2>
|
|
</div>
|
|
</div>
|
|
<div id="collapse{{$collapseIndex}}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading{{$collapseIndex}}">
|
|
<div class="panel-body">
|
|
<p>{{.Text}}</p>
|
|
{{range .PropertyStructs}}
|
|
<p>{{.Text}}</p>
|
|
{{template "properties" .Properties}}
|
|
{{end}}
|
|
</div>
|
|
</div>
|
|
{{end}}
|
|
</div>
|
|
</body>
|
|
</html>
|
|
|
|
{{define "properties"}}
|
|
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
|
|
{{range .}}
|
|
{{$collapseIndex := unique}}
|
|
{{if .Properties}}
|
|
<div class="panel panel-default">
|
|
<div class="panel-heading" role="tab" id="heading{{$collapseIndex}}">
|
|
<h4 class="panel-title">
|
|
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse{{$collapseIndex}}" aria-expanded="false" aria-controls="collapse{{$collapseIndex}}">
|
|
{{.Name}}{{range .OtherNames}}, {{.}}{{end}}
|
|
</a>
|
|
</h4>
|
|
</div>
|
|
</div>
|
|
<div id="collapse{{$collapseIndex}}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading{{$collapseIndex}}">
|
|
<div class="panel-body">
|
|
<p>{{.Text}}</p>
|
|
{{range .OtherTexts}}<p>{{.}}</p>{{end}}
|
|
{{template "properties" .Properties}}
|
|
</div>
|
|
</div>
|
|
{{else}}
|
|
<div>
|
|
<h4>{{.Name}}{{range .OtherNames}}, {{.}}{{end}}</h4>
|
|
<p>{{.Text}}</p>
|
|
{{range .OtherTexts}}<p>{{.}}</p>{{end}}
|
|
<p><i>Type: {{.Type}}</i></p>
|
|
{{if .Default}}<p><i>Default: {{.Default}}</i></p>{{end}}
|
|
</div>
|
|
{{end}}
|
|
{{end}}
|
|
</div>
|
|
{{end}}
|
|
`
|
|
)
|