2017-12-12 00:52:26 +01:00
|
|
|
// 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"
|
2019-02-20 16:12:30 +01:00
|
|
|
"path/filepath"
|
2019-01-26 07:43:35 +01:00
|
|
|
"reflect"
|
|
|
|
"sort"
|
2017-12-12 00:52:26 +01:00
|
|
|
|
|
|
|
"github.com/google/blueprint/bootstrap"
|
2019-01-26 07:43:35 +01:00
|
|
|
"github.com/google/blueprint/bootstrap/bpdoc"
|
2017-12-12 00:52:26 +01:00
|
|
|
)
|
|
|
|
|
2019-02-20 16:12:30 +01:00
|
|
|
type perPackageTemplateData struct {
|
|
|
|
Name string
|
|
|
|
Modules []moduleTypeTemplateData
|
|
|
|
}
|
|
|
|
|
2019-02-07 21:10:56 +01:00
|
|
|
type moduleTypeTemplateData struct {
|
|
|
|
Name string
|
2019-03-11 22:35:41 +01:00
|
|
|
Synopsis template.HTML
|
2019-02-07 21:10:56 +01:00
|
|
|
Properties []bpdoc.Property
|
|
|
|
}
|
|
|
|
|
|
|
|
// The properties in this map are displayed first, according to their rank.
|
|
|
|
// TODO(jungjw): consider providing module type-dependent ranking
|
|
|
|
var propertyRank = map[string]int{
|
|
|
|
"name": 0,
|
|
|
|
"src": 1,
|
|
|
|
"srcs": 2,
|
|
|
|
"defautls": 3,
|
|
|
|
"host_supported": 4,
|
|
|
|
"device_supported": 5,
|
|
|
|
}
|
|
|
|
|
|
|
|
// For each module type, extract its documentation and convert it to the template data.
|
2019-02-20 16:12:30 +01:00
|
|
|
func moduleTypeDocsToTemplates(moduleTypeList []*bpdoc.ModuleType) []moduleTypeTemplateData {
|
2019-02-07 21:10:56 +01:00
|
|
|
result := make([]moduleTypeTemplateData, 0)
|
2017-12-12 00:52:26 +01:00
|
|
|
|
2019-02-07 21:10:56 +01:00
|
|
|
// Combine properties from all PropertyStruct's and reorder them -- first the ones
|
|
|
|
// with rank, then the rest of the properties in alphabetic order.
|
|
|
|
for _, m := range moduleTypeList {
|
|
|
|
item := moduleTypeTemplateData{
|
|
|
|
Name: m.Name,
|
|
|
|
Synopsis: m.Text,
|
|
|
|
Properties: make([]bpdoc.Property, 0),
|
|
|
|
}
|
|
|
|
props := make([]bpdoc.Property, 0)
|
|
|
|
for _, propStruct := range m.PropertyStructs {
|
|
|
|
props = append(props, propStruct.Properties...)
|
|
|
|
}
|
|
|
|
sort.Slice(props, func(i, j int) bool {
|
|
|
|
if rankI, ok := propertyRank[props[i].Name]; ok {
|
|
|
|
if rankJ, ok := propertyRank[props[j].Name]; ok {
|
|
|
|
return rankI < rankJ
|
|
|
|
} else {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _, ok := propertyRank[props[j].Name]; ok {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return props[i].Name < props[j].Name
|
|
|
|
})
|
|
|
|
// Eliminate top-level duplicates. TODO(jungjw): improve bpdoc to handle this.
|
|
|
|
previousPropertyName := ""
|
|
|
|
for _, prop := range props {
|
|
|
|
if prop.Name == previousPropertyName {
|
|
|
|
oldProp := &item.Properties[len(item.Properties)-1].Properties
|
|
|
|
bpdoc.CollapseDuplicateProperties(oldProp, &prop.Properties)
|
|
|
|
} else {
|
|
|
|
item.Properties = append(item.Properties, prop)
|
|
|
|
}
|
|
|
|
previousPropertyName = prop.Name
|
|
|
|
}
|
|
|
|
result = append(result, item)
|
2017-12-12 00:52:26 +01:00
|
|
|
}
|
2019-02-07 21:10:56 +01:00
|
|
|
sort.Slice(result, func(i, j int) bool { return result[i].Name < result[j].Name })
|
2019-02-20 16:12:30 +01:00
|
|
|
return result
|
2019-02-07 21:10:56 +01:00
|
|
|
}
|
2017-12-12 00:52:26 +01:00
|
|
|
|
2019-02-07 21:10:56 +01:00
|
|
|
func writeDocs(ctx *android.Context, filename string) error {
|
2019-02-20 16:12:30 +01:00
|
|
|
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
|
|
|
|
}
|
2017-12-12 00:52:26 +01:00
|
|
|
|
2019-02-20 16:12:30 +01:00
|
|
|
// Produce the top-level, package list page first.
|
2019-02-22 22:44:38 +01:00
|
|
|
tmpl := template.Must(template.Must(template.New("file").Parse(packageListTemplate)).Parse(copyBaseUrl))
|
2019-02-20 16:12:30 +01:00
|
|
|
buf := &bytes.Buffer{}
|
2019-02-22 22:44:38 +01:00
|
|
|
err = tmpl.Execute(buf, packages)
|
2019-02-07 21:10:56 +01:00
|
|
|
if err == nil {
|
|
|
|
err = ioutil.WriteFile(filename, buf.Bytes(), 0666)
|
|
|
|
}
|
2019-02-20 16:12:30 +01:00
|
|
|
|
|
|
|
// Now, produce per-package module lists with detailed information.
|
|
|
|
for _, pkg := range packages {
|
|
|
|
// We need a module name getter/setter function because I couldn't
|
|
|
|
// find a way to keep it in a variable defined within the template.
|
|
|
|
currentModuleName := ""
|
2019-02-22 22:44:38 +01:00
|
|
|
tmpl := template.Must(
|
|
|
|
template.Must(template.New("file").Funcs(map[string]interface{}{
|
|
|
|
"setModule": func(moduleName string) string {
|
|
|
|
currentModuleName = moduleName
|
|
|
|
return ""
|
|
|
|
},
|
|
|
|
"getModule": func() string {
|
|
|
|
return currentModuleName
|
|
|
|
},
|
|
|
|
}).Parse(perPackageTemplate)).Parse(copyBaseUrl))
|
2019-02-20 16:12:30 +01:00
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
modules := moduleTypeDocsToTemplates(pkg.ModuleTypes)
|
|
|
|
data := perPackageTemplateData{Name: pkg.Name, Modules: modules}
|
|
|
|
err = tmpl.Execute(buf, data)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
pkgFileName := filepath.Join(filepath.Dir(filename), pkg.Name+".html")
|
|
|
|
err = ioutil.WriteFile(pkgFileName, buf.Bytes(), 0666)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2019-02-07 21:10:56 +01:00
|
|
|
return err
|
2017-12-12 00:52:26 +01:00
|
|
|
}
|
|
|
|
|
2019-02-20 16:12:30 +01:00
|
|
|
// TODO(jungjw): Consider ordering by name.
|
2017-12-12 00:52:26 +01:00
|
|
|
const (
|
2019-02-20 16:12:30 +01:00
|
|
|
packageListTemplate = `
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Build Docs</title>
|
|
|
|
<style>
|
|
|
|
#main {
|
|
|
|
padding: 48px;
|
|
|
|
}
|
|
|
|
|
|
|
|
table{
|
|
|
|
table-layout: fixed;
|
|
|
|
}
|
|
|
|
|
|
|
|
td {
|
|
|
|
word-wrap:break-word;
|
|
|
|
}
|
2019-04-16 00:09:16 +02:00
|
|
|
|
|
|
|
/* The following entries are copied from source.android.com's css file. */
|
|
|
|
td,td code {
|
|
|
|
color: #202124
|
|
|
|
}
|
|
|
|
|
|
|
|
th,th code {
|
|
|
|
color: #fff;
|
|
|
|
font: 500 16px/24px Roboto,sans-serif
|
|
|
|
}
|
|
|
|
|
|
|
|
td,table.responsive tr:not(.alt) td td:first-child,table.responsive td tr:not(.alt) td:first-child {
|
|
|
|
background: rgba(255,255,255,.95);
|
|
|
|
vertical-align: top
|
|
|
|
}
|
|
|
|
|
|
|
|
td,td code {
|
|
|
|
padding: 7px 8px 8px
|
|
|
|
}
|
|
|
|
|
|
|
|
tr {
|
|
|
|
border: 0;
|
|
|
|
background: #78909c;
|
|
|
|
border-top: 1px solid #cfd8dc
|
|
|
|
}
|
|
|
|
|
|
|
|
th,td {
|
|
|
|
border: 0;
|
|
|
|
margin: 0;
|
|
|
|
text-align: left
|
|
|
|
}
|
|
|
|
|
|
|
|
th {
|
|
|
|
height: 48px;
|
|
|
|
padding: 8px;
|
|
|
|
vertical-align: middle
|
|
|
|
}
|
|
|
|
|
|
|
|
table {
|
|
|
|
border: 0;
|
|
|
|
border-collapse: collapse;
|
|
|
|
border-spacing: 0;
|
|
|
|
font: 14px/20px Roboto,sans-serif;
|
|
|
|
margin: 16px 0;
|
|
|
|
width: 100%
|
|
|
|
}
|
|
|
|
|
|
|
|
h1 {
|
|
|
|
color: #80868b;
|
|
|
|
font: 300 34px/40px Roboto,sans-serif;
|
|
|
|
letter-spacing: -0.01em;
|
|
|
|
margin: 40px 0 20px
|
|
|
|
}
|
|
|
|
|
|
|
|
h1,h2,h3,h4,h5,h6 {
|
|
|
|
overflow: hidden;
|
|
|
|
padding: 0;
|
|
|
|
text-overflow: ellipsis
|
|
|
|
}
|
|
|
|
|
|
|
|
:link,:visited {
|
|
|
|
color: #039be5;
|
|
|
|
outline: 0;
|
|
|
|
text-decoration: none
|
|
|
|
}
|
|
|
|
|
|
|
|
body,html {
|
|
|
|
color: #202124;
|
|
|
|
font: 400 16px/24px Roboto,sans-serif;
|
|
|
|
-moz-osx-font-smoothing: grayscale;
|
|
|
|
-webkit-font-smoothing: antialiased;
|
|
|
|
height: 100%;
|
|
|
|
margin: 0;
|
|
|
|
-webkit-text-size-adjust: 100%;
|
|
|
|
-moz-text-size-adjust: 100%;
|
|
|
|
-ms-text-size-adjust: 100%;
|
|
|
|
text-size-adjust: 100%
|
|
|
|
}
|
|
|
|
|
|
|
|
html {
|
|
|
|
-webkit-box-sizing: border-box;
|
|
|
|
box-sizing: border-box
|
|
|
|
}
|
|
|
|
|
|
|
|
*,*::before,*::after {
|
|
|
|
-webkit-box-sizing: inherit;
|
|
|
|
box-sizing: inherit
|
|
|
|
}
|
|
|
|
|
|
|
|
body,div,dl,dd,form,img,input,figure,menu {
|
|
|
|
margin: 0;
|
|
|
|
padding: 0
|
|
|
|
}
|
2019-02-20 16:12:30 +01:00
|
|
|
</style>
|
2019-02-22 22:44:38 +01:00
|
|
|
{{template "copyBaseUrl"}}
|
2019-02-20 16:12:30 +01:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="main">
|
|
|
|
<H1>Soong Modules Reference</H1>
|
|
|
|
The latest versions of Android use the Soong build system, which greatly simplifies build
|
|
|
|
configuration over the previous Make-based system. This site contains the generated reference
|
|
|
|
files for the Soong build system.
|
|
|
|
|
|
|
|
<table class="module_types" summary="Table of Soong module types sorted by package">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th style="width:20%">Package</th>
|
|
|
|
<th style="width:80%">Module types</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{{range $pkg := .}}
|
|
|
|
<tr>
|
|
|
|
<td>{{.Path}}</td>
|
|
|
|
<td>
|
|
|
|
{{range $i, $mod := .ModuleTypes}}{{if $i}}, {{end}}<a href="{{$pkg.Name}}.html#{{$mod.Name}}">{{$mod.Name}}</a>{{end}}
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
{{end}}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`
|
|
|
|
|
|
|
|
perPackageTemplate = `
|
2017-12-12 00:52:26 +01:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Build Docs</title>
|
2019-02-07 21:10:56 +01:00
|
|
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
|
|
|
|
<style>
|
|
|
|
.accordion,.simple{margin-left:1.5em;text-indent:-1.5em;margin-top:.25em}
|
|
|
|
.collapsible{border-width:0 0 0 1;margin-left:.25em;padding-left:.25em;border-style:solid;
|
|
|
|
border-color:grey;display:none;}
|
|
|
|
span.fixed{display: block; float: left; clear: left; width: 1em;}
|
|
|
|
ul {
|
|
|
|
list-style-type: none;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
width: 30ch;
|
|
|
|
background-color: #f1f1f1;
|
|
|
|
position: fixed;
|
|
|
|
height: 100%;
|
|
|
|
overflow: auto;
|
|
|
|
}
|
|
|
|
li a {
|
|
|
|
display: block;
|
|
|
|
color: #000;
|
|
|
|
padding: 8px 16px;
|
|
|
|
text-decoration: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
li a.active {
|
|
|
|
background-color: #4CAF50;
|
|
|
|
color: white;
|
|
|
|
}
|
|
|
|
|
|
|
|
li a:hover:not(.active) {
|
|
|
|
background-color: #555;
|
|
|
|
color: white;
|
|
|
|
}
|
|
|
|
</style>
|
2019-02-22 22:44:38 +01:00
|
|
|
{{template "copyBaseUrl"}}
|
2017-12-12 00:52:26 +01:00
|
|
|
</head>
|
|
|
|
<body>
|
2019-02-07 21:10:56 +01:00
|
|
|
{{- /* Fixed sidebar with module types */ -}}
|
|
|
|
<ul>
|
2019-02-20 16:12:30 +01:00
|
|
|
<li><h3>{{.Name}} package</h3></li>
|
2019-02-27 20:15:00 +01:00
|
|
|
{{range $moduleType := .Modules}}<li><a href="{{$.Name}}.html#{{$moduleType.Name}}">{{$moduleType.Name}}</a></li>
|
2019-02-07 21:10:56 +01:00
|
|
|
{{end -}}
|
|
|
|
</ul>
|
|
|
|
{{/* Main panel with H1 section per module type */}}
|
|
|
|
<div style="margin-left:30ch;padding:1px 16px;">
|
2019-02-20 16:12:30 +01:00
|
|
|
{{range $moduleType := .Modules}}
|
2019-02-07 21:10:56 +01:00
|
|
|
{{setModule $moduleType.Name}}
|
|
|
|
<p>
|
|
|
|
<h2 id="{{$moduleType.Name}}">{{$moduleType.Name}}</h2>
|
|
|
|
{{if $moduleType.Synopsis }}{{$moduleType.Synopsis}}{{else}}<i>Missing synopsis</i>{{end}}
|
|
|
|
{{- /* Comma-separated list of module attributes' links module attributes */ -}}
|
|
|
|
<div class="breadcrumb">
|
|
|
|
{{range $i,$prop := $moduleType.Properties }}
|
|
|
|
{{ if gt $i 0 }}, {{end -}}
|
2019-02-27 20:15:00 +01:00
|
|
|
<a href={{$.Name}}.html#{{getModule}}.{{$prop.Name}}>{{$prop.Name}}</a>
|
2019-02-07 21:10:56 +01:00
|
|
|
{{- end -}}
|
|
|
|
</div>
|
|
|
|
{{- /* Property description */ -}}
|
|
|
|
{{- template "properties" $moduleType.Properties -}}
|
|
|
|
{{- end -}}
|
|
|
|
|
|
|
|
{{define "properties" -}}
|
2017-12-12 00:52:26 +01:00
|
|
|
{{range .}}
|
2019-02-07 21:10:56 +01:00
|
|
|
{{if .Properties -}}
|
|
|
|
<div class="accordion" id="{{getModule}}.{{.Name}}">
|
|
|
|
<span class="fixed">⊕</span><b>{{.Name}}</b>
|
|
|
|
{{- range .OtherNames -}}, {{.}}{{- end -}}
|
|
|
|
</div>
|
|
|
|
<div class="collapsible">
|
|
|
|
{{- .Text}} {{range .OtherTexts}}{{.}}{{end}}
|
|
|
|
{{template "properties" .Properties -}}
|
2017-12-12 00:52:26 +01:00
|
|
|
</div>
|
2019-02-07 21:10:56 +01:00
|
|
|
{{- else -}}
|
|
|
|
<div class="simple" id="{{getModule}}.{{.Name}}">
|
|
|
|
<span class="fixed"> </span><b>{{.Name}} {{range .OtherNames}}, {{.}}{{end -}}</b>
|
2019-03-12 21:28:25 +01:00
|
|
|
<i>{{.Type}}</i>
|
|
|
|
{{- if .Text -}}{{if ne .Text "\n"}}, {{end}}{{.Text}}{{- end -}}
|
|
|
|
{{- with .OtherTexts -}}{{.}}{{- end -}}
|
2019-02-07 21:10:56 +01:00
|
|
|
{{- if .Default -}}<i>Default: {{.Default}}</i>{{- end -}}
|
2017-12-12 00:52:26 +01:00
|
|
|
</div>
|
2019-02-07 21:10:56 +01:00
|
|
|
{{- end}}
|
|
|
|
{{- end -}}
|
|
|
|
{{- end -}}
|
2017-12-12 00:52:26 +01:00
|
|
|
</div>
|
2019-02-07 21:10:56 +01:00
|
|
|
<script>
|
|
|
|
accordions = document.getElementsByClassName('accordion');
|
|
|
|
for (i=0; i < accordions.length; ++i) {
|
|
|
|
accordions[i].addEventListener("click", function() {
|
|
|
|
var panel = this.nextElementSibling;
|
|
|
|
var child = this.firstElementChild;
|
|
|
|
if (panel.style.display === "block") {
|
|
|
|
panel.style.display = "none";
|
|
|
|
child.textContent = '\u2295';
|
|
|
|
} else {
|
|
|
|
panel.style.display = "block";
|
|
|
|
child.textContent = '\u2296';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
</script>
|
2017-12-12 00:52:26 +01:00
|
|
|
</body>
|
2019-02-22 22:44:38 +01:00
|
|
|
`
|
|
|
|
|
|
|
|
copyBaseUrl = `
|
|
|
|
{{define "copyBaseUrl"}}
|
|
|
|
<script type="text/javascript">
|
|
|
|
window.addEventListener('message', (e) => {
|
|
|
|
if (e != null && e.data != null && e.data.type === "SET_BASE" && e.data.base != null) {
|
|
|
|
const existingBase = document.querySelector('base');
|
|
|
|
if (existingBase != null) {
|
|
|
|
existingBase.parentElement.removeChild(existingBase);
|
|
|
|
}
|
|
|
|
|
|
|
|
const base = document.createElement('base');
|
|
|
|
base.setAttribute('href', e.data.base);
|
|
|
|
document.head.appendChild(base);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
{{end}}
|
2017-12-12 00:52:26 +01:00
|
|
|
`
|
|
|
|
)
|