java_aconfig_library.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. "android/soong/java"
  18. "fmt"
  19. "github.com/google/blueprint"
  20. )
  21. type declarationsTagType struct {
  22. blueprint.BaseDependencyTag
  23. }
  24. var declarationsTag = declarationsTagType{}
  25. type JavaAconfigDeclarationsLibraryProperties struct {
  26. // name of the aconfig_declarations module to generate a library for
  27. Aconfig_declarations string
  28. }
  29. type JavaAconfigDeclarationsLibraryCallbacks struct {
  30. properties JavaAconfigDeclarationsLibraryProperties
  31. }
  32. func JavaDeclarationsLibraryFactory() android.Module {
  33. callbacks := &JavaAconfigDeclarationsLibraryCallbacks{}
  34. return java.GeneratedJavaLibraryModuleFactory("java_aconfig_library", callbacks, &callbacks.properties)
  35. }
  36. func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) DepsMutator(module *java.GeneratedJavaLibraryModule, ctx android.BottomUpMutatorContext) {
  37. declarations := callbacks.properties.Aconfig_declarations
  38. if len(declarations) == 0 {
  39. // TODO: Add test for this case
  40. ctx.PropertyErrorf("aconfig_declarations", "aconfig_declarations property required")
  41. } else {
  42. ctx.AddDependency(ctx.Module(), declarationsTag, declarations)
  43. }
  44. }
  45. func (callbacks *JavaAconfigDeclarationsLibraryCallbacks) GenerateSourceJarBuildActions(ctx android.ModuleContext) android.Path {
  46. // Get the values that came from the global RELEASE_ACONFIG_VALUE_SETS flag
  47. declarationsModules := ctx.GetDirectDepsWithTag(declarationsTag)
  48. if len(declarationsModules) != 1 {
  49. panic(fmt.Errorf("Exactly one aconfig_declarations property required"))
  50. }
  51. declarations := ctx.OtherModuleProvider(declarationsModules[0], declarationsProviderKey).(declarationsProviderData)
  52. srcJarPath := android.PathForModuleGen(ctx, ctx.ModuleName()+".srcjar")
  53. ctx.Build(pctx, android.BuildParams{
  54. Rule: srcJarRule,
  55. Input: declarations.IntermediatePath,
  56. Output: srcJarPath,
  57. Description: "aconfig.srcjar",
  58. })
  59. return srcJarPath
  60. }