aconfig_values.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. package aconfig
  15. import (
  16. "android/soong/android"
  17. "github.com/google/blueprint"
  18. )
  19. // Properties for "aconfig_value"
  20. type ValuesModule struct {
  21. android.ModuleBase
  22. android.DefaultableModuleBase
  23. properties struct {
  24. // aconfig files, relative to this Android.bp file
  25. Srcs []string `android:"path"`
  26. // Release config flag package
  27. Package string
  28. }
  29. }
  30. func ValuesFactory() android.Module {
  31. module := &ValuesModule{}
  32. android.InitAndroidModule(module)
  33. android.InitDefaultableModule(module)
  34. module.AddProperties(&module.properties)
  35. // TODO: bp2build
  36. //android.InitBazelModule(module)
  37. return module
  38. }
  39. // Provider published by aconfig_value_set
  40. type valuesProviderData struct {
  41. // The package that this values module values
  42. Package string
  43. // The values aconfig files, relative to the root of the tree
  44. Values android.Paths
  45. }
  46. var valuesProviderKey = blueprint.NewProvider(valuesProviderData{})
  47. func (module *ValuesModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
  48. if len(module.properties.Package) == 0 {
  49. ctx.PropertyErrorf("package", "missing package property")
  50. }
  51. // Provide the our source files list to the aconfig_value_set as a list of files
  52. providerData := valuesProviderData{
  53. Package: module.properties.Package,
  54. Values: android.PathsForModuleSrc(ctx, module.properties.Srcs),
  55. }
  56. ctx.SetProvider(valuesProviderKey, providerData)
  57. }