Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 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 | |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 15 | package aconfig |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "github.com/google/blueprint" |
| 20 | ) |
| 21 | |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 22 | // Properties for "aconfig_value" |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 23 | type 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 Onorato | 81b25ed | 2023-06-21 13:49:37 -0700 | [diff] [blame] | 31 | // Release config flag package |
| 32 | Package string |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 33 | } |
| 34 | } |
| 35 | |
| 36 | func ValuesFactory() android.Module { |
| 37 | module := &ValuesModule{} |
| 38 | |
| 39 | android.InitAndroidModule(module) |
| 40 | android.InitDefaultableModule(module) |
| 41 | module.AddProperties(&module.properties) |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 42 | |
| 43 | return module |
| 44 | } |
| 45 | |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 46 | // Provider published by aconfig_value_set |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 47 | type valuesProviderData struct { |
Joe Onorato | 81b25ed | 2023-06-21 13:49:37 -0700 | [diff] [blame] | 48 | // The package that this values module values |
| 49 | Package string |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 50 | |
| 51 | // The values aconfig files, relative to the root of the tree |
| 52 | Values android.Paths |
| 53 | } |
| 54 | |
Colin Cross | bc7d76c | 2023-12-12 16:39:03 -0800 | [diff] [blame] | 55 | var valuesProviderKey = blueprint.NewProvider[valuesProviderData]() |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 56 | |
| 57 | func (module *ValuesModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Joe Onorato | 81b25ed | 2023-06-21 13:49:37 -0700 | [diff] [blame] | 58 | if len(module.properties.Package) == 0 { |
| 59 | ctx.PropertyErrorf("package", "missing package property") |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 62 | // Provide the our source files list to the aconfig_value_set as a list of files |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 63 | providerData := valuesProviderData{ |
Joe Onorato | 81b25ed | 2023-06-21 13:49:37 -0700 | [diff] [blame] | 64 | Package: module.properties.Package, |
| 65 | Values: android.PathsForModuleSrc(ctx, module.properties.Srcs), |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 66 | } |
Colin Cross | 4021302 | 2023-12-13 15:19:49 -0800 | [diff] [blame] | 67 | android.SetProvider(ctx, valuesProviderKey, providerData) |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 68 | } |