blob: 03a930dbd099d74e8b0efc02ff6e0b1b904ec12c [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"
Yu Liu2cc802a2023-09-05 17:19:45 -070019 "android/soong/bazel"
Joe Onoratofee845a2023-05-09 08:14:14 -070020 "github.com/google/blueprint"
21)
22
Joe Onorato981c9262023-06-21 15:16:23 -070023// Properties for "aconfig_value"
Joe Onoratofee845a2023-05-09 08:14:14 -070024type ValuesModule struct {
25 android.ModuleBase
26 android.DefaultableModuleBase
Yu Liu2cc802a2023-09-05 17:19:45 -070027 android.BazelModuleBase
Joe Onoratofee845a2023-05-09 08:14:14 -070028
29 properties struct {
30 // aconfig files, relative to this Android.bp file
31 Srcs []string `android:"path"`
32
Joe Onorato81b25ed2023-06-21 13:49:37 -070033 // Release config flag package
34 Package string
Joe Onoratofee845a2023-05-09 08:14:14 -070035 }
36}
37
38func ValuesFactory() android.Module {
39 module := &ValuesModule{}
40
41 android.InitAndroidModule(module)
42 android.InitDefaultableModule(module)
43 module.AddProperties(&module.properties)
Yu Liu2cc802a2023-09-05 17:19:45 -070044 android.InitBazelModule(module)
Joe Onoratofee845a2023-05-09 08:14:14 -070045
46 return module
47}
48
Joe Onorato981c9262023-06-21 15:16:23 -070049// Provider published by aconfig_value_set
Joe Onoratofee845a2023-05-09 08:14:14 -070050type valuesProviderData struct {
Joe Onorato81b25ed2023-06-21 13:49:37 -070051 // The package that this values module values
52 Package string
Joe Onoratofee845a2023-05-09 08:14:14 -070053
54 // The values aconfig files, relative to the root of the tree
55 Values android.Paths
56}
57
58var valuesProviderKey = blueprint.NewProvider(valuesProviderData{})
59
60func (module *ValuesModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Joe Onorato81b25ed2023-06-21 13:49:37 -070061 if len(module.properties.Package) == 0 {
62 ctx.PropertyErrorf("package", "missing package property")
Joe Onoratofee845a2023-05-09 08:14:14 -070063 }
64
Joe Onorato981c9262023-06-21 15:16:23 -070065 // Provide the our source files list to the aconfig_value_set as a list of files
Joe Onoratofee845a2023-05-09 08:14:14 -070066 providerData := valuesProviderData{
Joe Onorato81b25ed2023-06-21 13:49:37 -070067 Package: module.properties.Package,
68 Values: android.PathsForModuleSrc(ctx, module.properties.Srcs),
Joe Onoratofee845a2023-05-09 08:14:14 -070069 }
70 ctx.SetProvider(valuesProviderKey, providerData)
71}
Yu Liu2cc802a2023-09-05 17:19:45 -070072
73type bazelAconfigValuesAttributes struct {
74 Srcs bazel.LabelListAttribute
75 Package string
76}
77
Chris Parsons637458d2023-09-19 20:09:00 +000078func (module *ValuesModule) ConvertWithBp2build(ctx android.Bp2buildMutatorContext) {
Yu Liu2cc802a2023-09-05 17:19:45 -070079 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}