blob: 7ccb81a37c7160b2f5fe0ea8b9069794eb981efb [file] [log] [blame]
Joe Onorato2f99c472023-06-21 18:10:28 -07001// 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
15package aconfig
16
17import (
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.
28func AllAconfigDeclarationsFactory() android.Singleton {
29 return &allAconfigDeclarationsSingleton{}
30}
31
32type allAconfigDeclarationsSingleton struct {
33 intermediatePath android.OutputPath
34}
35
36func (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) {
Yu Liueae7b362023-11-16 17:05:47 -080040 if !ctx.ModuleHasProvider(module, DeclarationsProviderKey) {
Joe Onorato2f99c472023-06-21 18:10:28 -070041 return
42 }
Yu Liueae7b362023-11-16 17:05:47 -080043 decl := ctx.ModuleProvider(module, DeclarationsProviderKey).(DeclarationsProviderData)
Joe Onorato2f99c472023-06-21 18:10:28 -070044 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{
Yu Liueae7b362023-11-16 17:05:47 -080050 Rule: AllDeclarationsRule,
Joe Onorato2f99c472023-06-21 18:10:28 -070051 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
61func (this *allAconfigDeclarationsSingleton) MakeVars(ctx android.MakeVarsContext) {
62 ctx.DistForGoal("droid", this.intermediatePath)
63}