From e87040b2eb90fddffc52d3af0e4f1ba4edca9d25 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 11 Dec 2017 15:52:26 -0800 Subject: Allow Soong to generate its own build documentation Add a rule in soong that re-executes soong_build in order to generate build documentation. This allows Soong to customize the documentation. Bug: 70516282 Test: m soong_docs Change-Id: If143cfacd6ac20274cd7bb8d8fab0c07025a5553 --- cmd/soong_build/Android.bp | 1 + cmd/soong_build/main.go | 16 ++++++ cmd/soong_build/writedocs.go | 129 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 cmd/soong_build/writedocs.go (limited to 'cmd') diff --git a/cmd/soong_build/Android.bp b/cmd/soong_build/Android.bp index d9daafc4..2536a535 100644 --- a/cmd/soong_build/Android.bp +++ b/cmd/soong_build/Android.bp @@ -23,6 +23,7 @@ bootstrap_go_binary { ], srcs: [ "main.go", + "writedocs.go", ], primaryBuilder: true, } diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go index ddde1c59..40beab8c 100644 --- a/cmd/soong_build/main.go +++ b/cmd/soong_build/main.go @@ -25,6 +25,14 @@ import ( "android/soong/android" ) +var ( + docFile string +) + +func init() { + flag.StringVar(&docFile, "soong_docs", "", "build documentation file to output") +} + func newNameResolver(config android.Config) *android.NameResolver { namespacePathsToExport := make(map[string]bool) @@ -56,9 +64,17 @@ func main() { os.Exit(1) } + if docFile != "" { + configuration.SetStopBefore(bootstrap.StopBeforePrepareBuildActions) + } + ctx.SetNameInterface(newNameResolver(configuration)) ctx.SetAllowMissingDependencies(configuration.AllowMissingDependencies()) bootstrap.Main(ctx.Context, configuration, configuration.ConfigFileName, configuration.ProductVariablesFileName) + + if docFile != "" { + writeDocs(ctx, docFile) + } } diff --git a/cmd/soong_build/writedocs.go b/cmd/soong_build/writedocs.go new file mode 100644 index 00000000..a6686c0d --- /dev/null +++ b/cmd/soong_build/writedocs.go @@ -0,0 +1,129 @@ +// 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" + + "github.com/google/blueprint/bootstrap" +) + +func writeDocs(ctx *android.Context, filename string) error { + moduleTypeList, err := bootstrap.ModuleTypeDocs(ctx.Context) + if err != nil { + return err + } + + buf := &bytes.Buffer{} + + 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 = ` + + +Build Docs + + + + + +

Build Docs

+
+ {{range .}} + {{ $collapseIndex := unique }} +
+ +
+
+
+

{{.Text}}

+ {{range .PropertyStructs}} +

{{.Text}}

+ {{template "properties" .Properties}} + {{end}} +
+
+ {{end}} +
+ + + +{{define "properties"}} +
+ {{range .}} + {{$collapseIndex := unique}} + {{if .Properties}} + +
+
+

{{.Text}}

+ {{range .OtherTexts}}

{{.}}

{{end}} + {{template "properties" .Properties}} +
+
+ {{else}} +
+

{{.Name}}{{range .OtherNames}}, {{.}}{{end}}

+

{{.Text}}

+ {{range .OtherTexts}}

{{.}}

{{end}} +

Type: {{.Type}}

+ {{if .Default}}

Default: {{.Default}}

{{end}} +
+ {{end}} + {{end}} +
+{{end}} +` +) -- cgit v1.2.3