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 15package aconfig 16 17import ( 18 "android/soong/android" 19 "github.com/google/blueprint" 20) 21 22// Properties for "aconfig_value_set" 23type ValueSetModule struct { 24 android.ModuleBase 25 android.DefaultableModuleBase 26 27 properties struct { 28 // aconfig_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 40 return module 41} 42 43// Dependency tag for values property 44type valueSetType struct { 45 blueprint.BaseDependencyTag 46} 47 48var valueSetTag = valueSetType{} 49 50// Provider published by aconfig_value_set 51type valueSetProviderData struct { 52 // The package of each of the 53 // (map of package --> aconfig_module) 54 AvailablePackages map[string]android.Paths 55} 56 57var valueSetProviderKey = blueprint.NewProvider[valueSetProviderData]() 58 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 { 64 ctx.PropertyErrorf("values", "values must be a aconfig_values module") 65 return 66 } 67 } 68} 69 70func (module *ValueSetModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { 71 // Accumulate the packages of the values modules listed, and set that as an 72 // valueSetProviderKey provider that aconfig modules can read and use 73 // to append values to their aconfig actions. 74 packages := make(map[string]android.Paths) 75 ctx.VisitDirectDeps(func(dep android.Module) { 76 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 80 } 81 82 }) 83 android.SetProvider(ctx, valueSetProviderKey, valueSetProviderData{ 84 AvailablePackages: packages, 85 }) 86} 87