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"
23type 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
31		// Release config flag package
32		Package string
33	}
34}
35
36func ValuesFactory() android.Module {
37	module := &ValuesModule{}
38
39	android.InitAndroidModule(module)
40	android.InitDefaultableModule(module)
41	module.AddProperties(&module.properties)
42
43	return module
44}
45
46// Provider published by aconfig_value_set
47type valuesProviderData struct {
48	// The package that this values module values
49	Package string
50
51	// The values aconfig files, relative to the root of the tree
52	Values android.Paths
53}
54
55var valuesProviderKey = blueprint.NewProvider[valuesProviderData]()
56
57func (module *ValuesModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
58	if len(module.properties.Package) == 0 {
59		ctx.PropertyErrorf("package", "missing package property")
60	}
61
62	// Provide the our source files list to the aconfig_value_set as a list of files
63	providerData := valuesProviderData{
64		Package: module.properties.Package,
65		Values:  android.PathsForModuleSrc(ctx, module.properties.Srcs),
66	}
67	android.SetProvider(ctx, valuesProviderKey, providerData)
68}
69