init.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. var (
  20. pctx = android.NewPackageContext("android/soong/aconfig")
  21. // For aconfig_declarations: Generate cache file
  22. aconfigRule = pctx.AndroidStaticRule("aconfig",
  23. blueprint.RuleParams{
  24. Command: `${aconfig} create-cache` +
  25. ` --package ${package}` +
  26. ` --declarations ${in}` +
  27. ` ${values}` +
  28. ` --cache ${out}.tmp` +
  29. ` && ( if cmp -s ${out}.tmp ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
  30. // ` --build-id ${release_version}` +
  31. CommandDeps: []string{
  32. "${aconfig}",
  33. },
  34. Restat: true,
  35. }, "release_version", "package", "values")
  36. // For java_aconfig_library: Generate java file
  37. srcJarRule = pctx.AndroidStaticRule("aconfig_srcjar",
  38. blueprint.RuleParams{
  39. Command: `rm -rf ${out}.tmp` +
  40. ` && mkdir -p ${out}.tmp` +
  41. ` && ${aconfig} create-java-lib` +
  42. ` --cache ${in}` +
  43. ` --out ${out}.tmp` +
  44. ` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
  45. ` && rm -rf ${out}.tmp`,
  46. CommandDeps: []string{
  47. "$aconfig",
  48. "$soong_zip",
  49. },
  50. Restat: true,
  51. })
  52. // For all_aconfig_declarations
  53. allDeclarationsRule = pctx.AndroidStaticRule("all_aconfig_declarations_dump",
  54. blueprint.RuleParams{
  55. Command: `${aconfig} dump --format protobuf --out ${out} ${cache_files}`,
  56. CommandDeps: []string{
  57. "${aconfig}",
  58. },
  59. }, "cache_files")
  60. )
  61. func init() {
  62. registerBuildComponents(android.InitRegistrationContext)
  63. pctx.HostBinToolVariable("aconfig", "aconfig")
  64. pctx.HostBinToolVariable("soong_zip", "soong_zip")
  65. }
  66. func registerBuildComponents(ctx android.RegistrationContext) {
  67. ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
  68. ctx.RegisterModuleType("aconfig_values", ValuesFactory)
  69. ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
  70. ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory)
  71. ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory)
  72. }