blob: 239b10c4b92ae8a0b22c8c32fa8ad8b73fc52002 [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"
Joe Onoratofee845a2023-05-09 08:14:14 -070023type ValuesModule struct {
24 android.ModuleBase
25 android.DefaultableModuleBase
26
27 properties struct {
28 // aconfig files, relative to this Android.bp file
29 Srcs []string `android:"path"`
30
Joe Onorato81b25ed2023-06-21 13:49:37 -070031 // Release config flag package
32 Package string
Joe Onoratofee845a2023-05-09 08:14:14 -070033 }
34}
35
36func ValuesFactory() android.Module {
37 module := &ValuesModule{}
38
39 android.InitAndroidModule(module)
40 android.InitDefaultableModule(module)
41 module.AddProperties(&module.properties)
Joe Onoratofee845a2023-05-09 08:14:14 -070042
43 return module
44}
45
Joe Onorato981c9262023-06-21 15:16:23 -070046// Provider published by aconfig_value_set
Joe Onoratofee845a2023-05-09 08:14:14 -070047type valuesProviderData struct {
Joe Onorato81b25ed2023-06-21 13:49:37 -070048 // The package that this values module values
49 Package string
Joe Onoratofee845a2023-05-09 08:14:14 -070050
51 // The values aconfig files, relative to the root of the tree
52 Values android.Paths
53}
54
Colin Crossbc7d76c2023-12-12 16:39:03 -080055var valuesProviderKey = blueprint.NewProvider[valuesProviderData]()
Joe Onoratofee845a2023-05-09 08:14:14 -070056
57func (module *ValuesModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Joe Onorato81b25ed2023-06-21 13:49:37 -070058 if len(module.properties.Package) == 0 {
59 ctx.PropertyErrorf("package", "missing package property")
Joe Onoratofee845a2023-05-09 08:14:14 -070060 }
61
Joe Onorato981c9262023-06-21 15:16:23 -070062 // Provide the our source files list to the aconfig_value_set as a list of files
Joe Onoratofee845a2023-05-09 08:14:14 -070063 providerData := valuesProviderData{
Joe Onorato81b25ed2023-06-21 13:49:37 -070064 Package: module.properties.Package,
65 Values: android.PathsForModuleSrc(ctx, module.properties.Srcs),
Joe Onoratofee845a2023-05-09 08:14:14 -070066 }
Colin Cross40213022023-12-13 15:19:49 -080067 android.SetProvider(ctx, valuesProviderKey, providerData)
Joe Onoratofee845a2023-05-09 08:14:14 -070068}