2023-05-09 17:14:14 +02:00
|
|
|
// Copyright 2023 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2023-06-22 00:16:23 +02:00
|
|
|
package aconfig
|
2023-05-09 17:14:14 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"android/soong/android"
|
|
|
|
"github.com/google/blueprint"
|
|
|
|
)
|
|
|
|
|
2023-06-22 00:16:23 +02:00
|
|
|
// Properties for "aconfig_value_set"
|
2023-05-09 17:14:14 +02:00
|
|
|
type ValueSetModule struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultableModuleBase
|
|
|
|
|
|
|
|
properties struct {
|
2023-06-22 00:16:23 +02:00
|
|
|
// aconfig_values modules
|
2023-05-09 17:14:14 +02:00
|
|
|
Values []string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func ValueSetFactory() android.Module {
|
|
|
|
module := &ValueSetModule{}
|
|
|
|
|
|
|
|
android.InitAndroidModule(module)
|
|
|
|
android.InitDefaultableModule(module)
|
|
|
|
module.AddProperties(&module.properties)
|
|
|
|
// TODO: bp2build
|
|
|
|
//android.InitBazelModule(module)
|
|
|
|
|
|
|
|
return module
|
|
|
|
}
|
|
|
|
|
|
|
|
// Dependency tag for values property
|
|
|
|
type valueSetType struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
}
|
|
|
|
|
|
|
|
var valueSetTag = valueSetType{}
|
|
|
|
|
2023-06-22 00:16:23 +02:00
|
|
|
// Provider published by aconfig_value_set
|
2023-05-09 17:14:14 +02:00
|
|
|
type valueSetProviderData struct {
|
2023-06-21 22:49:37 +02:00
|
|
|
// The package of each of the
|
2023-06-22 00:16:23 +02:00
|
|
|
// (map of package --> aconfig_module)
|
2023-06-21 22:49:37 +02:00
|
|
|
AvailablePackages map[string]android.Paths
|
2023-05-09 17:14:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var valueSetProviderKey = blueprint.NewProvider(valueSetProviderData{})
|
|
|
|
|
|
|
|
func (module *ValueSetModule) DepsMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
deps := ctx.AddDependency(ctx.Module(), valueSetTag, module.properties.Values...)
|
|
|
|
for _, dep := range deps {
|
|
|
|
_, ok := dep.(*ValuesModule)
|
|
|
|
if !ok {
|
2023-06-22 00:16:23 +02:00
|
|
|
ctx.PropertyErrorf("values", "values must be a aconfig_values module")
|
2023-05-09 17:14:14 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (module *ValueSetModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2023-06-21 22:49:37 +02:00
|
|
|
// Accumulate the packages of the values modules listed, and set that as an
|
2023-06-22 00:16:23 +02:00
|
|
|
// valueSetProviderKey provider that aconfig modules can read and use
|
2023-05-09 17:14:14 +02:00
|
|
|
// to append values to their aconfig actions.
|
2023-06-21 22:49:37 +02:00
|
|
|
packages := make(map[string]android.Paths)
|
2023-05-09 17:14:14 +02:00
|
|
|
ctx.VisitDirectDeps(func(dep android.Module) {
|
|
|
|
if !ctx.OtherModuleHasProvider(dep, valuesProviderKey) {
|
|
|
|
// Other modules get injected as dependencies too, for example the license modules
|
|
|
|
return
|
|
|
|
}
|
|
|
|
depData := ctx.OtherModuleProvider(dep, valuesProviderKey).(valuesProviderData)
|
|
|
|
|
|
|
|
srcs := make([]android.Path, len(depData.Values))
|
|
|
|
copy(srcs, depData.Values)
|
2023-06-21 22:49:37 +02:00
|
|
|
packages[depData.Package] = srcs
|
2023-05-09 17:14:14 +02:00
|
|
|
|
|
|
|
})
|
|
|
|
ctx.SetProvider(valueSetProviderKey, valueSetProviderData{
|
2023-06-21 22:49:37 +02:00
|
|
|
AvailablePackages: packages,
|
2023-05-09 17:14:14 +02:00
|
|
|
})
|
|
|
|
}
|