blob: e406d20e0e240ae5d5bc7118050bc7f1bcf44455 [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
15package device_config
16
17import (
18 "android/soong/android"
19 "github.com/google/blueprint"
20)
21
22// Properties for "device_config_value_set"
23type ValueSetModule struct {
24 android.ModuleBase
25 android.DefaultableModuleBase
26
27 properties struct {
28 // device_config_values modules
29 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)
39 // TODO: bp2build
40 //android.InitBazelModule(module)
41
42 return module
43}
44
45// Dependency tag for values property
46type valueSetType struct {
47 blueprint.BaseDependencyTag
48}
49
50var valueSetTag = valueSetType{}
51
52// Provider published by device_config_value_set
53type valueSetProviderData struct {
54 // The namespace of each of the
55 // (map of namespace --> device_config_module)
56 AvailableNamespaces map[string]android.Paths
57}
58
59var valueSetProviderKey = blueprint.NewProvider(valueSetProviderData{})
60
61func (module *ValueSetModule) DepsMutator(ctx android.BottomUpMutatorContext) {
62 deps := ctx.AddDependency(ctx.Module(), valueSetTag, module.properties.Values...)
63 for _, dep := range deps {
64 _, ok := dep.(*ValuesModule)
65 if !ok {
66 ctx.PropertyErrorf("values", "values must be a device_config_values module")
67 return
68 }
69 }
70}
71
72func (module *ValueSetModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
73 // Accumulate the namespaces of the values modules listed, and set that as an
74 // valueSetProviderKey provider that device_config modules can read and use
75 // to append values to their aconfig actions.
76 namespaces := make(map[string]android.Paths)
77 ctx.VisitDirectDeps(func(dep android.Module) {
78 if !ctx.OtherModuleHasProvider(dep, valuesProviderKey) {
79 // Other modules get injected as dependencies too, for example the license modules
80 return
81 }
82 depData := ctx.OtherModuleProvider(dep, valuesProviderKey).(valuesProviderData)
83
84 srcs := make([]android.Path, len(depData.Values))
85 copy(srcs, depData.Values)
86 namespaces[depData.Namespace] = srcs
87
88 })
89 ctx.SetProvider(valueSetProviderKey, valueSetProviderData{
90 AvailableNamespaces: namespaces,
91 })
92}