| Joe Onorato | 2f99c47 | 2023-06-21 18:10:28 -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 aconfig | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "android/soong/android" | 
|  | 19 | ) | 
|  | 20 |  | 
|  | 21 | // A singleton module that collects all of the aconfig 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 aconfig_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 AllAconfigDeclarationsFactory() android.Singleton { | 
|  | 29 | return &allAconfigDeclarationsSingleton{} | 
|  | 30 | } | 
|  | 31 |  | 
|  | 32 | type allAconfigDeclarationsSingleton struct { | 
|  | 33 | intermediatePath android.OutputPath | 
|  | 34 | } | 
|  | 35 |  | 
|  | 36 | func (this *allAconfigDeclarationsSingleton) GenerateBuildActions(ctx android.SingletonContext) { | 
|  | 37 | // Find all of the aconfig_declarations modules | 
|  | 38 | var cacheFiles android.Paths | 
|  | 39 | ctx.VisitAllModules(func(module android.Module) { | 
|  | 40 | if !ctx.ModuleHasProvider(module, declarationsProviderKey) { | 
|  | 41 | return | 
|  | 42 | } | 
|  | 43 | decl := ctx.ModuleProvider(module, declarationsProviderKey).(declarationsProviderData) | 
|  | 44 | cacheFiles = append(cacheFiles, decl.IntermediatePath) | 
|  | 45 | }) | 
|  | 46 |  | 
|  | 47 | // Generate build action for aconfig | 
|  | 48 | this.intermediatePath = android.PathForIntermediates(ctx, "all_aconfig_declarations.pb") | 
|  | 49 | ctx.Build(pctx, android.BuildParams{ | 
|  | 50 | Rule:        allDeclarationsRule, | 
|  | 51 | Inputs:      cacheFiles, | 
|  | 52 | Output:      this.intermediatePath, | 
|  | 53 | Description: "all_aconfig_declarations", | 
|  | 54 | Args: map[string]string{ | 
|  | 55 | "cache_files": android.JoinPathsWithPrefix(cacheFiles, "--cache "), | 
|  | 56 | }, | 
|  | 57 | }) | 
|  | 58 | ctx.Phony("all_aconfig_declarations", this.intermediatePath) | 
|  | 59 | } | 
|  | 60 |  | 
|  | 61 | func (this *allAconfigDeclarationsSingleton) MakeVars(ctx android.MakeVarsContext) { | 
|  | 62 | ctx.DistForGoal("droid", this.intermediatePath) | 
|  | 63 | } |