blob: 7ba76c044ec4d5da684aa4cad50d1bfcb152d4bf [file] [log] [blame]
Joe Onoratofee845a2023-05-09 08:14:14 -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
Joe Onorato981c9262023-06-21 15:16:23 -070015package aconfig
Joe Onoratofee845a2023-05-09 08:14:14 -070016
17import (
18 "android/soong/android"
19 "github.com/google/blueprint"
20)
21
Joe Onorato981c9262023-06-21 15:16:23 -070022// Properties for "aconfig_value_set"
Joe Onoratofee845a2023-05-09 08:14:14 -070023type ValueSetModule struct {
24 android.ModuleBase
25 android.DefaultableModuleBase
26
27 properties struct {
Joe Onorato981c9262023-06-21 15:16:23 -070028 // aconfig_values modules
Joe Onoratofee845a2023-05-09 08:14:14 -070029 Values []string
30 }
31}
32
33func ValueSetFactory() android.Module {
34 module := &ValueSetModule{}
35
36 android.InitAndroidModule(module)
37 android.InitDefaultableModule(module)
38 module.AddProperties(&module.properties)
Joe Onoratofee845a2023-05-09 08:14:14 -070039
40 return module
41}
42
43// Dependency tag for values property
44type valueSetType struct {
45 blueprint.BaseDependencyTag
46}
47
48var valueSetTag = valueSetType{}
49
Joe Onorato981c9262023-06-21 15:16:23 -070050// Provider published by aconfig_value_set
Joe Onoratofee845a2023-05-09 08:14:14 -070051type valueSetProviderData struct {
Joe Onorato81b25ed2023-06-21 13:49:37 -070052 // The package of each of the
Joe Onorato981c9262023-06-21 15:16:23 -070053 // (map of package --> aconfig_module)
Joe Onorato81b25ed2023-06-21 13:49:37 -070054 AvailablePackages map[string]android.Paths
Joe Onoratofee845a2023-05-09 08:14:14 -070055}
56
Colin Crossbc7d76c2023-12-12 16:39:03 -080057var valueSetProviderKey = blueprint.NewProvider[valueSetProviderData]()
Joe Onoratofee845a2023-05-09 08:14:14 -070058
59func (module *ValueSetModule) DepsMutator(ctx android.BottomUpMutatorContext) {
60 deps := ctx.AddDependency(ctx.Module(), valueSetTag, module.properties.Values...)
61 for _, dep := range deps {
62 _, ok := dep.(*ValuesModule)
63 if !ok {
Joe Onorato981c9262023-06-21 15:16:23 -070064 ctx.PropertyErrorf("values", "values must be a aconfig_values module")
Joe Onoratofee845a2023-05-09 08:14:14 -070065 return
66 }
67 }
68}
69
70func (module *ValueSetModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Joe Onorato81b25ed2023-06-21 13:49:37 -070071 // Accumulate the packages of the values modules listed, and set that as an
Joe Onorato981c9262023-06-21 15:16:23 -070072 // valueSetProviderKey provider that aconfig modules can read and use
Joe Onoratofee845a2023-05-09 08:14:14 -070073 // to append values to their aconfig actions.
Joe Onorato81b25ed2023-06-21 13:49:37 -070074 packages := make(map[string]android.Paths)
Joe Onoratofee845a2023-05-09 08:14:14 -070075 ctx.VisitDirectDeps(func(dep android.Module) {
Colin Cross313aa542023-12-13 13:47:44 -080076 if depData, ok := android.OtherModuleProvider(ctx, dep, valuesProviderKey); ok {
77 srcs := make([]android.Path, len(depData.Values))
78 copy(srcs, depData.Values)
79 packages[depData.Package] = srcs
Joe Onoratofee845a2023-05-09 08:14:14 -070080 }
Joe Onoratofee845a2023-05-09 08:14:14 -070081
82 })
Colin Cross40213022023-12-13 15:19:49 -080083 android.SetProvider(ctx, valueSetProviderKey, valueSetProviderData{
Joe Onorato81b25ed2023-06-21 13:49:37 -070084 AvailablePackages: packages,
Joe Onoratofee845a2023-05-09 08:14:14 -070085 })
86}