Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 1 | // Copyright 2015 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package android |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "os" |
| 20 | "path/filepath" |
| 21 | "strings" |
| 22 | |
| 23 | "github.com/google/blueprint" |
| 24 | ) |
| 25 | |
| 26 | func init() { |
| 27 | RegisterSingletonType("writedocs", DocsSingleton) |
| 28 | } |
| 29 | |
| 30 | func DocsSingleton() Singleton { |
| 31 | return &docsSingleton{} |
| 32 | } |
| 33 | |
| 34 | type docsSingleton struct{} |
| 35 | |
| 36 | func primaryBuilderPath(ctx SingletonContext) Path { |
Lukacs T. Berki | 7690c09 | 2021-02-26 14:27:36 +0100 | [diff] [blame] | 37 | buildDir := absolutePath(ctx.Config().BuildDir()) |
| 38 | primaryBuilder, err := filepath.Rel(buildDir, os.Args[0]) |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 39 | if err != nil { |
| 40 | ctx.Errorf("path to primary builder %q is not in build dir %q", |
| 41 | os.Args[0], ctx.Config().BuildDir()) |
| 42 | } |
| 43 | |
| 44 | return PathForOutput(ctx, primaryBuilder) |
| 45 | } |
| 46 | |
| 47 | func (c *docsSingleton) GenerateBuildActions(ctx SingletonContext) { |
Chris Parsons | 8f232a2 | 2020-06-23 17:37:05 -0400 | [diff] [blame] | 48 | var deps Paths |
| 49 | deps = append(deps, pathForBuildToolDep(ctx, ctx.Config().moduleListFile)) |
| 50 | deps = append(deps, pathForBuildToolDep(ctx, ctx.Config().ProductVariablesFileName)) |
| 51 | |
Jingwen Chen | ebb0b57 | 2020-11-02 00:24:57 -0500 | [diff] [blame] | 52 | // The dexpreopt configuration may not exist, but if it does, it's a dependency |
| 53 | // of soong_build. |
| 54 | dexpreoptConfigPath := ctx.Config().DexpreoptGlobalConfigPath(ctx) |
| 55 | if dexpreoptConfigPath.Valid() { |
| 56 | deps = append(deps, dexpreoptConfigPath.Path()) |
| 57 | } |
| 58 | |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 59 | // Generate build system docs for the primary builder. Generating docs reads the source |
| 60 | // files used to build the primary builder, but that dependency will be picked up through |
| 61 | // the dependency on the primary builder itself. There are no dependencies on the |
| 62 | // Blueprints files, as any relevant changes to the Blueprints files would have caused |
| 63 | // a rebuild of the primary builder. |
| 64 | docsFile := PathForOutput(ctx, "docs", "soong_build.html") |
| 65 | primaryBuilder := primaryBuilderPath(ctx) |
| 66 | soongDocs := ctx.Rule(pctx, "soongDocs", |
| 67 | blueprint.RuleParams{ |
Jaewoong Jung | 6c29688 | 2019-02-20 07:12:30 -0800 | [diff] [blame] | 68 | Command: fmt.Sprintf("rm -f ${outDir}/* && %s --soong_docs %s %s", |
Lukacs T. Berki | 7d613bf | 2021-03-02 10:09:41 +0100 | [diff] [blame^] | 69 | primaryBuilder.String(), |
| 70 | docsFile.String(), |
| 71 | "\""+strings.Join(os.Args[1:], "\" \"")+"\""), |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 72 | CommandDeps: []string{primaryBuilder.String()}, |
| 73 | Description: fmt.Sprintf("%s docs $out", primaryBuilder.Base()), |
Jaewoong Jung | 6c29688 | 2019-02-20 07:12:30 -0800 | [diff] [blame] | 74 | }, |
| 75 | "outDir") |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 76 | |
| 77 | ctx.Build(pctx, BuildParams{ |
| 78 | Rule: soongDocs, |
| 79 | Output: docsFile, |
Chris Parsons | 8f232a2 | 2020-06-23 17:37:05 -0400 | [diff] [blame] | 80 | Inputs: deps, |
Jaewoong Jung | 6c29688 | 2019-02-20 07:12:30 -0800 | [diff] [blame] | 81 | Args: map[string]string{ |
| 82 | "outDir": PathForOutput(ctx, "docs").String(), |
| 83 | }, |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 84 | }) |
| 85 | |
| 86 | // Add a phony target for building the documentation |
Colin Cross | c3d87d3 | 2020-06-04 13:25:17 -0700 | [diff] [blame] | 87 | ctx.Phony("soong_docs", docsFile) |
Colin Cross | e87040b | 2017-12-11 15:52:26 -0800 | [diff] [blame] | 88 | } |