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" |
Yu Liu | 2cc802a | 2023-09-05 17:19:45 -0700 | [diff] [blame] | 19 | "android/soong/bazel" |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 20 | "github.com/google/blueprint" |
| 21 | ) |
| 22 | |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 23 | // Properties for "aconfig_value" |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 24 | type ValuesModule struct { |
| 25 | android.ModuleBase |
| 26 | android.DefaultableModuleBase |
Yu Liu | 2cc802a | 2023-09-05 17:19:45 -0700 | [diff] [blame] | 27 | android.BazelModuleBase |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 28 | |
| 29 | properties struct { |
| 30 | // aconfig files, relative to this Android.bp file |
| 31 | Srcs []string `android:"path"` |
| 32 | |
Joe Onorato | 81b25ed | 2023-06-21 13:49:37 -0700 | [diff] [blame] | 33 | // Release config flag package |
| 34 | Package string |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
| 38 | func ValuesFactory() android.Module { |
| 39 | module := &ValuesModule{} |
| 40 | |
| 41 | android.InitAndroidModule(module) |
| 42 | android.InitDefaultableModule(module) |
| 43 | module.AddProperties(&module.properties) |
Yu Liu | 2cc802a | 2023-09-05 17:19:45 -0700 | [diff] [blame] | 44 | android.InitBazelModule(module) |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 45 | |
| 46 | return module |
| 47 | } |
| 48 | |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 49 | // Provider published by aconfig_value_set |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 50 | type valuesProviderData struct { |
Joe Onorato | 81b25ed | 2023-06-21 13:49:37 -0700 | [diff] [blame] | 51 | // The package that this values module values |
| 52 | Package string |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 53 | |
| 54 | // The values aconfig files, relative to the root of the tree |
| 55 | Values android.Paths |
| 56 | } |
| 57 | |
| 58 | var valuesProviderKey = blueprint.NewProvider(valuesProviderData{}) |
| 59 | |
| 60 | func (module *ValuesModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Joe Onorato | 81b25ed | 2023-06-21 13:49:37 -0700 | [diff] [blame] | 61 | if len(module.properties.Package) == 0 { |
| 62 | ctx.PropertyErrorf("package", "missing package property") |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Joe Onorato | 981c926 | 2023-06-21 15:16:23 -0700 | [diff] [blame] | 65 | // 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] | 66 | providerData := valuesProviderData{ |
Joe Onorato | 81b25ed | 2023-06-21 13:49:37 -0700 | [diff] [blame] | 67 | Package: module.properties.Package, |
| 68 | Values: android.PathsForModuleSrc(ctx, module.properties.Srcs), |
Joe Onorato | fee845a | 2023-05-09 08:14:14 -0700 | [diff] [blame] | 69 | } |
| 70 | ctx.SetProvider(valuesProviderKey, providerData) |
| 71 | } |
Yu Liu | 2cc802a | 2023-09-05 17:19:45 -0700 | [diff] [blame] | 72 | |
| 73 | type bazelAconfigValuesAttributes struct { |
| 74 | Srcs bazel.LabelListAttribute |
| 75 | Package string |
| 76 | } |
| 77 | |
Chris Parsons | 637458d | 2023-09-19 20:09:00 +0000 | [diff] [blame^] | 78 | func (module *ValuesModule) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) { |
Yu Liu | 2cc802a | 2023-09-05 17:19:45 -0700 | [diff] [blame] | 79 | if ctx.ModuleType() != "aconfig_values" { |
| 80 | return |
| 81 | } |
| 82 | |
| 83 | srcs := bazel.MakeLabelListAttribute(android.BazelLabelForModuleSrc(ctx, module.properties.Srcs)) |
| 84 | |
| 85 | attrs := bazelAconfigValuesAttributes{ |
| 86 | Srcs: srcs, |
| 87 | Package: module.properties.Package, |
| 88 | } |
| 89 | props := bazel.BazelTargetModuleProperties{ |
| 90 | Rule_class: "aconfig_values", |
| 91 | Bzl_load_location: "//build/bazel/rules/aconfig:aconfig_values.bzl", |
| 92 | } |
| 93 | |
| 94 | ctx.CreateBazelTargetModule(props, android.CommonAttributes{Name: module.Name()}, &attrs) |
| 95 | } |