LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 1 | // Copyright 2023 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 build_flags |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | ) |
| 20 | |
| 21 | // A singleton module that collects all of the build flags declared in the |
| 22 | // tree into a single combined file for export to the external flag setting |
| 23 | // server (inside Google it's Gantry). |
| 24 | // |
| 25 | // Note that this is ALL build_declarations modules present in the tree, not just |
| 26 | // ones that are relevant to the product currently being built, so that that infra |
| 27 | // doesn't need to pull from multiple builds and merge them. |
| 28 | func AllBuildFlagDeclarationsFactory() android.Singleton { |
| 29 | return &allBuildFlagDeclarationsSingleton{} |
| 30 | } |
| 31 | |
| 32 | type allBuildFlagDeclarationsSingleton struct { |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 33 | flagsBinaryProtoPath android.OutputPath |
| 34 | flagsTextProtoPath android.OutputPath |
| 35 | configsBinaryProtoPath android.OutputPath |
| 36 | configsTextProtoPath android.OutputPath |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | func (this *allBuildFlagDeclarationsSingleton) GenerateBuildActions(ctx android.SingletonContext) { |
| 40 | // Find all of the build_flag_declarations modules |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 41 | var flagsFiles android.Paths |
| 42 | // Find all of the release_config_contribution modules |
| 43 | var contributionDirs android.Paths |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 44 | ctx.VisitAllModules(func(module android.Module) { |
Yu Liu | 663e450 | 2024-08-12 18:23:59 +0000 | [diff] [blame] | 45 | decl, ok := android.OtherModuleProvider(ctx, module, BuildFlagDeclarationsProviderKey) |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 46 | if ok { |
| 47 | flagsFiles = append(flagsFiles, decl.IntermediateCacheOutputPath) |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 48 | } |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 49 | |
| 50 | contrib, ok := android.OtherModuleProvider(ctx, module, ReleaseConfigContributionsProviderKey) |
| 51 | if ok { |
| 52 | contributionDirs = append(contributionDirs, contrib.ContributionDir) |
| 53 | } |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 54 | }) |
| 55 | |
| 56 | // Generate build action for build_flag (binary proto output) |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 57 | this.flagsBinaryProtoPath = android.PathForIntermediates(ctx, "all_build_flag_declarations.pb") |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 58 | ctx.Build(pctx, android.BuildParams{ |
| 59 | Rule: allDeclarationsRule, |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 60 | Inputs: flagsFiles, |
| 61 | Output: this.flagsBinaryProtoPath, |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 62 | Description: "all_build_flag_declarations", |
| 63 | Args: map[string]string{ |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 64 | "intermediates": android.JoinPathsWithPrefix(flagsFiles, "--intermediate "), |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 65 | }, |
| 66 | }) |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 67 | ctx.Phony("all_build_flag_declarations", this.flagsBinaryProtoPath) |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 68 | |
| 69 | // Generate build action for build_flag (text proto output) |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 70 | this.flagsTextProtoPath = android.PathForIntermediates(ctx, "all_build_flag_declarations.textproto") |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 71 | ctx.Build(pctx, android.BuildParams{ |
| 72 | Rule: allDeclarationsRuleTextProto, |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 73 | Input: this.flagsBinaryProtoPath, |
| 74 | Output: this.flagsTextProtoPath, |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 75 | Description: "all_build_flag_declarations_textproto", |
| 76 | }) |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 77 | ctx.Phony("all_build_flag_declarations_textproto", this.flagsTextProtoPath) |
| 78 | |
| 79 | // Generate build action for release_configs (binary proto output) |
| 80 | this.configsBinaryProtoPath = android.PathForIntermediates(ctx, "all_release_config_contributions.pb") |
| 81 | ctx.Build(pctx, android.BuildParams{ |
| 82 | Rule: allReleaseConfigContributionsRule, |
| 83 | Inputs: contributionDirs, |
| 84 | Output: this.configsBinaryProtoPath, |
| 85 | Description: "all_release_config_contributions", |
| 86 | Args: map[string]string{ |
| 87 | "dirs": android.JoinPathsWithPrefix(contributionDirs, "--dir "), |
| 88 | "format": "pb", |
| 89 | }, |
| 90 | }) |
| 91 | ctx.Phony("all_release_config_contributions", this.configsBinaryProtoPath) |
| 92 | |
| 93 | this.configsTextProtoPath = android.PathForIntermediates(ctx, "all_release_config_contributions.textproto") |
| 94 | ctx.Build(pctx, android.BuildParams{ |
| 95 | Rule: allReleaseConfigContributionsRule, |
| 96 | Inputs: contributionDirs, |
| 97 | Output: this.configsTextProtoPath, |
| 98 | Description: "all_release_config_contributions_textproto", |
| 99 | Args: map[string]string{ |
| 100 | "dirs": android.JoinPathsWithPrefix(contributionDirs, "--dir "), |
| 101 | "format": "textproto", |
| 102 | }, |
| 103 | }) |
| 104 | ctx.Phony("all_release_config_contributions_textproto", this.configsTextProtoPath) |
| 105 | |
| 106 | // Add a simple target for ci/build_metadata to use. |
| 107 | ctx.Phony("release_config_metadata", |
| 108 | this.flagsBinaryProtoPath, |
| 109 | this.flagsTextProtoPath, |
| 110 | this.configsBinaryProtoPath, |
| 111 | this.configsTextProtoPath, |
| 112 | ) |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | func (this *allBuildFlagDeclarationsSingleton) MakeVars(ctx android.MakeVarsContext) { |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 116 | ctx.DistForGoal("droid", this.flagsBinaryProtoPath) |
LaMont Jones | 1639ab5 | 2024-10-04 12:48:01 -0700 | [diff] [blame^] | 117 | for _, goal := range []string{"docs", "droid", "sdk", "release_config_metadata"} { |
LaMont Jones | 735a80b | 2024-10-02 15:42:53 -0700 | [diff] [blame] | 118 | ctx.DistForGoalWithFilename(goal, this.flagsBinaryProtoPath, "build_flags/all_flags.pb") |
| 119 | ctx.DistForGoalWithFilename(goal, this.flagsTextProtoPath, "build_flags/all_flags.textproto") |
| 120 | ctx.DistForGoalWithFilename(goal, this.configsBinaryProtoPath, "build_flags/all_release_config_contributions.pb") |
| 121 | ctx.DistForGoalWithFilename(goal, this.configsTextProtoPath, "build_flags/all_release_config_contributions.textproto") |
LaMont Jones | c6aef16 | 2024-05-20 10:37:25 -0700 | [diff] [blame] | 122 | } |
| 123 | } |