blob: b6c90234a7a960e2d9c2b06b25e34a017ba11c99 [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"
Dennis Shen4e7773d2024-01-05 19:06:50 +000019 "fmt"
Joe Onorato2f99c472023-06-21 18:10:28 -070020)
21
22// A singleton module that collects all of the aconfig flags declared in the
23// tree into a single combined file for export to the external flag setting
24// server (inside Google it's Gantry).
25//
26// Note that this is ALL aconfig_declarations modules present in the tree, not just
27// ones that are relevant to the product currently being built, so that that infra
28// doesn't need to pull from multiple builds and merge them.
29func AllAconfigDeclarationsFactory() android.Singleton {
30 return &allAconfigDeclarationsSingleton{}
31}
32
33type allAconfigDeclarationsSingleton struct {
34 intermediatePath android.OutputPath
35}
36
37func (this *allAconfigDeclarationsSingleton) GenerateBuildActions(ctx android.SingletonContext) {
38 // Find all of the aconfig_declarations modules
Dennis Shen4e7773d2024-01-05 19:06:50 +000039 var packages = make(map[string]int)
Joe Onorato2f99c472023-06-21 18:10:28 -070040 var cacheFiles android.Paths
41 ctx.VisitAllModules(func(module android.Module) {
LaMont Jonesaa005ae2023-12-19 19:01:57 +000042 decl, ok := android.SingletonModuleProvider(ctx, module, android.AconfigDeclarationsProviderKey)
Colin Cross5a377182023-12-14 14:46:23 -080043 if !ok {
Joe Onorato2f99c472023-06-21 18:10:28 -070044 return
45 }
Jihoon Kangcca3e0c2023-11-29 19:35:29 +000046 cacheFiles = append(cacheFiles, decl.IntermediateCacheOutputPath)
Dennis Shen4e7773d2024-01-05 19:06:50 +000047 packages[decl.Package]++
Joe Onorato2f99c472023-06-21 18:10:28 -070048 })
49
Dennis Shen4e7773d2024-01-05 19:06:50 +000050 var numOffendingPkg = 0
51 for pkg, cnt := range packages {
52 if cnt > 1 {
53 fmt.Printf("%d aconfig_declarations found for package %s\n", cnt, pkg)
54 numOffendingPkg++
55 }
56 }
57
58 if numOffendingPkg > 0 {
59 panic(fmt.Errorf("Only one aconfig_declarations allowed for each package."))
60 }
61
Joe Onorato2f99c472023-06-21 18:10:28 -070062 // Generate build action for aconfig
63 this.intermediatePath = android.PathForIntermediates(ctx, "all_aconfig_declarations.pb")
64 ctx.Build(pctx, android.BuildParams{
Yu Liueae7b362023-11-16 17:05:47 -080065 Rule: AllDeclarationsRule,
Joe Onorato2f99c472023-06-21 18:10:28 -070066 Inputs: cacheFiles,
67 Output: this.intermediatePath,
68 Description: "all_aconfig_declarations",
69 Args: map[string]string{
70 "cache_files": android.JoinPathsWithPrefix(cacheFiles, "--cache "),
71 },
72 })
73 ctx.Phony("all_aconfig_declarations", this.intermediatePath)
74}
75
76func (this *allAconfigDeclarationsSingleton) MakeVars(ctx android.MakeVarsContext) {
77 ctx.DistForGoal("droid", this.intermediatePath)
78}